private void btnSave_Click(object sender, EventArgs e) { if (CheckInput()) { if (_currentCustomerPriceTable == null) { _currentCustomerPriceTable = new BaseCustomerPriceTable(); } _currentCustomerPriceTable.CUSTOMER_CODE = txtCustomerCode.Text; _currentCustomerPriceTable.PRODUCT_CODE = txtProductCode.Text; _currentCustomerPriceTable.UNIT_CODE = txtUnitCode.Text; _currentCustomerPriceTable.PRICE = Convert.ToDecimal(txtPrice.Text); _currentCustomerPriceTable.LAST_UPDATE_USER = _userInfo.CODE; try { if (bCustomerPrice.Exists(txtCustomerCode.Text.Trim(), txtProductCode.Text.Trim(), txtUnitCode.Text.Trim())) { bCustomerPrice.Update(_currentCustomerPriceTable); } else { _currentCustomerPriceTable.CREATE_USER = _userInfo.CODE; bCustomerPrice.Add(_currentCustomerPriceTable); } } catch (Exception ex) { MessageBox.Show(""); } result = DialogResult.OK; this.Close(); } }
private void txtUnitCode_Leave(object sender, EventArgs e) { //判断编号是否已存在 if (!string.IsNullOrEmpty(this.txtUnitCode.Text.Trim()) && !string.IsNullOrEmpty(this.txtCustomerCode.Text.Trim()) && !string.IsNullOrEmpty(this.txtProductCode.Text.Trim())) { BaseCustomerPriceTable CustomerPriceCode = new BaseCustomerPriceTable(); CustomerPriceCode = bCustomerPrice.GetModel(txtCustomerCode.Text, txtProductCode.Text, txtUnitCode.Text); if (CustomerPriceCode != null) { txtCustomerCode.Text = ""; txtProductCode.Text = ""; txtUnitCode.Text = ""; txtCustomerName.Text = ""; txtProductName.Text = ""; txtUnitName.Text = ""; txtCustomerCode.Focus(); MessageBox.Show("客户编号商品编号单位编号的组合已存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } string unit = txtUnitCode.Text.Trim(); if (!string.IsNullOrEmpty(unit)) { BaseMaster baseMaster = bCommon.GetBaseMaster("UNIT", unit); if (baseMaster != null) { txtUnitCode.Text = baseMaster.Code; txtUnitName.Text = baseMaster.Name; txtPrice.Focus(); } else { MessageBox.Show("单位编号不存在!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtUnitCode.Text = ""; txtUnitName.Text = ""; txtUnitCode.Focus(); } } else { txtUnitName.Text = ""; } }
/// <summary> /// 获得当前选中的数据 /// </summary> private void GetCurrentSelectedTable() { try { string customercode = dgvData.SelectedRows[0].Cells[0].Value.ToString(); string productcode = dgvData.SelectedRows[0].Cells[2].Value.ToString(); string unitcode = dgvData.SelectedRows[0].Cells[4].Value.ToString(); if (customercode != "") { _currentCustomerPriceTable = bCustomerPrice.GetModel(customercode, productcode, unitcode); } } catch (Exception ex) { } if (_currentCustomerPriceTable == null || _currentCustomerPriceTable.CUSTOMER_CODE == null || "".Equals(_currentCustomerPriceTable.CUSTOMER_CODE)) { _currentCustomerPriceTable = null; } }
/// <summary> /// 打开新窗口 /// </summary> private void OpenDialogFrm(int mode) { if (mode == CConstant.MODE_NEW || _currentCustomerPriceTable != null) { FrmCustomerPriceDialog frm = new FrmCustomerPriceDialog(); frm.UserInfo = _userInfo; frm.CurrentCustomerPriceTable = _currentCustomerPriceTable; frm.Mode = mode; DialogResult resule = frm.ShowDialog(this); if (resule == DialogResult.OK && isSearch) { Search(this.pgControl.GetCurrentPage()); } frm.Dispose(); } else { //MessageBox.Show("请选择正确的行!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } _currentCustomerPriceTable = null; }
private bool CheckCode() { //判断编号是否已存在 if (!string.IsNullOrEmpty(this.txtUnitCode.Text.Trim()) && !string.IsNullOrEmpty(this.txtCustomerCode.Text.Trim()) && !string.IsNullOrEmpty(this.txtProductCode.Text.Trim())) { BaseCustomerPriceTable CustomerPriceCode = new BaseCustomerPriceTable(); CustomerPriceCode = bCustomerPrice.GetModel(txtCustomerCode.Text, txtProductCode.Text, txtUnitCode.Text); if (CustomerPriceCode != null) { txtCustomerCode.Text = ""; txtProductCode.Text = ""; txtUnitCode.Text = ""; txtCustomerName.Text = ""; txtProductName.Text = ""; txtUnitName.Text = ""; txtCustomerCode.Focus(); MessageBox.Show("客户编号商品编号单位编号的组合已存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } return(true); }
/// <summary> /// 删除 /// </summary> private void MasterToolBar_DoDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("确定要删除吗?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.OK) { try { GetCurrentSelectedTable(); if (_currentCustomerPriceTable != null) { bCustomerPrice.Delete(_currentCustomerPriceTable.CUSTOMER_CODE, _currentCustomerPriceTable.PRODUCT_CODE, _currentCustomerPriceTable.UNIT_CODE); Search(this.pgControl.GetCurrentPage()); } else { MessageBox.Show("请选择正确的行!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("删除失败,请重试或与系统管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } _currentCustomerPriceTable = null; } }
public override string[] doUpdateDB() { BaseCustomerPriceTable CustomerPriceTable = null; BCustomerPrice bCustomerPrice = new BCustomerPrice(); StringBuilder strError = new StringBuilder(); int successData = 0; int failureData = 0; string errorFilePath = ""; string backupFilePath = ""; //数据导入处理 foreach (DataRow dr in _csvDataTable.Rows) { StringBuilder str = new StringBuilder(); //客户编号 str.Append(CheckCustomer(CConvert.ToString(GetValue(dr, "CUSTOMER_CODE")), "客户编号")); //商品编号 if (CConvert.ToString(GetValue(dr, "PRODUCT_CODE")).Length > 20) { string product = GetValue(dr, "PRODUCT_CODE").ToString().Substring(0, 20); str.Append(CheckProduct(product, "商品编号")); } else { str.Append(CheckProduct(CConvert.ToString(GetValue(dr, "PRODUCT_CODE")), "商品编号")); } //单位 str.Append(CheckUnit(CConvert.ToString(GetValue(dr, "UNIT_CODE")), "单位编号")); //单价 str.Append(CheckDecimal(GetValue(dr, "PRICE", 0), 12, 3, "单价")); //状态 str.Append(CheckInt(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS), 9, "状态")); if (str.ToString().Trim().Length > 0) { strError.Append(GetStringBuilder(dr, str.ToString().Trim())); failureData++; continue; } try { CustomerPriceTable = new BaseCustomerPriceTable(); CustomerPriceTable.CUSTOMER_CODE = CConvert.ToString(GetValue(dr, "CUSTOMER_CODE")); if (GetValue(dr, "PRODUCT_CODE").ToString().Length > 20) { CustomerPriceTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_CODE")).Substring(0, 20); } else { CustomerPriceTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_CODE")); } CustomerPriceTable.UNIT_CODE = CConvert.ToString(GetValue(dr, "UNIT_CODE")); CustomerPriceTable.PRICE = CConvert.ToDecimal(GetValue(dr, "PRICE", 0)); CustomerPriceTable.STATUS_FLAG = CConvert.ToInt32(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS)); CustomerPriceTable.CREATE_USER = _userInfo.CODE; CustomerPriceTable.LAST_UPDATE_USER = _userInfo.CODE; if (!bCustomerPrice.Exists(CustomerPriceTable.CUSTOMER_CODE, CustomerPriceTable.PRODUCT_CODE, CustomerPriceTable.UNIT_CODE)) { bCustomerPrice.Add(CustomerPriceTable); } else { bCustomerPrice.Update(CustomerPriceTable); } successData++; } catch { strError.Append(GetStringBuilder(dr, " 数据导入失败,请与系统管理员联系!").ToString()); failureData++; } } //错误记录处理 if (strError.Length > 0) { errorFilePath = WriteFile(strError.ToString()); } //备份处理 backupFilePath = BackupFile(); return(new string[] { successData.ToString(), failureData.ToString(), errorFilePath, backupFilePath }); }