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.Common; using WMS.Base.WebService; using WMS.Ctrl; using WMS.Frm; using System.Collections; using WMS.Model.SystemManage; namespace WMS.FrmBaseData { public partial class FrmCapacity : FormBase { /// /// 运力资料MODEL /// CapacityModel capaModel = new CapacityModel(); /// /// 运力资料数据源 /// List SourceList = new List(); List AddList = new List(); /// /// 业务类型 /// int workflag;//0 增加 1 修改 2 删除 ; public FrmCapacity() { InitializeComponent(); } private void FrmCapacity_Load(object sender, EventArgs e) { #region 绑定部门 CompanyModel com_model = new CompanyModel(); string str_com_model = Newtonsoft.Json.JsonConvert.SerializeObject(com_model); string str_list = ""; try { str_list = WebLockConfig.Instance.WebCompany.GetCompanyData("", ""); } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("网络连接错误!"); return; } List list_com = Newtonsoft.Json.JsonConvert.DeserializeObject>(str_list); lue_Com.DataSource = list_com; lue_Com.DisplayMember = "COM_NAME"; lue_Com.ValueMember = "COM_ID"; #endregion FrmSelectModle = new CapacityModel(); BSCapacityTab.DataSource = new CapacityModel(); bindgrid(); } /// /// 通用查询 /// /// public override void LoadListData(DataTable table) { SourceList = ConvertHelper.ConvertToList(table); GCCapacity.DataSource = SourceList; GVCapacity.RefreshData(); } private void bindgrid() { CapacityModel model = BSCapacityTab.DataSource as CapacityModel; string strCapacityModel = Newtonsoft.Json.JsonConvert.SerializeObject(model); try { string Source = WebLockConfig.Instance.WebCapacity.execCapacityGetList(strCapacityModel); SourceList = Newtonsoft.Json.JsonConvert.DeserializeObject>(Source); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } GCCapacity.DataSource = SourceList; GVCapacity.RefreshData(); GVCapacity.ExpandAllGroups(); BSCapacityTab.DataSource = new CapacityModel(); } #region 以下是继承的按钮事件 /// /// 新增按钮 /// public void Add() { workflag = 0; FrmOperator(workflag); } ///// ///// 保存按钮 ///// //public void Save() //{ // FrmOperator(workflag); //} /// /// 删除按钮 /// public void Del() { workflag = 2; FrmOperator(workflag); } /// /// 修改按钮 /// public void Edit() { workflag = 1; FrmOperator(workflag); } /// /// 刷新按钮 /// public void Refresh() { bindgrid(); } /// /// 确定按钮 /// public void ConfrimDataButton() { } /// /// 查询按钮 /// public void Search() { FrmSelect frm = new FrmSelect(this.FrmSelectModle); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.LoadListData(frm.SelectData); } } /// /// 导出按钮 /// public void Export() { SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.Title = "导出Excel"; fileDialog.Filter = "Excel文件(*.xls)|*.xls"; DialogResult dialogResult = fileDialog.ShowDialog(this); if (dialogResult == DialogResult.OK) { try { //DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions(); GCCapacity.ExportToXls(fileDialog.FileName); DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception e) { SystemCommon.ShowInfoMessageBox("导出失败:" + e.Message); } } } /// /// 打印按钮 /// public void PrintDataButton() { } /// /// 备注 /// protected new void NoteDataButton(FormBase fBase) { } /// /// 导入 /// public void Import() { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Title = "导入供应商资料"; //fileDialog.Filter = "Excel文件(*.xls)|*.xls"; fileDialog.Filter = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx"; DialogResult dialogResult = fileDialog.ShowDialog(this); if (dialogResult == DialogResult.OK) { LoadForm load = new LoadForm(); DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(load, load.GetType(), false, true, false, 50); DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormDescription("正在加载数据,请稍等...."); Hashtable ht = new Hashtable(); //PropertyInfo[] model = new ProviderModel().GetType().GetProperties(); ht.Add("ID", "id"); ht.Add("CAR_ID", "车牌号"); ht.Add("CAR_PRIVATEID", "自车编号"); ht.Add("CAR_DRIVER", "主要驾驶员"); ht.Add("CAR_CARRIER", "承运商"); AddList = NPOIHelper.Import(fileDialog, ht); if (AddList != null) { if (AddList.Count > 0) { SourceList.InsertRange(0, AddList); GCCapacity.DataSource = SourceList; GVCapacity.RefreshData(); frmButtonItem["Save"].Enabled = true; workflag = 0; } } DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm(); } } /// /// 反审核 /// public void ReturnAuditDataButton() { } #endregion #region 操作(增、改、删) /// /// 操作(增、改、删) /// /// 0 新增 1修改 2删除 3停用 4启用/param> private void FrmOperator(int flag) { GCCapacity.Focus(); try { if (flag == 0) { if (AddList != null && AddList.Count > 0) { LoadForm load = new LoadForm(); DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(load, load.GetType(), false, true, false, 50); DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormDescription("正在处理数据,请稍等...."); string err = ""; string strList = Newtonsoft.Json.JsonConvert.SerializeObject(AddList); try { err = WebLockConfig.Instance.WebCapacity.execCapacityAddList(strList); } catch (Exception e) { SystemCommon.ShowErrorMessageBox("保存数据失败!" + e.Message); } DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm(); List errList = Newtonsoft.Json.JsonConvert.DeserializeObject>(err); if (errList == null || errList.Count == 0) { frmButtonItem["Save"].Enabled = false; SystemCommon.ShowInfoMessageBox("操作成功!"); } else { SystemCommon.ShowInfoMessageBox("有些车辆保存失败,失败的数据在页面列出!"); GCCapacity.DataSource = errList; GVCapacity.RefreshData(); return; } } else { FrmCapaCityDetcs frm = new FrmCapaCityDetcs(new CapacityModel() { CAR_BUYDATE = DateTime.Now, CAR_FILEDATE = DateTime.Now, CAR_PRODATE = DateTime.Now, CAR_REGDATE = DateTime.Now, CAR_INSUREDSRADATE = DateTime.Now, CAR_INSUREDEDDDATE = DateTime.Now, CAR_DISPART = "0", CAR_STATUS = "1", STATUS = "1" }, flag); LoadForm load = new LoadForm(); DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(load, load.GetType(), false, true, false, 50); DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormDescription("正在加载窗体,请等待...."); DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm(); frm.ShowDialog(); frm.Close(); frm.Dispose(); } } else if (flag == 1) { if (GVCapacity.FocusedRowHandle < 0) { SystemCommon.ShowInfoMessageBox("请先选择需要修改的记录!"); return; } capaModel = GVCapacity.GetRow(GVCapacity.FocusedRowHandle) as CapacityModel; LoadForm load = new LoadForm(); DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(load, load.GetType(), false, true, false, 50); DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormDescription("正在加载窗体,请等待...."); FrmCapaCityDetcs frm = new FrmCapaCityDetcs(capaModel, flag); DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm(); frm.ShowDialog(); frm.Close(); frm.Dispose(); } else if (flag == 2) { if (SystemCommon.ShowMessageBoxResult("确定要删除:" + GVCapacity.GetFocusedRowCellValue("CAR_ID").ToString()) == System.Windows.Forms.DialogResult.Yes) { string errtext = WebLockConfig.Instance.WebCapacity.execCapacityDel(GVCapacity.GetFocusedRowCellValue("ID").ToString()); if (!string.IsNullOrEmpty(errtext)) { SystemCommon.ShowErrorMessageBox(errtext); } else { SystemCommon.ShowInfoMessageBox("删除成功!"); bindgrid(); } } } } catch (Exception e) { SystemCommon.ShowInfoMessageBox("请规范操作!" + Environment.NewLine + e.Message); } } #endregion private void GCCapacity_DoubleClick(object sender, EventArgs e) { Edit(); } private void GVCapacity_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { if (e.Value == null || e.Value == DBNull.Value) { return; } if (e.Column.FieldName == "STATUS") { switch (e.Value.ToString().Trim()) { case "0": e.DisplayText = "停用"; break; case "1": e.DisplayText = "启用"; break; } } else if (e.Column.FieldName == "CAR_DISPART") { switch (e.Value.ToString().Trim()) { case "0": e.DisplayText = "未调度"; break; case "1": e.DisplayText = "已调度"; break; } } else if (e.Column.FieldName == "CAR_STATUS") { switch (e.Value.ToString().Trim()) { case "0": e.DisplayText = "停用"; break; case "1": e.DisplayText = "启用"; break; } } } } }