/// <summary> /// 现货单位换算数据输入检测 /// </summary> /// <param name="msg">提示信息</param> /// <returns></returns> private CM_UnitConversion VerifyUnitConversionInput(ref string msg) { try { msg = string.Empty; CM_UnitConversion cM_UnitConversion = new CM_UnitConversion(); if (!string.IsNullOrEmpty(this.txtValue.Text)) { if (InputTest.intTest(this.txtValue.Text)) { cM_UnitConversion.Value = Convert.ToInt32(this.txtValue.Text); } else { msg = "请输入数字且第一位数不能为0!"; } } else { msg = "比例不能为空!"; } cM_UnitConversion.BreedClassID = ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex; cM_UnitConversion.UnitIDFrom = ((UComboItem)this.cmbUnitIDFrom.SelectedItem).ValueIndex; cM_UnitConversion.UnitIDTo = ((UComboItem)this.cmbUnitIDTo.SelectedItem).ValueIndex; if (EditType == (int)UITypes.EditTypeEnum.UpdateUI) { cM_UnitConversion.UnitConversionID = m_UnitConversionID; } return(cM_UnitConversion); } catch (Exception ex) { LogHelper.WriteError(ex.Message, ex); return(null); } }
/// <summary> /// 确定按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_Click(object sender, EventArgs e) { if (m_EditType == 1) { #region 添加操作 EditType = (int)UITypes.EditTypeEnum.AddUI; int result = AppGlobalVariable.INIT_INT; try { CM_UnitConversion cM_UnitConversion = new CM_UnitConversion(); int breedClassID = AppGlobalVariable.INIT_INT; //品种ID if (!string.IsNullOrEmpty(this.cmbBreedClassID.Text)) { breedClassID = ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex; if (breedClassID != AppGlobalVariable.INIT_INT) { List <CM_UnitConversion> cMUnitConversionList = SpotManageCommon.GetUnitConveByBreedClassID(breedClassID); if (cMUnitConversionList.Count > 0) { int _curRow = 0; //当前记录行 foreach (CM_UnitConversion _UnitConversion in cMUnitConversionList) { _curRow++; if (_UnitConversion.BreedClassID == ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex) { if (_UnitConversion.UnitIDFrom == ((UComboItem)this.cmbUnitIDFrom.SelectedItem).ValueIndex && _UnitConversion.UnitIDTo == ((UComboItem)this.cmbUnitIDTo.SelectedItem).ValueIndex) { ShowMessageBox.ShowInformation("同一品种,同一从单位到单位的转换只允许一条记录!"); break; } else { if (_curRow == cMUnitConversionList.Count) { string msg = string.Empty; cM_UnitConversion = VerifyUnitConversionInput(ref msg); if (!string.IsNullOrEmpty(msg)) { ShowMessageBox.ShowInformation(msg); } else { result = SpotManageCommon.AddCMUnitConversion(cM_UnitConversion); if (result != AppGlobalVariable.INIT_INT) { ShowMessageBox.ShowInformation("添加成功!"); this.ClearAll(); this.QuerySpotUnitConversion(); } else { ShowMessageBox.ShowInformation("添加失败!"); } } } } continue; } } } else { string msg = string.Empty; cM_UnitConversion = VerifyUnitConversionInput(ref msg); if (!string.IsNullOrEmpty(msg)) { ShowMessageBox.ShowInformation(msg); } else { result = SpotManageCommon.AddCMUnitConversion(cM_UnitConversion); if (result != AppGlobalVariable.INIT_INT) { ShowMessageBox.ShowInformation("添加成功!"); this.ClearAll(); this.QuerySpotUnitConversion(); } else { ShowMessageBox.ShowInformation("添加失败!"); } } } } } } catch (Exception ex) { string errCode = "GL-5701"; string errMsg = "添加现货单位换算失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return; } #endregion } else if (m_EditType == 2) { #region 修改操作 try { EditType = (int)UITypes.EditTypeEnum.UpdateUI; CM_UnitConversion cM_UnitConversion = new CM_UnitConversion(); int breedClassID = AppGlobalVariable.INIT_INT; //品种ID if (m_UnitConversionID == AppGlobalVariable.INIT_INT) { ShowMessageBox.ShowInformation("请选择更新数据!"); return; } if (!string.IsNullOrEmpty(this.cmbBreedClassID.Text)) { breedClassID = ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex; if (breedClassID != AppGlobalVariable.INIT_INT) { List <CM_UnitConversion> cMUnitConversionList = SpotManageCommon.GetUnitConveByBreedClassID(breedClassID); if (cMUnitConversionList.Count > 0) { int _curRow = 0; //当前记录行 foreach (CM_UnitConversion _UnitConversion in cMUnitConversionList) { if (m_UnitConversionID == _UnitConversion.UnitConversionID) //不与自己比较 { _curRow++; if (_curRow == cMUnitConversionList.Count) { string msg = string.Empty; cM_UnitConversion = VerifyUnitConversionInput(ref msg); if (!string.IsNullOrEmpty(msg)) { ShowMessageBox.ShowInformation(msg); } else { m_Result = SpotManageCommon.UpdateCMUnitConversion(cM_UnitConversion); if (m_Result) { ShowMessageBox.ShowInformation("修改成功!"); this.ClearAll(); this.QuerySpotUnitConversion(); m_UnitConversionID = AppGlobalVariable.INIT_INT; } else { ShowMessageBox.ShowInformation("修改失败!"); } } break; } continue; } _curRow++; if (_UnitConversion.BreedClassID == ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex) { if (_UnitConversion.UnitIDFrom == ((UComboItem)this.cmbUnitIDFrom.SelectedItem).ValueIndex && _UnitConversion.UnitIDTo == ((UComboItem)this.cmbUnitIDTo.SelectedItem).ValueIndex) { ShowMessageBox.ShowInformation("同一品种,同一从单位到单位的转换只允许一条记录!"); break; } else { if (_curRow == cMUnitConversionList.Count) { string msg = string.Empty; cM_UnitConversion = VerifyUnitConversionInput(ref msg); if (!string.IsNullOrEmpty(msg)) { ShowMessageBox.ShowInformation(msg); } else { m_Result = SpotManageCommon.UpdateCMUnitConversion(cM_UnitConversion); if (m_Result) { ShowMessageBox.ShowInformation("修改成功!"); this.ClearAll(); this.QuerySpotUnitConversion(); m_UnitConversionID = AppGlobalVariable.INIT_INT; } else { ShowMessageBox.ShowInformation("修改失败!"); } } } } continue; } } } } } } catch (Exception ex) { string errCode = "GL-5703"; string errMsg = "修改现货单位换算失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return; } #endregion } this.ClearAll(); }