/// <summary> /// 响应“反封存”按钮的Click事件 /// </summary> private void tsButtonUnSeal_Click(object sender, EventArgs e) { /* 选中一行,若当前行为null,则直接返回 */ DataRow dr = wnGridSealManage.CurrRow; if (dr == null) { return; } /* 询问是否确定要进行反封存操作 */ if (DialogBox.AskYesNo(this.GetCurrLanguageContent("WnFormSealManage.AskUnSealData")) == DialogResult.No) { return; } //Content_CN:是否确定要进行反封存操作? /* 获取服务器的当前时间 */ object currTime = AppServer.GetDateTime(); if (currTime == null) { return; } /* 执行SQL语句,执行反封存操作 */ Hashtable htUnSeal = new Hashtable(); htUnSeal["DataSetName"] = "UnSealData"; htUnSeal["{Guid}"] = dr["Guid"].ToString(); htUnSeal["{EditUser}"] = AppInfo.UserName; htUnSeal["{EditTime}"] = ((DateTime)currTime).ToString("yyyy/MM/dd HH:mm:ss"); if (this.DataSource.ExecSql(htUnSeal)["IsSuccess"].Equals("0")) { return; } /* 标记进行了反封存操作 */ IsModify = true; /* 记录反封存日志 */ Hashtable htLog = new Hashtable(); htLog["{Year}"] = dr["Year"].ToString(); htLog["{Month}"] = dr["Month"].ToString(); htLog["{HdgsName}"] = dr["HdgsName"].ToString(); htLog["{Zyg}"] = dr["Zyg"].ToString(); htLog["{Mdg}"] = dr["Mdg"].ToString(); htLog["{Yfdj}"] = dr["Yfdj"].ToString(); htLog["{Dpfy}"] = dr["Dpfy"].ToString(); htLog["{Ysts}"] = dr["Ysts"].ToString(); AppServer.SaveModuleOpLog(this.ModuleId, "WnFormMain.UnSealLog", htLog); //Content_CN:反封存了年份为【{Year}】、月份为【{Month}】、货代公司名称为【{HdgsName}】、装运港为【{Zyg}】、目的港为【{Mdg}】、运费单价为【{Yfdj}】、单票费用为【{Dpfy}】、运输天数为【{Ysts}】的海运费用登记信息! /* 从界面上删除数据 */ wnGridSealManage.DeleteRow(dr); dr.AcceptChanges(); }
/// <summary> /// 响应窗体的AfterAssemble事件 /// </summary> private void WnFormMain_AfterAssemble(object sender, CancelEventArgs e) { /* 初始化控件变量 */ InitializeObject(); /* 注册控件事件 */ tsComboYear.ValueChanging += tsComboYear_ValueChanging; tsComboMonth.ValueChanging += tsComboMonth_ValueChanging; tsButtonLoad.Click += tsButtonLoad_Click; tsButtonCarry.Click += tsButtonCarry_Click; tsButtonAppend.Click += tsButtonAppend_Click; tsButtonImport.Click += tsButtonImport_Click; tsButtonSave.Click += tsButtonSave_Click; tsButtonAudit.Click += tsButtonAudit_Click; tsButtonUnAudit.Click += tsButtonUnAudit_Click; tsButtonSeal.Click += tsButtonSeal_Click; tsButtonHelp.Click += tsButtonHelp_Click; tsButtonExit.Click += tsButtonExit_Click; tsButtonSealManage.Click += tsButtonSealManage_Click; wnGridMain.CurrRowChanged += wnGridMain_CurrRowChanged; /* 获取当前服务器时间 */ object currTime = AppServer.GetDateTime(); if (currTime == null) { e.Cancel = true; return; } /* 为tsComboYear控件绑定数据源 */ tsComboYear.ComboString = ((DateTime)currTime).AddYears(-1).Year + "|" + ((DateTime)currTime).Year + "|" + ((DateTime)currTime).AddYears(+1).Year; tsComboYear.SelectedIndex = 1; /* 为tsComboMonth控件设置默认值,默认为当前月份 */ tsComboMonth.SelectedIndex = ((DateTime)currTime).Month - 1; /* 设置右键菜单 */ wnGridMain.ContextMenuStrip = wnToolBarMain.WnMenu; /* 设置标准前景色和特殊前景色 */ wnGridMain.SetForeColor("RowState = '0'|| RowState = '10'|| RowState = '11'", "", Color.FromArgb(0, 128, 0)); wnGridMain.SetForeColor("AuditUser is not null", "", Color.FromArgb(255, 0, 0)); //已审核的数据显示红色 /* 获取数据 */ GetData(); }
/// <summary> /// 保存数据 /// </summary> private bool SaveData(List <Act> actionStep) { /* 提交数据,如果没有数据发生修改直接返回 */ Hashtable ht = new Hashtable(); ht["DataSetName"] = "GetData"; ht["ActionStep"] = new List <Act>() { Act.CommitEdit }; if (this.DataSource.UpdateDataSet(ht)["IsChanged"].Equals("0")) { return(true); } /* 若包含AskIsUpdate选项,询问是否保存,根据用户的选择返回相应的值*/ if (actionStep.Contains(Act.AskIsUpdate)) { ht["ActionStep"] = new List <Act> { Act.AskIsUpdate }; Hashtable result = DataSource.UpdateDataSet(ht); if (result["IsUpdate"].Equals("-1")) { return(false); } if (result["IsUpdate"].Equals("0")) { wnGridMain.RejectChanges(); return(true); } /* 移除AskIsUpdate选项 */ actionStep.Remove(Act.AskIsUpdate); } /* 检查必录项 */ ht["ActionStep"] = new List <Act>() { Act.CheckData }; if (this.DataSource.UpdateDataSet(ht)["IsSuccess"].Equals("0")) { return(false); } /* 检查唯一索引不重复 */ var item = from p in wnGridMain.DataSource.AsEnumerable() group p by new { year = p.Field <Int16>("Year"), month = p.Field <byte>("Month"), hdgsGuid = p.Field <string>("HdgsGuid"), hdgsName = p.Field <string>("HdgsName"), zyg = p.Field <string>("Zyg"), mdg = p.Field <string>("Mdg") } into g where g.Count() > 1 select new { g.Key.year, g.Key.month, g.Key.hdgsGuid, g.Key.hdgsName, g.Key.zyg, g.Key.mdg }; if (item.Count() > 0) { /* 定义字符串,存储重复数据 */ StringBuilder message = new StringBuilder(); /* 遍历拼接重复数据,用于提示 */ foreach (var obj in item) { message.Append(",").AppendFormat(this.GetCurrLanguageContent("WnFormMain.CheckRepeat"), obj.year, obj.month, obj.hdgsName, obj.zyg, obj.mdg); //Content_CN:年份:‘{0}’,月份:‘{1}’,货代公司名称:‘{2}’,装运港:‘{3}’,目的港:‘{4}’ message.Append('\n'); } DialogBox.ShowWarning(string.Format(this.GetCurrLanguageContent("WnFormMain.RepeatData"), message.ToString().Substring(1))); //Content_CN:{0}的信息存在重复值,请修改后保存! return(false); } /* 创建集合存储年份、月份、货代公司内码、装运港、目的港的信息 */ List <Int16> list_Year = new List <Int16>(); List <byte> list_Month = new List <byte>(); List <string> list_hdgsGuid = new List <string>(); List <string> list_Zyg = new List <string>(); List <string> list_Mdg = new List <string>(); /* 将新增行的信息存入集合 */ foreach (DataRow datarow in wnGridMain.DataSource.Select("RowState = '10'")) { list_Year.Add(Convert.ToInt16(datarow["Year"])); list_Month.Add(Convert.ToByte(datarow["Month"])); list_hdgsGuid.Add(datarow["HdgsGuid"].ToString()); list_Zyg.Add(datarow["Zyg"].ToString()); list_Mdg.Add(datarow["Mdg"].ToString()); } /* 拼接年份、月份、货代公司内码、装运港、目的港的信息 */ string years = "'" + string.Join("','", list_Year) + "'"; string months = "'" + string.Join("','", list_Month) + "'"; string hdgsGuids = "'" + string.Join("','", list_hdgsGuid) + "'"; string zyg = "'" + string.Join("','", list_Zyg) + "'"; string mdg = "'" + string.Join("','", list_Mdg) + "'"; /* 检查数据库是否有重复索引的数据 */ Hashtable htCheckRepeat = new Hashtable(); htCheckRepeat["DataSetName"] = "CheckRepeat"; htCheckRepeat["{Years}"] = years; htCheckRepeat["{Months}"] = months; htCheckRepeat["{HdgsGuids}"] = hdgsGuids; htCheckRepeat["{Zyg}"] = zyg; htCheckRepeat["{Mdg}"] = mdg; if (this.DataSource.GetDataSet(htCheckRepeat)["IsSuccess"].Equals("0")) { return(false); } DataTable dtRepeat = (this.DataSource.DataSets["CheckRepeat"] as DataSet).Tables[0]; if (dtRepeat.Rows.Count > 0) { /* 获取重复的年份、月份、货代公司名称、装运港、目的港的信息,并提示 */ var repeat = dtRepeat.AsEnumerable().Select(x => new { year = x.Field <Int16>("Year"), month = x.Field <byte>("Month"), hdgsName = x.Field <string>("HdgsName"), zyg = x.Field <string>("Zyg"), mdg = x.Field <string>("Mdg") }); /* 定义字符串,存储重复数据 */ StringBuilder message = new StringBuilder(); /* 遍历拼接重复数据,用于提示 */ foreach (var obj in repeat) { message.Append(",").AppendFormat(this.GetCurrLanguageContent("WnFormMain.CheckRepeat"), obj.year, obj.month, obj.hdgsName, obj.zyg, obj.mdg); //Content_CN:年份:‘{0}’,月份:‘{1}’,货代公司名称:‘{2}’,装运港:‘{3}’,目的港:‘{4}’ message.Append('\n'); } DialogBox.ShowWarning(string.Format(this.GetCurrLanguageContent("WnFormMain.RepeatData"), message.ToString().Substring(1))); //Content_CN:{0}的信息存在重复值,请修改后保存! return(false); } /* 获取服务器的当前时间 */ object currTime = AppServer.GetDateTime(); if (currTime == null) { return(false); } /* 为编辑人、编辑时间赋值 */ foreach (DataRow dr in wnGridMain.DataSource.Select("RowState = '10' or RowState = '11'")) { dr["EditUser"] = AppInfo.UserName; dr["EditTime"] = ((DateTime)currTime).ToString("yyyy/MM/dd HH:mm:ss"); } /* 保存数据 */ ht["ActionStep"] = actionStep; if (this.DataSource.UpdateDataSet(ht)["IsSuccess"].Equals("0")) { return(false); } return(true); }
/// <summary> /// 响应“审核”按钮的Click事件 /// </summary> private void tsButtonAudit_Click(object sender, EventArgs e) { /* 保存按钮可用,检查是否有未保存的数据 */ if (tsButtonSave.Enabled && !SaveData(new List <Act> { Act.AskIsUpdate, Act.SaveData })) { return; } /* 若未选择行,则提示返回 */ if (wnGridMain.SelectedRowsArray.Length == 0) { DialogBox.ShowWarning(GetCurrLanguageContent("WnGridMain.AuditWarn")); //Content_CN:请勾选需要审核的数据! return; } /* 获取当前服务器时间 */ object currTime = AppServer.GetDateTime(); if (currTime == null) { return; } /* 遍历选中行,获取Guid、审核人、审核时间 */ List <string> listGuid = new List <string>(); List <string> listAuditUser = new List <string>(); List <string> listAuditTime = new List <string>(); foreach (DataRow datarow in wnGridMain.SelectedRowsArray) { /* 排除已审核和新增的空行 */ if (datarow["AuditUser"] != DBNull.Value || datarow["RowState"].Equals("0")) { wnGridMain.SetRowUnSelected(datarow); continue; } /* 将需要审核行的信息添加到集合中 */ listGuid.Add(datarow["Guid"].ToString()); listAuditUser.Add(AppInfo.UserName); listAuditTime.Add(Convert.ToDateTime(currTime).ToString("yyyy/MM/dd HH:mm:ss")); } /* 若集合中无数据,则直接返回 */ if (listGuid.Count == 0) { return; } /* 执行审核语句 */ Hashtable htAudit = new Hashtable(); htAudit["DataSetName"] = "AuditData"; htAudit["{Guid}"] = listGuid; htAudit["{AuditUser}"] = listAuditUser; htAudit["{AuditTime}"] = listAuditTime; if (this.DataSource.ExecSql(htAudit)["IsSuccess"].Equals("0")) { return; } /* 记录日志,并更新界面数据 */ Hashtable htLog = new Hashtable(); foreach (DataRow dr in wnGridMain.SelectedRowsArray) { /* 记录审核日志 */ htLog["{Year}"] = dr["Year"].ToString(); htLog["{Month}"] = dr["Month"].ToString(); htLog["{HdgsName}"] = dr["HdgsName"].ToString(); htLog["{Zyg}"] = dr["Zyg"].ToString(); htLog["{Mdg}"] = dr["Mdg"].ToString(); htLog["{Yfdj}"] = dr["Yfdj"].ToString(); htLog["{Dpfy}"] = dr["Dpfy"].ToString(); htLog["{Ysts}"] = dr["Ysts"].ToString(); AppServer.SaveModuleOpLog(this.ModuleId, "WnFormMain.AuditLog", htLog); //Content_CN:审核了年份为【{Year}】、月份为【{Month}】、货代公司名称为【{HdgsName}】、装运港为【{Zyg}】、目的港为【{Mdg}】、运费单价为【{Yfdj}】、单票费用为【{Dpfy}】、运输天数为【{Ysts}】的海运费用登记信息! dr["AuditUser"] = AppInfo.UserName; dr["AuditTime"] = currTime; dr.AcceptChanges(); } /* 清空选中行 */ wnGridMain.SetRowUnSelected(wnGridMain.SelectedRowsArray); /* 手动触发CurrRowChanged事件,控制已审核的数据不可编辑 */ wnGridMain_CurrRowChanged(null, null); }
/// <summary> /// 响应“封存”按钮的Click事件 /// </summary> private void tsButtonSeal_Click(object sender, EventArgs e) { /* 保存按钮可用,检查是否有未保存的数据 */ if (tsButtonSave.Enabled && !SaveData(new List <Act> { Act.AskIsUpdate, Act.SaveData })) { return; } /* 若界面没有勾选行并且当前行不为空,则选中当前行,对当前行进行封存 */ if (wnGridMain.SelectedRowsArray.Length == 0) { if (wnGridMain.CurrRow == null) { return; } wnGridMain.SetRowSelected(wnGridMain.CurrRow); } /* 询问是否确定要进行封存操作 */ if (DialogBox.AskYesNo(this.GetCurrLanguageContent("WnFormMain.AskSealData")) == DialogResult.No) { return; } //Content_CN:是否确定要进行封存操作? /* 获取当前服务器时间 */ object currTime = AppServer.GetDateTime(); if (currTime == null) { return; } /* 遍历选中行,获取选中行的Guid、封存人、封存时间 */ List <string> listSeal = new List <string>(); List <string> listSealUser = new List <string>(); List <string> listSealTime = new List <string>(); foreach (DataRow datarow in wnGridMain.SelectedRowsArray) { /* 已审核的数据不允许封存,只封存未审核的行 */ if (!string.IsNullOrWhiteSpace(datarow["AuditUser"] + "")) { wnGridMain.SetRowUnSelected(datarow); continue; } /* 界面的新增行直接删除 */ if (datarow.RowState == DataRowState.Added) { wnGridMain.DeleteRow(datarow); continue; } /* 将符合条件的信息存入集合 */ listSeal.Add(datarow["Guid"].ToString()); listSealUser.Add(AppInfo.UserName); listSealTime.Add(Convert.ToDateTime(currTime).ToString("yyyy/MM/dd HH:mm:ss")); } /* 若集合中无数据,则直接返回 */ if (listSeal.Count == 0) { return; } /* 执行封存语句 */ Hashtable htSealData = new Hashtable(); htSealData["DataSetName"] = "SealData"; htSealData["{Guid}"] = listSeal; htSealData["{SealUser}"] = listSealUser; htSealData["{SealTime}"] = listSealTime; if (this.DataSource.ExecSql(htSealData)["IsSuccess"].Equals("0")) { return; } /* 记录日志,并删除界面上的数据 */ Hashtable htLog = new Hashtable(); foreach (DataRow dr in wnGridMain.SelectedRowsArray) { /* 记录封存日志 */ htLog["{Year}"] = dr["Year"].ToString(); htLog["{Month}"] = dr["Month"].ToString(); htLog["{HdgsName}"] = dr["HdgsName"].ToString(); htLog["{Zyg}"] = dr["Zyg"].ToString(); htLog["{Mdg}"] = dr["Mdg"].ToString(); htLog["{Yfdj}"] = dr["Yfdj"].ToString(); htLog["{Dpfy}"] = dr["Dpfy"].ToString(); htLog["{Ysts}"] = dr["Ysts"].ToString(); AppServer.SaveModuleOpLog(this.ModuleId, "WnFormMain.SealLog", htLog); //Content_CN:封存了年份为【{Year}】、月份为【{Month}】、货代公司名称为【{HdgsName}】、装运港为【{Zyg}】、目的港为【{Mdg}】、运费单价为【{Yfdj}】、单票费用为【{Dpfy}】、运输天数为【{Ysts}】的海运费用登记信息! wnGridMain.DeleteRow(dr); dr.AcceptChanges(); } }