BaoKai_202508_Wms_Jingwang_.../WMS.FrmBaseData/FrmLogisticsComInfo.cs

475 lines
18 KiB
C#
Raw Normal View History

2025-08-24 21:52:42 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMS.Frm.Base;
using WMS.Model.Base;
using WMS.Base.WebService;
using WMS.Common;
using WMS.Ctrl;
using System.Collections;
namespace WMS.FrmBaseData
{
/// <summary>
/// 窗体:快递公司信息
/// </summary>
public partial class FrmLogisticsComInfo : FormBase
{
#region
public static FrmLogisticsComInfo frmLogisticsComInfo;
private LogisticsComInfoModel LogisticsComInfoModel = new LogisticsComInfoModel();
private List<LogisticsComInfoModel> listLogisticsComInfo = new List<LogisticsComInfoModel>();
private int flag;//0:新增;1:修改
private bool importing = false;
#endregion
#region
/// <summary>
/// 无参构造 查所有
/// </summary>
public FrmLogisticsComInfo()
{
InitializeComponent();
}
/// <summary>
/// 本窗体加载的时候
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void FrmLogisticsComInfo_Load(object sender, EventArgs e)
{
bindGrid();
FrmSelectModle = new LogisticsComInfoModel();
if (frmButtonItem.ContainsKey("SaveImport")) { frmButtonItem["SaveImport"].Enabled = false; }
}
public static FrmLogisticsComInfo getInstance()
{
if (frmLogisticsComInfo == null || frmLogisticsComInfo.IsDisposed)
{
frmLogisticsComInfo = new FrmLogisticsComInfo();
}
return frmLogisticsComInfo;
}
#endregion
#region
/// <summary>
/// 整体绑定数据
/// </summary>
private void bindGrid()
{
if (!importing)
{
string errText = string.Empty;
LogisticsComInfoModel LogisticsComInfoModel = new LogisticsComInfoModel();
string strParameter = Newtonsoft.Json.JsonConvert.SerializeObject(LogisticsComInfoModel);
//整体绑定数据
string strResult = string.Empty;
try
{
strResult = WebLockConfig.Instance.WebLogisticsComInfo.GetLogisticsComInfoListStr(strParameter, ref errText);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (errText == string.Empty)
{
listLogisticsComInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LogisticsComInfoModel>>(strResult);
if (listLogisticsComInfo.Count > 0)
{
//bsLogisticsComInfo.DataSource = listLogisticsComInfo;
//GVLogisticsComInfo.RefreshData();
}
else
{
//SystemCommon.ShowInfoMessageBox("没有快递公司信息");
}
}
else
{
SystemCommon.ShowInfoMessageBox(errText);
}
}
//else {
// bsLogisticsComInfo.DataSource = listLogisticsComInfo;
// GVLogisticsComInfo.RefreshData();
//}
bsLogisticsComInfo.DataSource = listLogisticsComInfo;
GVLogisticsComInfo.RefreshData();
}
/// <summary>
/// GridView选中行改变
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GVLogisticsComInfo_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
LogisticsComInfoModel = new LogisticsComInfoModel();
LogisticsComInfoModel = GVLogisticsComInfo.GetFocusedRow() as LogisticsComInfoModel;
}
/// <summary>
/// 双击GridView,得到属于该快递公司的配送范围
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GVLogisticsComInfo_DoubleClick(object sender, EventArgs e)
{
/*当该快递公司有配送范围信息,显示它的配送范围*/
string errText = string.Empty;
LogisticsRangeModel logisticsRangeModel = new LogisticsRangeModel();
logisticsRangeModel.LOG_COM_ID = LogisticsComInfoModel.LOG_COM_ID;
string strParameter = Newtonsoft.Json.JsonConvert.SerializeObject(logisticsRangeModel);
string strDataSet = string.Empty;
try
{
strDataSet = WebLockConfig.Instance.WebLogisticsRange.GetLogisticsRangeListStr(strParameter, ref errText);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (errText == string.Empty)
{
//调用Web服务读取快递公司配送范围信息
List<LogisticsRangeModel> listLogisticsRangeModel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LogisticsRangeModel>>(strDataSet);
if (listLogisticsRangeModel.Count > 0)
{
/*在Tab页打开新窗体*/
FormBase formBase = OpenFrmTable("WMS.FrmBaseData", "FrmLogisticsRange");//创建窗体
if (formBase != null)
{
FrmLogisticsRange frmLogisticsRange = formBase as FrmLogisticsRange;
frmLogisticsRange.LogComID = LogisticsComInfoModel.LOG_COM_ID;//为 刚创建的窗体 的 属性 赋值
//OpenTabAddFrm打开窗体打开之前检测该窗体是否已经被打开 是则返回false
if (!OpenTabAddFrm("1613", "FrmLogisticsRange", "快递公司配送范围-" + LogisticsComInfoModel.LOG_COM_ID))
{
frmLogisticsRange.FrmLogisticsRange_Load(null, null);//如果已经被打开,执行一下窗体加载方法
}
}
}
else
{
SystemCommon.ShowInfoMessageBox("该快递公司下没有可配送的范围");
}
}
else
{
SystemCommon.ShowInfoMessageBox(errText);
}
}
/// <summary>
/// 通用查询
/// </summary>
/// <param name="table"></param>
public override void LoadListData(DataTable table)
{
listLogisticsComInfo = ConvertHelper<LogisticsComInfoModel>.ConvertToList(table);
bsLogisticsComInfo.DataSource = listLogisticsComInfo;
GVLogisticsComInfo.RefreshData();
}
#endregion
#region
/// <summary>
/// 新增按钮
/// </summary>
public override void Add()
{
LoadForm load = new LoadForm();
DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(load, load.GetType(), false, true, false, 10);
DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormDescription("正在加载窗体,请等待....");
FrmLogisticsComInfoHandle frmLogisticsComInfoHandle = new FrmLogisticsComInfoHandle();
frmLogisticsComInfoHandle.userData = this.userData;
frmLogisticsComInfoHandle.ShowDialog();
bindGrid();
}
/// <summary>
/// 编辑按钮
/// </summary>
public override void Edit()
{
if (!frmButtonItem.ContainsKey("Edit"))
{
return;
}
else if (frmButtonItem["Edit"].Enabled == false)
{
return;
}
LoadForm load = new LoadForm();
DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(load, load.GetType(), false, true, false, 10);
DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormDescription("正在加载窗体,请等待....");
FrmLogisticsComInfoHandle frmLogisticsComInfoHandle = new FrmLogisticsComInfoHandle(LogisticsComInfoModel);
frmLogisticsComInfoHandle.userData = this.userData;
if (importing)
{
frmLogisticsComInfoHandle.flag = 3;
}
frmLogisticsComInfoHandle.ShowDialog();
bindGrid();
}
/// <summary>
/// 刷新按钮
/// </summary>
public override void Refresh()
{
importing = false;
bindGrid();
if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = true; }
if (frmButtonItem.ContainsKey("SaveImport")) { frmButtonItem["SaveImport"].Enabled = false; }
}
/// <summary>
/// 删除按钮
/// </summary>
public override void Del()
{
string errText = string.Empty;
if (DialogResult.Yes == SystemCommon.ShowMessageBoxResult("确定删除"))
{
if (!importing)
{
string str = LogisticsComInfoModel.LOG_COM_ID;
if (!string.IsNullOrEmpty(str))
{
/*检测该快递公司下是否存在配送范围数据,若有提示用户是否一并删除*/
/*得到该快递公司下配送范围数据*/
LogisticsRangeModel logisticsRangeModel = new LogisticsRangeModel();
logisticsRangeModel.LOG_COM_ID = str;
string strModel = Newtonsoft.Json.JsonConvert.SerializeObject(logisticsRangeModel);
string strDataSet = string.Empty;
try
{
strDataSet = WebLockConfig.Instance.WebLogisticsRange.GetLogisticsRangeListStr(strModel, ref errText);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (errText == string.Empty)
{
List<LogisticsRangeModel> logisticsRangeList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LogisticsRangeModel>>(strDataSet);
if (logisticsRangeList.Count > 0)
{
if (DialogResult.Yes == SystemCommon.ShowMessageBoxResult("该快递公司下存在配送范围数据,是否删除?(点击是将一并删除,点击否不进行任何操作)"))
{
errText = string.Empty;
try
{
errText = WebLockConfig.Instance.WebLogisticsComInfo.DeleteLogisticsComInfoAndRange(str);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (string.IsNullOrEmpty(errText))
{
bindGrid();
}
else
{
SystemCommon.ShowInfoMessageBox("删除失败:" + errText);
return;
}
}
else
{
return;
}
}
else
{
//删除快递公司
errText = string.Empty;
try
{
errText = WebLockConfig.Instance.WebLogisticsComInfo.DeleteLogisticsComInfo(str);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (string.IsNullOrEmpty(errText))
{
bindGrid();
}
else
{
SystemCommon.ShowInfoMessageBox("删除失败" + errText);
}
}
}
else
{
SystemCommon.ShowInfoMessageBox(errText);
}
}
else
{
SystemCommon.ShowInfoMessageBox("请选择一条记录");
}
}
else {
listLogisticsComInfo.RemoveAll(p=>p.LOG_COM_ID == LogisticsComInfoModel.LOG_COM_ID && p.LOG_COM_NAME == LogisticsComInfoModel.LOG_COM_NAME);//.RemoveAt(GVLogisticsComInfo.GetFocusedDataSourceRowIndex());
bindGrid();
}
}
}
#endregion
/// <summary>
/// 导入
/// </summary>
public void Import()
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Title = "导入快递公司信息";
fileDialog.Filter = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx";
DialogResult dialogResult = fileDialog.ShowDialog(this);
if (dialogResult == DialogResult.OK)
{
Hashtable ht = new Hashtable();
ht.Add("LOG_COM_ID", "物流公司代码");
ht.Add("LOG_COM_NAME", "物流公司名称");
List<LogisticsComInfoModel> tempList = NPOIHelper<LogisticsComInfoModel>.Import(fileDialog, ht);
if (tempList == null)
{
bindGrid();
return;
}
if (importing)
{
listLogisticsComInfo.AddRange(tempList);
}
else
{
listLogisticsComInfo = tempList;
}
//if (listLogisticsComInfo == null) {
// bindGrid();
// return;
//}
if (frmButtonItem.ContainsKey("Add")) { frmButtonItem["Add"].Enabled = false; }
if (frmButtonItem.ContainsKey("SaveImport")) { frmButtonItem["SaveImport"].Enabled = true; }
importing = true;
bindGrid();
}
}
/// <summary>
/// 保存
/// </summary>
public void SaveImport()
{
//将list存入数据库
if (listLogisticsComInfo != null && listLogisticsComInfo.Count > 0)
{
string errText = string.Empty;
string strList = Newtonsoft.Json.JsonConvert.SerializeObject(listLogisticsComInfo);
List<int> errorIndex = new List<int>();
int hadNum = 0;
int lengthNum = 0;
string error = string.Empty;
try
{
errorIndex = Newtonsoft.Json.JsonConvert.DeserializeObject<List<int>>(WebLockConfig.Instance.WebLogisticsComInfo.InsLogisticsComList(strList, ref errText, ref hadNum, ref lengthNum, ref error));
}
catch (Exception)
{
SystemCommon.ShowErrorMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (errorIndex.Count == 0)
{
SystemCommon.ShowInfoMessageBox("所有记录已保存成功");
Refresh();
}
else
{
List<LogisticsComInfoModel> tempList = new List<LogisticsComInfoModel>();
for (int i = errorIndex.Count - 1; i >= 0; i--)
{
tempList.Add(listLogisticsComInfo[i]);
}
listLogisticsComInfo = tempList;
bindGrid();
string fileName = @"D:\WMS\保存导入快递公司错误日志" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
SystemCommon.WriteFile(fileName, error);///写文件
/*错误提示*/
string info = string.Empty;
if (errorIndex.Count > (hadNum + lengthNum))
{
info += ((errorIndex.Count - hadNum - lengthNum) + "个快递公司导入时遇到未知错误,");
}
if (hadNum > 0)
{
info += (hadNum + "个快递公司编号已存在,");
}
if (lengthNum > 0)
{
info += (lengthNum + "条快递公司记录数据长度过长,");
}
info += "日志已写入" + fileName + ",未出错记录已写入数据库并从窗体中移除。";
SystemCommon.ShowErrorMessageBox(info);
}
}
}
/// <summary>
/// 导出
/// </summary>
public void Export()
{
GCLogisticsComInfo.ShowExportDialog();
}
}
}