public int UpdateTemp_storage(EntityTemp_storage entity, SearchParameter sp) { //设置更新库存表SQL语句 string SqlStr = ""; SqlStr = "update tc_temp_storage"; SqlStr += " set count= count +" + entity.Count + ""; ArrayList arrayList = sp.Keys(); switch (sp.GetHashTable[arrayList[0]].GetType().Name) { case "String": SqlStr += " where " + arrayList[0].ToString().Replace(":", "") + " like '" + sp.GetValue(arrayList[0].ToString()) + "%'"; break; case "Int32": SqlStr += " where " + arrayList[0].ToString().Replace(":", "") + "= " + sp.GetValue(arrayList[0].ToString()) + ""; break; default: SqlStr += " where " + arrayList[0].ToString().Replace(":", "") + " like '" + sp.GetValue(arrayList[0].ToString()) + "%'"; break; } SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = SqlStr; //执行SQL语句 ExcuteSql(sqlCommand); //返回操作成功结果 return(Constants.SystemConfig.SERVER_SUCCESS); }
//******************************************************************* /// <summary> /// 双击文本框弹出不同的选择窗体 /// </summary> /// <history> /// 完成信息:代国明 2010/07/25 完成 /// 更新信息: /// </history> //******************************************************************* private void textBox_DoubleClick(object sender, EventArgs e) { switch (((TextBox)sender).Name) { //双击文本框弹出弹出产品信息窗体 case "txt_input_code": { //判断当前页面的状态 if (dataType == DataType.Insert) { storageGoodsDialogForm sgd = new storageGoodsDialogForm("报损数量:"); sgd.ShowDialog(); if (sgd.inputCode != string.Empty) { txt_goods_name.Text = sgd.goodName; nud_lose_count.Value = sgd.outputStorage1; txt_input_code.Text = sgd.inputCode; tempStorageEntity = sgd.tempStorageEntity; instorageDate = sgd.instorageDate; } } break; } //双击文本框弹出弹出员工信息窗体 case "txt_lose_applier": { //判断当前页面的状态 if (dataType == DataType.Insert) { StaffForm child = new StaffForm(); child.ShowDialog(); if (child.staffName != string.Empty) { txt_lose_applier.Text = child.staffName; } } break; } //双击文本框弹出弹出员工信息窗体 case "txt_lose_checker": { //判断当前页面的状态 if (dataType == DataType.Insert) { StaffForm child = new StaffForm(); child.ShowDialog(); if (child.staffName != string.Empty) { txt_lose_checker.Text = child.staffName; } } break; } default: break; } }
//*********************************************************************** /// <summary> ///添加销售数量后,更新库存表 /// </summary> /// <history> /// 完成信息:代国明 2010/07/20 完成 /// 更新信息: /// </history> //*********************************************************************** void UpdateStorageDetails(int outputStorage1) { //取得树体类 tempStorageEntity = new EntityTemp_storage(); //赋值实体类 tempStorageEntity.Goods_code = dgvStorageGoods.SelectedRows[0].Cells["goods_code"].Value.ToString(); tempStorageEntity.Count = -outputStorage1; }
//*********************************************************************** /// <summary> /// 删除后复原库存数目数据信息 /// </summary> /// <history> /// 完成信息:代国明 2010/07/22 完成 /// 更新信息: /// </history> //*********************************************************************** void UpdateStorageDetailsbyDelete() { //取得树体类 tempStorageEntity = new EntityTemp_storage(); //赋值实体类 tempStorageEntity.Goods_code = dgvOutputStorage.SelectedRows[0].Cells["input_goods_code"].Value.ToString(); tempStorageEntity.Count = Convert.ToInt32(dgvOutputStorage.SelectedRows[0].Cells["output_count"].Value.ToString()); try { result = -1; //打开数据库连接 dataAccess = new DataAccess(); dataAccess.Open(); //打开事务 dataAccess.BeginTransaction(); SearchParameter sp = new SearchParameter(); sp.SetValue(":goods_code", tempStorageEntity.Goods_code); //取得操作类 GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction); //取得结果符 result = getData.UpdateTemp_storage(tempStorageEntity, sp); //提交事务 dataAccess.Commit(); } catch (Exception ex) { if (dataAccess.Transaction != null) { //回滚 dataAccess.Rollback(); } //提示错误 MessageBox.Show("数据添加时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { //关闭数据库连接 dataAccess.Close(); } }
public int InsertTemp_storageTable(EntityTemp_storage entity) { string SqlStr = ""; SqlStr = "insert into tc_temp_storage(goods_code,count)"; SqlStr += " values('" + entity.Goods_code.Trim() + "'," + entity.Count + ")"; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = SqlStr; try { ExcuteSql(sqlCommand); } catch (Exception ex) { return(Constants.SystemConfig.SERVER_ERROR); throw ex; } return(Constants.SystemConfig.SERVER_SUCCESS); }
//*********************************************************************** /// <summary> /// 双击text事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// 完成信息:代国明 2010/07/22 完成 /// 更新信息: /// </history> //*********************************************************************** private void textBox_DoubleClick(object sender, EventArgs e) { switch (((TextBox)sender).Name) { //双击文本框弹出弹出产品信息窗体 case "txt_goods_name": { //判断当前页面的状态 if (dataType == DataType.Insert) { storageGoodsDialogForm sgd = new storageGoodsDialogForm("退货数量:"); sgd.ShowDialog(); if (sgd.goodName != string.Empty) { //产品名称 txt_goods_name.Text = sgd.goodName; //退货数量 nud_output_count.Value = sgd.outputStorage1; //入库编号 inputCode = sgd.inputCode; //供货商名称 txt_supplier_name.Text = sgd.supplierName; //库存数量临时表 tempStorageEntity = sgd.tempStorageEntity; } } break; } //双击文本框弹出弹出员工信息窗体 case "txt_output_check_persion": { //判断当前页面的状态 if (dataType == DataType.Insert) { StaffForm child = new StaffForm(); child.ShowDialog(); if (child.staffName != string.Empty) { txt_output_check_persion.Text = child.staffName; } } break; } //双击文本框弹出弹出员工信息窗体 case "txt_output_oper": { //判断当前页面的状态 if (dataType == DataType.Insert) { StaffForm child = new StaffForm(); child.ShowDialog(); if (child.staffName != string.Empty) { txt_output_oper.Text = child.staffName; } } break; } //双击文本框弹出弹出员工信息窗体 case "txt_output_issued": { //判断当前页面的状态 if (dataType == DataType.Insert) { StaffForm child = new StaffForm(); child.ShowDialog(); if (child.staffName != string.Empty) { txt_output_issued.Text = child.staffName; } } break; } //双击文本框弹出弹出员工信息窗体 case "txt_output_quality_persion": { //判断当前页面的状态 if (dataType == DataType.Insert) { StaffForm child = new StaffForm(); child.ShowDialog(); if (child.staffName != string.Empty) { txt_output_quality_persion.Text = child.staffName; } } break; } default: break; } }
//*********************************************************************** /// <summary> /// 更新按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// 完成信息:吴小科 2010/07/14 完成 /// 更新信息: /// </history> //*********************************************************************** private void btnCommit_Click(object sender, EventArgs e) { foreach (Control control in groupBox2.Controls) { if (control is TextBox) { if (Util.CheckRegex(control.Text.Trim()) && !((TextBox)control).ReadOnly) { MessageBox.Show("不可以输入非法字符,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); control.Focus(); return; } } } //结果符 result1 = -1; //取得实体类 input_storageEntity = new EntityInput_storage(); //判断该字段是否为空 if (textBox_goods_name.Text.Equals("双击选择一个产品...")) { MessageBox.Show("产品名称不能为空", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textBox_goods_name.Focus(); return; } //赋值实体类 input_storageEntity.INPUT_GOODS_CODE = goods_code; //判断该字段是否为空 if (textBox_input_standard_count.Value == 0) { MessageBox.Show("数量不能为0,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textBox_input_standard_count.Focus(); return; } if (textBox_input_standard_count.Text == "") { MessageBox.Show("数量不能为空,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textBox_input_standard_count.Focus(); return; } input_storageEntity.INPUT_STANDARD_COUNT = (int)textBox_input_standard_count.Value; input_storageEntity.INPUT_ARRIVAL_COUNT = (int)textBox_input_standard_count.Value; //判断时间有效性 if (dataTime_input_maketime.Value.Date > dateTime_input_instorage_date.Value.Date) { MessageBox.Show("生产日期不可大于入库日期", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); dataTime_input_maketime.Focus(); return; } //判断时间有效性 if (DateTime.Now.Date < dateTime_input_instorage_date.Value.Date) { MessageBox.Show("入库时间不可大于今天", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); dateTime_input_instorage_date.Focus(); return; } input_storageEntity.INPUT_MAKETIME = dataTime_input_maketime.Value.Date; input_storageEntity.INPUT_INSTORAGE_DATE = dateTime_input_instorage_date.Value.Date; //判断该字段是否为空 if (textBox_counter_name.Text.Equals("双击选择一个货位...")) { MessageBox.Show("货位不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textBox_counter_name.Focus(); return; } if (textBox_input_oper.Text.Equals("双击选择一个业务员...")) { MessageBox.Show("业务员不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textBox_input_oper.Focus(); return; } if (textBox_input_quality_persion.Text.Equals("双击此处一个质管员...")) { MessageBox.Show("质管员不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textBox_input_quality_persion.Focus(); return; } if (textBox_supplier_name.Text.Equals("双击选择一个供货商...")) { MessageBox.Show("供货商不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textBox_supplier_name.Focus(); return; } if (comboBox_packing_out.Text.Equals("请选择一种包装情况")) { MessageBox.Show("请重新选择包装情况(外)", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); comboBox_packing_out.Focus(); return; } if (comboBox_packing_mid.Text.Equals("请选择一种包装情况")) { MessageBox.Show("请重新选择包装情况(中)", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); comboBox_packing_mid.Focus(); return; } if (comboBox_packing_in.Text.Equals("请选择一种包装情况")) { MessageBox.Show("请重新选择一种包装情况(内)", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); comboBox_packing_in.Focus(); return; } if (textBox_input_batch_num.Text.Trim().Equals(string.Empty)) { MessageBox.Show("批号/设备号不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textBox_input_batch_num.Focus(); return; } input_storageEntity.INPUT_PACKING_OUT = comboBox_packing_out.Text; input_storageEntity.INPUT_PACKING_MID = comboBox_packing_mid.Text; input_storageEntity.INPUT_PACKING_IN = comboBox_packing_in.Text; input_storageEntity.INPUT_REMARK = textBox_input_remark.Text; input_storageEntity.INPUT_BATCH_NUM = textBox_input_batch_num.Text; input_storageEntity.SUPPLIER_NAME = textBox_supplier_name.Text; input_storageEntity.COUNTER_NAME = textBox_counter_name.Text; input_storageEntity.INPUT_OPER = textBox_input_oper.Text; input_storageEntity.INPUT_QUALITY_PERSION = textBox_input_quality_persion.Text; //实体类赋值 input_storageEntity.INPUT_QUALITY_REG = textBox_input_quality_reg.Text; input_storageEntity.INPUT_REMARK = textBox_input_remark.Text; //增加操作 if (dataType == DataType.Insert) { SearchParameter sp = new SearchParameter(); //更新条件参数赋值 sp.SetValue(":goods_code", goods_code); //取得实体类 temp_storageEntity = new EntityTemp_storage(); //赋值实体类 temp_storageEntity.Count = (int)textBox_input_standard_count.Value; try { //打开数据库连接 dataAccess = new DataAccess(); dataAccess.Open(); //取得操作类 GetData getData1 = new GetData(dataAccess.Connection); MakePrimaryKey key = new MakePrimaryKey(dataAccess.Connection, dataAccess.Transaction); input_storageEntity.INPUT_CODE = key.MakeCode("入库"); //取得结果符 result2 = getData1.InsertInput_storageRow(input_storageEntity); result1 = getData1.UpdateTemp_storage(temp_storageEntity, sp); MessageBox.Show("数据已经保存成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { //提示错误 MessageBox.Show("操作数据时发生错误,请检查数据库是否正常开启!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { //关闭数据库连接 dataAccess.Close(); //设置按钮状态 dataType = DataType.None; SetButtonState(); //重新加载画面 BandingDgvCounter(); } } //更新操作 else if (dataType == DataType.Update) { input_storageEntity.INPUT_CODE = textBox_input_code2.Text; //设置更新条件参数 SearchParameter sp = new SearchParameter(); SearchParameter sp1 = new SearchParameter(); //更新条件参数赋值 sp.SetValue(":goods_code", goods_code); sp1.SetValue(":input_code", input_storageEntity.INPUT_CODE); temp_storageEntity = new EntityTemp_storage(); //赋值实体类 temp_storageEntity.Count = (int)textBox_input_standard_count.Value - oldCount; try { //打开数据库连接 dataAccess = new DataAccess(); dataAccess.Open(); //打开事务 dataAccess.BeginTransaction(); GetData getData1 = new GetData(dataAccess.Connection, dataAccess.Transaction); //取得结果符 result2 = getData1.UpdateInput_storageRow(input_storageEntity, sp1); result1 = getData1.UpdateTemp_storage(temp_storageEntity, sp); //提交事务 dataAccess.Commit(); MessageBox.Show("数据已经保存成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { if (dataAccess.Transaction != null) { //回滚 dataAccess.Rollback(); } //提示错误 MessageBox.Show("操作数据时发生错误,请检查数据库是否正常开启!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { //关闭数据库连接 dataAccess.Close(); } //设置按钮状态 dataType = DataType.None; SetButtonState(); //重新加载画面 BandingDgvCounter(); } dataGridView_input_storage.Focus(); }
//*********************************************************************** /// <summary> /// 删除按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// 完成信息:吴小科 2010/07/13 完成 /// 更新信息: /// </history> //*********************************************************************** private void btnDelete_Click(object sender, EventArgs e) { //设置按钮状态 countNum = 0; dataType = DataType.None; SetButtonState(); //如果选择多条数据删除,提示 if (dataGridView_input_storage.SelectedRows.Count > 1) { MessageBox.Show("只能选择一条要删除的记录!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //如果没有选择数据删除,提示 if (dataGridView_input_storage.SelectedRows.Count < 1) { MessageBox.Show("请选择一条要删除的记录!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //设置查询条件参数 SearchParameter sp2 = new SearchParameter(); sp2.SetValue(":TC_INPUT_STORAGE.INPUT_TYPE", '0'); sp2.SetValue(":TC_INPUT_STORAGE.INPUT_CODE", textBox_input_code2.Text); //打开数据库 dataAccess = new DataAccess(); dataAccess.Open(); //获取操作类 GetData getData = new GetData(dataAccess.Connection); //返回绑定数据表 DataTable dtCondition = getData.GetTableBySqlStr(Constants.SqlStr.TC_INPUT_INIT_STORAGE_LEFTJOIN_GOODS, sp2); if (dtCondition.Rows[0]["operate_type"].ToString() == "1") { MessageBox.Show("该入库单已经存在销售或报损记录,不能修改或删除!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //如果选择数据删除,提示 if (MessageBox.Show("您确定要删除该数据吗?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //取得实体类 temp_storageEntity = new EntityTemp_storage(); //赋值实体类 temp_storageEntity.Count = 0 - Convert.ToInt32(textBox_input_standard_count.Value); SearchParameter sp1 = new SearchParameter(); sp1.SetValue(":goods_code", goods_code); try { //设置删除条件参数 SearchParameter sp = new SearchParameter(); //获得表的主健 string input_code = dataGridView_input_storage.SelectedRows[0].Cells["input_code"].Value.ToString(); if (textBox_input_code2.Text != string.Empty) { //删除条件参数赋值 sp.SetValue(":input_code", input_code); } dataAccess = new DataAccess(); //打开数据库连接 dataAccess.Open(); //打开事务 dataAccess.BeginTransaction(); //取得操作类 GetData getData1 = new GetData(dataAccess.Connection, dataAccess.Transaction); //取得结果符 result1 = getData1.DeleteRow("tc_input_storage", sp); result2 = getData1.UpdateTemp_storage(temp_storageEntity, sp1); //提交事务 dataAccess.Commit(); //出现错误,提示信息 if (result1 == -1 || result2 == -1) { MessageBox.Show("操作数据时发生错误,请检查数据库是否正常开启!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } catch (Exception ex) { //回滚 dataAccess.Rollback(); MessageBox.Show("操作数据时发生错误,请检查数据库是否正常开启!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { //关闭数据库连接 dataAccess.Close(); } //判断结果符,0:成功;-1:失败 if (result1 == 0 || result2 == 0) { //加载画面 BandingDgvCounter(); MessageBox.Show("数据已经被成功删除!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("操作数据时发生错误,请检查数据库是否正常开启!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
//******************************************************************* /// <summary> /// 双击文本框弹出不同的选择窗体 /// </summary> /// <history> /// 完成信息:代国明 2010/07/20 完成 /// 更新信息: /// </history> //******************************************************************* private void textBox_DoubleClick(object sender, EventArgs e) { switch (((TextBox)sender).Name) { //双击文本框弹出弹出产品信息窗体 case "txt_goods_name": { //判断当前页面的状态 if (dataType == DataType.Insert) { storageGoodsDialogForm sgd = new storageGoodsDialogForm("销售数量:"); sgd.ShowDialog(); if (sgd.goodName != string.Empty) { txt_goods_name.Text = sgd.goodName; nud_output_count.Value = sgd.outputStorage1; inputCode = sgd.inputCode; tempStorageEntity = sgd.tempStorageEntity; makeTime = sgd.makeTime; instorageDate = sgd.instorageDate; } } break; } //双击文本框弹出弹出员工信息窗体 case "txt_output_check_persion": { //判断当前页面的状态 if (dataType == DataType.Insert) { StaffForm child = new StaffForm(); child.ShowDialog(); if (child.staffName != string.Empty) { txt_output_check_persion.Text = child.staffName; } } break; } //双击文本框弹出弹出员工信息窗体 case "txt_output_oper": { //判断当前页面的状态 if (dataType == DataType.Insert) { StaffForm child = new StaffForm(); child.ShowDialog(); if (child.staffName != string.Empty) { txt_output_oper.Text = child.staffName; } } break; } //双击文本框弹出弹出员工信息窗体 case "txt_output_issued": { //判断当前页面的状态 if (dataType == DataType.Insert) { StaffForm child = new StaffForm(); child.ShowDialog(); if (child.staffName != string.Empty) { txt_output_issued.Text = child.staffName; } } break; } //双击文本框弹出弹出员工信息窗体 case "txt_output_quality_persion": { //判断当前页面的状态 if (dataType == DataType.Insert) { StaffForm child = new StaffForm(); child.ShowDialog(); if (child.staffName != string.Empty) { txt_output_quality_persion.Text = child.staffName; } } break; } //双击文本框弹出弹出客户信息窗体 case "txt_output_customer_name": { //判断当前页面的状态 if (dataType == DataType.Insert) { if (LoginUser.CompanyType == "0") { customerDialogForm customerForm = new customerDialogForm(); customerForm.ShowDialog(); if (customerForm.customerName != string.Empty) { txt_output_customer_name.Text = customerForm.customerName; customerCode = customerForm.customerCode; } } else { persionalDialogForm persionalForm = new persionalDialogForm(); persionalForm.ShowDialog(); if (persionalForm.customerName != string.Empty) { txt_output_customer_name.Text = persionalForm.customerName; customerCode = persionalForm.customerCode; } } } break; } default: break; } }
//*********************************************************************** /// <summary> /// 保存按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// 完成信息:李梓楠 2010/7/15 完成 /// 更新信息: /// </history> //*********************************************************************** private void btnCommit_Click(object sender, EventArgs e) { //判断有效期不能为空 //判断产品名称不能为空 if (txtGoods_name.Text.Trim() == string.Empty) { MessageBox.Show("产品名称不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtGoods_name.Focus(); return; } if (txtGoods_appliance_code.Text.Trim() == string.Empty || txtGoods_appliance_code.Text == "双击选择器械分类...") { MessageBox.Show("器械分类不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtGoods_appliance_code.Focus(); return; } //判断注册证号不能为空 if (txtGoods_reg_num.Text.Trim() == string.Empty) { MessageBox.Show("注册证号不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtGoods_reg_num.Focus(); return; } //判断生产厂家不能为空 if (txtGoods_maker.Text.Trim() == string.Empty || txtGoods_maker.Text == "双击选择生产厂家...") { MessageBox.Show("生产厂家不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtGoods_maker.Focus(); return; } //判断规格型号不能为空 if (txtGoods_type.Text.Trim() == string.Empty) { MessageBox.Show("规格型号不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtGoods_type.Focus(); return; } if (txtGoods_validity.Text.Trim() == string.Empty) { MessageBox.Show("有效期不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtGoods_validity.Focus(); return; } if (int.Parse(txtGoods_validity.Text.Trim()) == 0) { MessageBox.Show("有效期不能为0!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtGoods_validity.Focus(); return; } //判断储藏方法不能为空 if (txtGoods_storemethod.Text.Trim() == string.Empty) { MessageBox.Show("储藏方法不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtGoods_storemethod.Focus(); return; } //判断非法字符 foreach (Control control in groupBox1.Controls) { if (control is TextBox) { if (Util.CheckRegex(control.Text.Trim()) && !((TextBox)control).ReadOnly) { MessageBox.Show("不可以输入非法字符,请重新输入!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); control.Focus(); return; } } } EntityGoods entityGoods = new EntityGoods(); try { result = -1; //如果是添加 if (dataType == DataType.Insert) { entityGoods.Goods_name = txtGoods_name.Text; entityGoods.Goods_yxm = txtGoods_yxm.Text; entityGoods.Goods_reg_num = txtGoods_reg_num.Text; entityGoods.Goods_reg_mark = txtGoods_reg_mark.Text; entityGoods.Goods_type = txtGoods_type.Text; entityGoods.Goods_maker = txtMaker_code.Text; entityGoods.Goods_validity = Convert.ToInt32(txtGoods_validity.Text.Trim()); entityGoods.Goods_unit = cb_goods_unit.SelectedValue.ToString(); entityGoods.Goods_storemethod = txtGoods_storemethod.Text; entityGoods.Goods_appliance_code = txtGoods_appliance_code.Text; dataAccess = new DataAccess(); dataAccess.Open(); MakePrimaryKey primaryKey = new MakePrimaryKey(dataAccess.Connection, dataAccess.Transaction); entityGoods.Goods_code = primaryKey.MakeCode("产品"); GetData getData = new GetData(dataAccess.Connection); result = getData.InsertGoods(entityGoods); if (result == 0) { EntityTemp_storage entityTemp = new EntityTemp_storage(); entityTemp.Goods_code = entityGoods.Goods_code; getData.InsertTemp_storageTable(entityTemp); } } //如果是更新 else if (dataType == DataType.Update) { //给选中行赋值 countNum = dgv.SelectedRows[0].Index; entityGoods.Goods_code = txtGoods_code.Text; entityGoods.Goods_name = txtGoods_name.Text; entityGoods.Goods_yxm = txtGoods_yxm.Text; entityGoods.Goods_reg_num = txtGoods_reg_num.Text; entityGoods.Goods_reg_mark = txtGoods_reg_mark.Text; entityGoods.Goods_type = txtGoods_type.Text; entityGoods.Goods_maker = txtMaker_code.Text; entityGoods.Goods_validity = Convert.ToInt32(txtGoods_validity.Text.Trim()); entityGoods.Goods_unit = cb_goods_unit.SelectedValue.ToString(); entityGoods.Goods_storemethod = txtGoods_storemethod.Text; entityGoods.Goods_appliance_code = txtGoods_appliance_code.Text; dataAccess = new DataAccess(); dataAccess.Open(); dataAccess.BeginTransaction(); GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction); //取得结果符 result = getData.UpdateGoods(entityGoods); //提交事务 dataAccess.Commit(); } } catch (Exception ex) { if (dataAccess.Transaction != null) { //回滚 dataAccess.Rollback(); } //提示错误 MessageBox.Show("数据添加时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); throw ex; } finally { //关闭数据库连接 dataAccess.Close(); } if (result == 0) { MessageBox.Show("数据已经保存成功!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); BandingDgv(); } else { MessageBox.Show("数据保存时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } //设置按钮状态 dataType = DataType.None; setButtonState(); }