public int UpdateInput_storageNUM(EntityInput_storage entity, SearchParameter sp) { //设置更新入库表合格数量SQL语句 string SqlStr = ""; SqlStr = "update tc_input_storage"; SqlStr += " set input_standard_count = input_standard_count +" + entity.INPUT_STANDARD_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); }
public int UpdateInput_storageRow(EntityInput_storage entity, SearchParameter sp) { //设置更新入库表SQL语句 string SqlStr = ""; SqlStr = "update tc_input_storage"; SqlStr += " set input_goods_code='" + entity.INPUT_GOODS_CODE.Trim() + "'"; SqlStr += " ,input_quality_reg='" + entity.INPUT_QUALITY_REG.Trim() + "',input_batch_num='" + entity.INPUT_BATCH_NUM.Trim() + "',input_arrival_count= " + entity.INPUT_ARRIVAL_COUNT + ",input_standard_count= " + entity.INPUT_STANDARD_COUNT; SqlStr += " ,counter_name= '" + entity.COUNTER_NAME.Trim() + "',input_maketime='" + entity.INPUT_MAKETIME + "',input_check_persion='" + entity.INPUT_CHECK_PERSION.Trim() + "',supplier_name = '" + entity.SUPPLIER_NAME.Trim() + ""; SqlStr += "',input_oper= '" + entity.INPUT_OPER.Trim() + "',input_quality_persion= '" + entity.INPUT_QUALITY_PERSION.Trim() + "',input_packing_in='" + entity.INPUT_PACKING_IN.Trim() + "',QUALITY_INFO = '" + entity.QUALITY_INFO.Trim() + "',check_info='" + entity.CHECK_INFO.Trim(); SqlStr += "',input_packing_mid='" + entity.INPUT_PACKING_MID.Trim() + "',input_packing_out='" + entity.INPUT_PACKING_OUT.Trim() + "',input_issued= '" + entity.INPUT_ISSUED.Trim() + "' ,output_code= '" + entity.OUTPUT_CODE.Trim(); SqlStr += "' ,input_remark='" + entity.INPUT_REMARK.Trim() + "',input_instorage_date='" + entity.INPUT_INSTORAGE_DATE + "',input_type='" + entity.INPUT_TYPE + "',operate_type='" + entity.OPERATE_TYPE + "',backstorage_date = "; if (entity.BACKSTORAGE_DATE.ToString("yyyyMMdd").Equals("00010101")) { SqlStr += "null"; } else { SqlStr += "'" + entity.BACKSTORAGE_DATE + "'"; } if (entity.INPUT_CHECKTIME.ToString("yyyyMMdd").Equals("00010101")) { SqlStr += ",input_checktime= " + "null"; } else { SqlStr += ",input_checktime='" + entity.INPUT_CHECKTIME + "'"; } 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); }
//更新入库操作标识,出库和报损专用 public int UpdateOperate_typeByInput_codeRow(EntityInput_storage entity) { string SqlStr = ""; SqlStr = "update tc_input_storage set "; SqlStr += "operate_type = '" + entity.OPERATE_TYPE + "' "; SqlStr += " where input_code= '" + entity.INPUT_CODE.Trim() + "' "; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = SqlStr; ExcuteSql(sqlCommand); return(Constants.SystemConfig.SERVER_SUCCESS); }
public int InsertInput_storageRow(EntityInput_storage entity) { //设置插入入库表SQL语句 string SqlStr = ""; SqlStr = "insert into tc_input_storage"; SqlStr += " values('" + entity.INPUT_CODE.Trim() + "','" + entity.INPUT_GOODS_CODE.Trim(); SqlStr += "','" + entity.INPUT_QUALITY_REG.Trim() + "','" + entity.INPUT_BATCH_NUM.Trim() + "'," + entity.INPUT_ARRIVAL_COUNT + "," + entity.INPUT_STANDARD_COUNT; SqlStr += ",'" + entity.COUNTER_NAME.Trim() + "','" + entity.SUPPLIER_NAME.Trim() + "','" + entity.INPUT_CHECK_PERSION.Trim(); SqlStr += "','" + entity.INPUT_OPER.Trim() + "','" + entity.INPUT_QUALITY_PERSION.Trim() + "','" + entity.INPUT_ISSUED.Trim() + "','" + entity.INPUT_PACKING_IN.Trim(); SqlStr += "','" + entity.INPUT_PACKING_MID.Trim() + "','" + entity.INPUT_PACKING_OUT.Trim() + "','" + entity.INPUT_REMARK.Trim() + "','" + entity.INPUT_INSTORAGE_DATE; SqlStr += "','" + entity.INPUT_MAKETIME + "',"; if (entity.INPUT_CHECKTIME.ToString("yyyyMMdd").Equals("00010101")) { SqlStr += "null,"; } else { SqlStr += "'" + entity.INPUT_CHECKTIME + "',"; } SqlStr += "'" + entity.INPUT_TYPE + "','" + entity.OPERATE_TYPE + "',"; if (entity.BACKSTORAGE_DATE.ToString("yyyyMMdd").Equals("00010101")) { SqlStr += "null,"; } else { SqlStr += "'" + entity.BACKSTORAGE_DATE + "',"; } SqlStr += "'" + entity.OUTPUT_CODE.Trim() + "','" + entity.QUALITY_INFO.Trim() + "','" + entity.CHECK_INFO.Trim() + "')"; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = SqlStr; //执行SQL语句 ExcuteSql(sqlCommand); //返回操作成功结果 return(Constants.SystemConfig.SERVER_SUCCESS); }
//*********************************************************************** /// <summary> /// 确认按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// 完成信息:代国明 2010/07/22 完成 /// 更新信息: /// </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; } } } if (txt_goods_name.Text.Trim() == "双击选择产品..." || txt_goods_name.Text.Trim() == string.Empty) { MessageBox.Show("产品名称不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_goods_name.Focus(); return; } if (txt_supplier_name.Text.Trim() == string.Empty) { MessageBox.Show("供货商不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_supplier_name.Focus(); return; } if (nud_output_count.Value == 0) { MessageBox.Show("退货数量不能为0!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); nud_output_count.Select(); return; } //判断时间有效性 if (DateTime.Now.Date < dtp_output_checktime.Value.Date) { MessageBox.Show("请选择一个正确的验收日期!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); dtp_output_checktime.Select(); return; } //判断时间有效性 if (dtp_output_instorage_date.Value.Date > dtp_output_checktime.Value.Date) { MessageBox.Show("请选择一个正确的出库日期!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); dtp_output_instorage_date.Select(); return; } if (txt_output_check_persion.Text.Trim() == "双击选择验收人..." || txt_output_check_persion.Text.Trim() == string.Empty) { MessageBox.Show("验收人不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_output_check_persion.Focus(); return; } if (txt_output_quality_persion.Text.Trim() == "双击选择质管员..." || txt_output_quality_persion.Text.Trim() == string.Empty) { MessageBox.Show("质管员不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_output_quality_persion.Focus(); return; } if (txt_output_oper.Text.Trim() == "双击选择业务员..." || txt_output_oper.Text.Trim() == string.Empty) { MessageBox.Show("业务员不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_output_oper.Focus(); return; } if (txt_output_issued.Text.Trim() == "双击选择经办人..." || txt_output_issued.Text.Trim() == string.Empty) { MessageBox.Show("经办人不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_output_issued.Focus(); return; } //if (cmb_output_packing_in.Text.Equals("请选择一种包装情况")) //{ // MessageBox.Show("请选择一种包装情况", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // cmb_output_packing_in.Focus(); // return; //} //if (cmb_output_packing_mid.Text.Equals("请选择一种包装情况")) //{ // MessageBox.Show("请选择一种包装情况", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // cmb_output_packing_mid.Focus(); // return; //} //if (cmb_output_packing_out.Text.Equals("请选择一种包装情况")) //{ // MessageBox.Show("请选择一种包装情况", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // cmb_output_packing_out.Focus(); // return; //} //添加后库存数目剪掉添加数目数据信息 UpdateStorageDetailsByAdd(); try { result = -1; //如果是添加 if (dataType == DataType.Insert) { //取得实体类 outputStorageEntity = new EntityOutput_storage(); //赋值实体类 outputStorageEntity.Output_checktime = Convert.ToDateTime(dtp_output_checktime.Value.ToString("yyyy-MM-dd")); outputStorageEntity.Output_instorage_date = Convert.ToDateTime(dtp_output_instorage_date.Value.ToString("yyyy-MM-dd")); outputStorageEntity.Output_count = Convert.ToInt32(nud_output_count.Value); outputStorageEntity.Input_code = inputCode; outputStorageEntity.Output_packing_in = cmb_output_packing_in.Text.ToString(); outputStorageEntity.Output_packing_mid = cmb_output_packing_mid.Text.ToString(); outputStorageEntity.Output_packing_out = cmb_output_packing_out.Text.ToString(); outputStorageEntity.Output_oper = txt_output_oper.Text.ToString(); outputStorageEntity.Output_quality_persion = txt_output_quality_persion.Text.ToString(); outputStorageEntity.Output_issued = txt_output_issued.Text.ToString(); outputStorageEntity.Output_check_persion = txt_output_check_persion.Text.ToString(); outputStorageEntity.Output_backreason = txt_output_reback_reason.Text.ToString(); outputStorageEntity.Output_remark = txt_output_remark.Text.ToString(); outputStorageEntity.Output_type = "1"; outputStorageEntity.Operate_type = "0"; //赋值实体类 inputStorageEntity = new EntityInput_storage(); inputStorageEntity.OPERATE_TYPE = '1'; inputStorageEntity.INPUT_CODE = inputCode; //打开数据库连接 dataAccess = new DataAccess(); dataAccess.Open(); MakePrimaryKey mpk = new MakePrimaryKey(dataAccess.Connection, dataAccess.Transaction); outputStorageEntity.Output_code = mpk.MakeCode("出库"); //取得操作类 GetData getData = new GetData(dataAccess.Connection); //取得结果符 result = getData.InsertOutput_storageRow(outputStorageEntity); if (result == 0) { MessageBox.Show("数据已经保存成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("数据已经保存失败!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } getData.UpdateOperate_typeByInput_codeRow(inputStorageEntity); } } catch (Exception ex) { if (dataAccess.Transaction != null) { //回滚 dataAccess.Rollback(); } //提示错误 MessageBox.Show("数据添加时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { //关闭数据库连接 dataAccess.Close(); //设置按钮状态 dataType = DataType.None; setButtonState(); //重新加载画面 BindingDgvOutputStorage(); } }
//*********************************************************************** /// <summary> /// 删除按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// 完成信息:代国明 2010/07/22 完成 /// 更新信息: /// </history> //*********************************************************************** private void btnDelete_Click(object sender, EventArgs e) { //设置按钮状态 dataType = DataType.None; setButtonState(); //结果符 result = -1; countNum = 0; //取得单表类 DataTable dtLose = GetLoseTable(); //如果选择多条数据删除,提示 if (dgvOutputStorage.SelectedRows.Count > 1) { MessageBox.Show("只能选择一条要作废的记录!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //如过画面中不存在数据,提示 if (dgvOutputStorage.SelectedRows.Count < 1) { MessageBox.Show("请选择一条要作废的记录!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Boolean bs = JudgeMaintain(); //弹出提示,确认删除 if (MessageBox.Show("您确定要作废该数据吗?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { try { //初始化参数类 SearchParameter sp = new SearchParameter(); //设置主键 sp.SetValue(":OUTPUT_CODE", dgvOutputStorage.SelectedRows[0].Cells["output_code"].Value.ToString()); //打开数据库 dataAccess = new DataAccess(); dataAccess.Open(); //打开事务 dataAccess.BeginTransaction(); //取得操作类 GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction); //判断报损表是否有标识 Boolean flag = false; if (JudgeOutputStorage()) { //遍历报损表 foreach (DataRow dr in dtLose.Rows) { if (dr["input_code"].ToString() == dgvOutputStorage.SelectedRows[0].Cells["input_code"].Value.ToString()) { flag = true; break; } } //如果报损表该删除的入库记录,将入库标识置为1 if (!flag && !bs) { inputStorageEntity = new EntityInput_storage(); inputStorageEntity.INPUT_CODE = dgvOutputStorage.SelectedRows[0].Cells["input_code"].Value.ToString(); inputStorageEntity.OPERATE_TYPE = '0'; getData.UpdateOperate_typeByInput_codeRow(inputStorageEntity); } else { inputStorageEntity = new EntityInput_storage(); inputStorageEntity.INPUT_CODE = dgvOutputStorage.SelectedRows[0].Cells["input_code"].Value.ToString(); inputStorageEntity.OPERATE_TYPE = '1'; getData.UpdateOperate_typeByInput_codeRow(inputStorageEntity); } } //取得结果符 result = getData.DeleteRow("TC_OUTPUT_STORAGE", sp); //提交事务 dataAccess.Commit(); } catch (Exception ex) { //回滚 dataAccess.Rollback(); MessageBox.Show(ex.Message); } finally { //关闭数据库连接 dataAccess.Close(); //判断结果符,0:成功;-1:失败 if (result == 0) { MessageBox.Show("数据已经被成功作废!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); UpdateStorageDetailsbyDelete(); //加载画面 BindingDgvOutputStorage(); } else { MessageBox.Show("数据作废时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
//*********************************************************************** /// <summary> /// 确认按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// 完成信息:代国明 2010/07/25 完成 /// 更新信息: /// </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; } } } //条件不为空 if (txt_input_code.Text.Trim() == string.Empty || txt_input_code.Text.Trim() == "双击选择入库编号...") { MessageBox.Show("入库编号不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_input_code.Focus(); return; } if (txt_goods_name.Text.Trim() == string.Empty) { MessageBox.Show("产品编号不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_goods_name.Focus(); return; } //判断时间有效性 if (DateTime.Now.Date < dtp_lose_datetime.Value.Date) { MessageBox.Show("报损日期不能大于今天!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); dtp_lose_datetime.Focus(); return; } if (instorageDate > dtp_lose_datetime.Value.Date) { MessageBox.Show("报损日期不能小于入库日期!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); dtp_lose_datetime.Focus(); return; } if (txt_lose_applier.Text.Trim() == "双击选择报损申请人..." || txt_lose_applier.Text.Trim() == string.Empty) { MessageBox.Show("报损申请人不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_lose_applier.Focus(); return; } if (txt_lose_checker.Text.Trim() == "双击选择报损核准人..." || txt_lose_checker.Text.Trim() == string.Empty) { MessageBox.Show("报损核准人不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txt_lose_checker.Focus(); return; } //添加,修改后库存数目剪掉添加数目数据信息 UpdateStorageDetailsByAdd(); try { result = -1; //如果是添加 if (dataType == DataType.Insert) { //取得实体类 loseEntity = new EntityLose(); //赋值实体类 loseEntity.Input_code = txt_input_code.Text.ToString(); loseEntity.Lose_applier = txt_lose_applier.Text.ToString(); loseEntity.Lose_checker = txt_lose_checker.Text.ToString(); loseEntity.Lose_count = int.Parse(nud_lose_count.Value.ToString()); loseEntity.Lose_reason = txt_lose_reason.Text.ToString(); loseEntity.Lose_remark = txt_lose_remark.Text.ToString(); loseEntity.Lose_result = txt_lose_result.Text.ToString(); loseEntity.Lose_datetime = Convert.ToDateTime(dtp_lose_datetime.Value.ToString("yyyy-MM-dd")); //赋值实体类 inputStorageEntity = new EntityInput_storage(); inputStorageEntity.OPERATE_TYPE = '1'; inputStorageEntity.INPUT_CODE = txt_input_code.Text.ToString(); //打开数据库连接 dataAccess = new DataAccess(); dataAccess.Open(); //取得操作类 GetData getData = new GetData(dataAccess.Connection); //生成主键 MakePrimaryKey mpk = new MakePrimaryKey(dataAccess.Connection, dataAccess.Transaction); loseEntity.Lose_code = mpk.MakeCode("报损表"); //取得结果符 result = getData.InsertLoseRow(loseEntity); if (result == 0) { MessageBox.Show("数据已经保存成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("数据已经保存失败!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } getData.UpdateOperate_typeByInput_codeRow(inputStorageEntity); } } catch (Exception ex) { if (dataAccess.Transaction != null) { //回滚 dataAccess.Rollback(); } //提示错误 MessageBox.Show("数据时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { //关闭数据库连接 dataAccess.Close(); } //设置按钮状态 dataType = DataType.None; setButtonState(); //重新加载画面 BandingDgvLose(); }
/// <summary> /// 删除按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// 完成信息:李梓楠 2010/7/21 完成 /// 更新信息: /// </history> private void btnDelete_Click(object sender, EventArgs e) { result = -1; countNum = 0; int result1 = -1; if (dgv.SelectedRows.Count > 1) { MessageBox.Show("只能选择一条要删除的记录!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (dgv.SelectedRows.Count < 1) { MessageBox.Show("请选择一条要删除的记录!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("您确定要删除该养护记录吗?如果删除该记录,明细记录也会被同时删除!", Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { try { SearchParameter sp = new SearchParameter(); sp.SetValue(":maintain_code", dgv.SelectedRows[0].Cells["maintain_code"].Value.ToString()); dataAccess = new DataAccess(); dataAccess.Open(); dataAccess.BeginTransaction(); GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction); result = getData.DeleteRow("tc_maintain", sp); result1 = getData.DeleteRow("tc_maintain_detail", sp); dataAccess.Commit(); } catch (Exception ex) { dataAccess.Rollback(); MessageBox.Show(ex.Message); throw ex; } finally { dataAccess.Close(); } if (result == 0 && result1 == 0) { if (!updateMark()) { try { dataAccess = new DataAccess(); dataAccess.Open(); GetData getData = new GetData(dataAccess.Connection); //处理操作标示 EntityInput_storage inputStorageEntity = new EntityInput_storage(); inputStorageEntity.OPERATE_TYPE = '0'; inputStorageEntity.INPUT_CODE = txtMaintain_input_code.Text; result = getData.UpdateOperate_typeByInput_codeRow(inputStorageEntity); } catch (Exception ex) { MessageBox.Show("请查看数据库是否正常!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { if (dataAccess.Connection != null) { dataAccess.Close(); } } } MessageBox.Show("数据已经被成功删除!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); BandingDgv(); } else { MessageBox.Show("数据删除时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
//*********************************************************************** /// <summary> /// 保存按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// 完成信息:李梓楠 2010/7/21 完成 /// 更新信息: /// </history> //*********************************************************************** private void btnCommit_Click(object sender, EventArgs e) { //判断入库编号不为空 if (txtMaintain_input_code.Text.Trim() == string.Empty || txtMaintain_input_code.Text == "双击选择入库编号...") { MessageBox.Show("入库编号不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtMaintain_input_code.Focus(); return; } //判断时间有效性 if (DateTime.Now.Date < dateMaintain_create_date.Value.Date) { MessageBox.Show("建档日期不可大于今天日期!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); dateMaintain_create_date.Focus(); return; } if (inStorageDate > dateMaintain_create_date.Value.Date) { MessageBox.Show("建档日期不可小于入库日期!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); dateMaintain_create_date.Focus(); return; } //判断非法字符 foreach (Control control in groupBox2.Controls) { if (control is TextBox) { if (Util.CheckRegex(control.Text.Trim()) && !((TextBox)control).ReadOnly) { MessageBox.Show("不可以输入非法字符,请重新输入!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); control.Focus(); return; } } } EntityMaintain entity = new EntityMaintain(); try { result = -1; //如果是添加 if (dataType == DataType.Insert) { entity.Maintain_input_code = txtMaintain_input_code.Text; entity.Maintain_application = txtMaintain_application.Text; entity.Maintain_purpose = txtMaintain_purpose.Text; entity.Maintain_quality = txtMaintain_quality.Text; entity.Maintain_test_items = txtMaintain_test_items.Text; entity.Maintain_characters = txtMaintain_characters.Text; entity.Maintain_create_date = dateMaintain_create_date.Value.Date; dataAccess = new DataAccess(); dataAccess.Open(); MakePrimaryKey primaryKey = new MakePrimaryKey(dataAccess.Connection, dataAccess.Transaction); entity.Maintain_code = primaryKey.MakeCode("养护记录"); GetData getData = new GetData(dataAccess.Connection); result = getData.InsertMaintainTable(entity); //处理操作标示 EntityInput_storage inputStorageEntity = new EntityInput_storage(); inputStorageEntity.OPERATE_TYPE = '1'; inputStorageEntity.INPUT_CODE = txtMaintain_input_code.Text; result = getData.UpdateOperate_typeByInput_codeRow(inputStorageEntity); } //如果是更新 else if (dataType == DataType.Update) { //给选中行赋值 countNum = dgv.SelectedRows[0].Index; entity.Maintain_code = dgv.SelectedRows[0].Cells["Maintain_code"].Value.ToString(); entity.Maintain_input_code = txtMaintain_input_code.Text; entity.Maintain_application = txtMaintain_application.Text; entity.Maintain_purpose = txtMaintain_purpose.Text; entity.Maintain_quality = txtMaintain_quality.Text; entity.Maintain_test_items = txtMaintain_test_items.Text; entity.Maintain_characters = txtMaintain_characters.Text; entity.Maintain_create_date = dateMaintain_create_date.Value.Date; dataAccess = new DataAccess(); dataAccess.Open(); dataAccess.BeginTransaction(); GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction); //取得结果符 result = getData.UpdateMaintainTable(entity); //提交事务 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(); //重新加载画面 BandingDgv(); }
//*********************************************************************** /// <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(); }