/// <summary> /// 更新一条数据 /// </summary> public bool Update(BaseProductPartsTable model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BASE_PRODUCT_PARTS set "); strSql.Append("QUANTITY=@QUANTITY,"); strSql.Append("STATUS_FLAG=@STATUS_FLAG,"); strSql.Append("LAST_UPDATE_USER=@LAST_UPDATE_USER,"); strSql.Append("LAST_UPDATE_TIME=GETDATE()"); strSql.Append(" where PRODUCT_CODE=@PRODUCT_CODE and PRODUCT_PARTS_CODE=@PRODUCT_PARTS_CODE "); SqlParameter[] parameters = { new SqlParameter("@PRODUCT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@PRODUCT_PARTS_CODE", SqlDbType.VarChar, 20), new SqlParameter("@QUANTITY", SqlDbType.Decimal, 9), new SqlParameter("@STATUS_FLAG", SqlDbType.Int, 4), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; parameters[0].Value = model.PRODUCT_CODE; parameters[1].Value = model.PRODUCT_PARTS_CODE; parameters[2].Value = model.QUANTITY; parameters[3].Value = model.STATUS_FLAG; parameters[4].Value = model.LAST_UPDATE_USER; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 打开新窗口 /// </summary> private void OpenDialogFrm(int mode) { if (mode == CConstant.MODE_NEW || _currentProductPartsTable != null) { FrmSpecificationProductDialog frm = new FrmSpecificationProductDialog(); frm.UserInfo = _userInfo; frm.CurrentProductPartsTable = _currentProductPartsTable; frm.Mode = mode; DialogResult resule = frm.ShowDialog(this); if (resule == DialogResult.OK && isSearch) { Search(this.pgControl.GetCurrentPage()); } frm.Dispose(); } _currentProductPartsTable = null; }
/// <summary> /// 获得当前选中的数据 /// </summary> private void GetCurrentSelectedTable() { try { string productcode = dgvData.SelectedRows[0].Cells["PRODUCT_CODE"].Value.ToString(); string partcode = dgvData.SelectedRows[0].Cells["PRODUCT_PART_CODE"].Value.ToString(); if (productcode != "") { _currentProductPartsTable = bProductParts.GetModel(productcode, partcode); } } catch (Exception ex) { } if (_currentProductPartsTable == null || _currentProductPartsTable.PRODUCT_CODE == null || "".Equals(_currentProductPartsTable.PRODUCT_CODE)) { _currentProductPartsTable = null; } }
private void txtProductCode_Leave(object sender, EventArgs e) { //判断编号是否已存在 if (!string.IsNullOrEmpty(this.txtProductCode.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartsCode.Text.Trim())) { BaseProductPartsTable ProductPartsCode = new BaseProductPartsTable(); ProductPartsCode = bProductParts.GetModel(txtProductCode.Text, txtPartsCode.Text); if (ProductPartsCode != null) { txtProductCode.Text = ""; txtProductName.Text = ""; txtPartsCode.Text = ""; txtProductCode.Focus(); MessageBox.Show("商品编号和材料编号的组合已存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } string product = txtProductCode.Text.Trim(); if (!string.IsNullOrEmpty(product)) { BaseMaster baseMaster = bCommon.GetBaseMaster("PRODUCT", product); if (baseMaster != null) { txtProductCode.Text = baseMaster.Code; txtProductName.Text = baseMaster.Name; txtPartsCode.Focus(); } else { MessageBox.Show("商品编号不存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtProductCode.Text = ""; txtProductName.Text = ""; txtProductCode.Focus(); } } else { txtProductName.Text = ""; } }
/// <summary> /// 打开新窗口 /// </summary> private void OpenDialogFrm(int mode) { if (mode == CConstant.MODE_NEW || _currentProductPartsTable != null) { FrmProductPartsDialog frm = new FrmProductPartsDialog(); frm.UserInfo = _userInfo; frm.CurrentProductPartsTable = _currentProductPartsTable; 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); } _currentProductPartsTable = null; }
/// <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 (_currentProductPartsTable != null) { bProductParts.Delete(_currentProductPartsTable.PRODUCT_CODE, _currentProductPartsTable.PRODUCT_PART_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); } _currentProductPartsTable = null; } }
private void btnSave_Click(object sender, EventArgs e) { if (CheckInput()) { if (_currentProductPartsTable == null) { _currentProductPartsTable = new BaseProductPartsTable(); } _currentProductPartsTable.PRODUCT_CODE = txtProductCode.Text; _currentProductPartsTable.PRODUCT_PART_CODE = txtPartsCode.Text; _currentProductPartsTable.QUANTITY = Convert.ToDecimal(txtQuantity.Text); _currentProductPartsTable.LAST_UPDATE_USER = _userInfo.CODE; try { if (bProductParts.Exists(txtProductCode.Text.Trim(), txtPartsCode.Text.Trim())) { bProductParts.Update(_currentProductPartsTable); } else { _currentProductPartsTable.CREATE_USER = _userInfo.CODE; bProductParts.Add(_currentProductPartsTable); } } catch (Exception ex) { //log.error MessageBox.Show(""); return; } result = DialogResult.OK; this.Close(); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BaseProductPartsTable model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(BaseProductPartsTable model) { return(dal.Add(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(BaseProductPartsTable model) { StringBuilder strSql = null; int rows = 0; if (Exists(model.PRODUCT_CODE, model.PRODUCT_PARTS_CODE)) { #region 更新 strSql = new StringBuilder(); strSql.Append("update BASE_PRODUCT_PARTS set "); strSql.Append("QUANTITY=@QUANTITY,"); strSql.Append("STATUS_FLAG=@STATUS_FLAG,"); strSql.Append("CREATE_USER=@CREATE_USER,"); strSql.Append("CREATE_DATE_TIME=GETDATE(),"); strSql.Append("LAST_UPDATE_USER=@LAST_UPDATE_USER,"); strSql.Append("LAST_UPDATE_TIME=GETDATE()"); strSql.Append(" where PRODUCT_CODE=@PRODUCT_CODE and PRODUCT_PARTS_CODE=@PRODUCT_PARTS_CODE "); SqlParameter[] parameters = { new SqlParameter("@PRODUCT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@PRODUCT_PARTS_CODE", SqlDbType.VarChar, 20), new SqlParameter("@QUANTITY", SqlDbType.Decimal, 9), new SqlParameter("@STATUS_FLAG", SqlDbType.Int, 4), new SqlParameter("@CREATE_USER", SqlDbType.VarChar, 20), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; parameters[0].Value = model.PRODUCT_CODE; parameters[1].Value = model.PRODUCT_PARTS_CODE; parameters[2].Value = model.QUANTITY; parameters[3].Value = model.STATUS_FLAG; parameters[4].Value = model.CREATE_USER; parameters[5].Value = model.LAST_UPDATE_USER; rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); #endregion } else { #region 增加 strSql = new StringBuilder(); strSql.Append("insert into BASE_PRODUCT_PARTS("); strSql.Append("PRODUCT_CODE,PRODUCT_PARTS_CODE,QUANTITY,STATUS_FLAG,CREATE_USER,CREATE_DATE_TIME,LAST_UPDATE_USER,LAST_UPDATE_TIME)"); strSql.Append(" values ("); strSql.Append("@PRODUCT_CODE,@PRODUCT_PARTS_CODE,@QUANTITY,@STATUS_FLAG,@CREATE_USER,GETDATE(),@LAST_UPDATE_USER,GETDATE())"); SqlParameter[] parameters = { new SqlParameter("@PRODUCT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@PRODUCT_PARTS_CODE", SqlDbType.VarChar, 20), new SqlParameter("@QUANTITY", SqlDbType.Decimal, 9), new SqlParameter("@STATUS_FLAG", SqlDbType.Int, 4), new SqlParameter("@CREATE_USER", SqlDbType.VarChar, 20), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; parameters[0].Value = model.PRODUCT_CODE; parameters[1].Value = model.PRODUCT_PARTS_CODE; parameters[2].Value = model.QUANTITY; parameters[3].Value = model.STATUS_FLAG; parameters[4].Value = model.CREATE_USER; parameters[5].Value = model.LAST_UPDATE_USER; rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); #endregion } if (rows > 0) { return(true); } else { return(false); } }
private void btnSave_Click(object sender, EventArgs e) { if (CheckInput()) { //判断编号是否已存在 if (_mode != CConstant.MODE_MODIFY) { if (!string.IsNullOrEmpty(this.txtProductCode.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartsCode.Text.Trim())) { if (bProductParts.Exists(txtProductCode.Text.Trim(), txtPartsCode.Text.Trim())) { MessageBox.Show("规格型号和构成件的组合已存在。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtPartsCode.Text = ""; txtPartsName.Text = ""; txtPartsCode.Focus(); return; } } } if (_currentProductPartsTable == null) { _currentProductPartsTable = new BaseProductPartsTable(); } _currentProductPartsTable.PRODUCT_CODE = txtProductCode.Text.Trim(); _currentProductPartsTable.PRODUCT_PARTS_CODE = txtPartsCode.Text.Trim(); _currentProductPartsTable.QUANTITY = Convert.ToDecimal(txtQuantity.Text.Trim()); _currentProductPartsTable.LAST_UPDATE_USER = _userInfo.CODE; try { bool ret = false; if (bProductParts.Exists(txtProductCode.Text.Trim(), txtPartsCode.Text.Trim())) { ret = bProductParts.Update(_currentProductPartsTable); } else { _currentProductPartsTable.CREATE_USER = _userInfo.CODE; ret = bProductParts.Add(_currentProductPartsTable); } if (ret) { result = DialogResult.OK; if ("btnSaveAndNew".Equals(((Button)sender).Name)) { ClearAll(); } else { this.Close(); } } else { MessageBox.Show("保存失败,请重试或与系统管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("保存失败,请重试或与系统管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); Logger.Error("规格型号构成保存失败。", ex); return; } } }
public override string[] doUpdateDB() { BaseProductPartsTable ProductPartsTable = null; BProductParts bProductParts = new BProductParts(); StringBuilder strError = new StringBuilder(); int successData = 0; int failureData = 0; string errorFilePath = ""; string backupFilePath = ""; //数据导入处理 foreach (DataRow dr in _csvDataTable.Rows) { StringBuilder str = new StringBuilder(); //编号 if (CConvert.ToString(GetValue(dr, "PRODUCT_CODE")).Length > 40) { string product = GetValue(dr, "PRODUCT_CODE").ToString().Substring(0, 40); str.Append(CheckProduct(product, "商品编号")); } else { str.Append(CheckProduct(CConvert.ToString(GetValue(dr, "PRODUCT_CODE")), "商品编号")); } //材料商品编号 if (CConvert.ToString(GetValue(dr, "PRODUCT_PART_CODE")).Length > 40) { string productpart = GetValue(dr, "PRODUCT_PART_CODE").ToString().Substring(0, 40); str.Append(CheckProduct(productpart, "材料商品编号")); } else { str.Append(CheckProduct(CConvert.ToString(GetValue(dr, "PRODUCT_PART_CODE")), "材料商品编号")); } //数量 str.Append(CheckDecimal(GetValue(dr, "QUANTITY", 0), 12, 2, "数量")); //状态 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 { ProductPartsTable = new BaseProductPartsTable(); if (GetValue(dr, "PRODUCT_CODE").ToString().Length > 20) { ProductPartsTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_CODE")).Substring(0, 20); } else { ProductPartsTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_CODE")); } if (GetValue(dr, "PRODUCT_PART_CODE").ToString().Length > 20) { ProductPartsTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_PART_CODE")).Substring(0, 20); } else { ProductPartsTable.PRODUCT_CODE = CConvert.ToString(GetValue(dr, "PRODUCT_PART_CODE")); } ProductPartsTable.QUANTITY = CConvert.ToDecimal(GetValue(dr, "QUANTITY", 0)); ProductPartsTable.STATUS_FLAG = CConvert.ToInt32(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS)); ProductPartsTable.CREATE_USER = _userInfo.CODE; ProductPartsTable.LAST_UPDATE_USER = _userInfo.CODE; if (!bProductParts.Exists(ProductPartsTable.PRODUCT_CODE, ProductPartsTable.PRODUCT_PART_CODE)) { bProductParts.Add(ProductPartsTable); } else { bProductParts.Update(ProductPartsTable); } 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 }); }