private void btn_ok_Click(object sender, EventArgs e) { T_Bllb_StorageDoc_tbsd SC = new T_Bllb_StorageDoc_tbsd(); T_Bllb_StorageDocMaterial_tsdm SCD = new T_Bllb_StorageDocMaterial_tsdm(); bool isSucess = false; if (_IsAddOrEdit == false)//新增 { if (txt_DOC_NO.Text != string.Empty) { SC.S_Doc_NO = txt_DOC_NO.Text.Trim();//单据号 } if (cbo_SourceStorage.SelectedValue.ToString() != string.Empty) { SC.Source_Storage = cbo_SourceStorage.SelectedValue.ToString();//原仓库 } if (cbo_TargetStorage.SelectedValue.ToString() != string.Empty) { SC.Target_Storage = cbo_TargetStorage.SelectedValue.ToString();//目的仓库 } if (txt_memo.Text != string.Empty) { SC.Memo = txt_memo.Text.Trim();//备注 } if (cbo_SourceStorage.SelectedValue.ToString() == cbo_TargetStorage.SelectedValue.ToString()) { new PubUtils().ShowNoteNGMsg("原仓库不能跟目的仓库相同", 2, grade.OrdinaryError); return; } lstMaterial.Clear(); foreach (DataGridViewRow row in dgv_MaterialMoveAdd.Rows) { if (!ValiMaterialCode(row)) { return; } SCD.S_Doc_NO = txt_DOC_NO.Text.Trim(); SCD.RowNumber = SqlInput.ChangeNullToInt(row.Cells["RowNumber"].Value, 0); //行号 SCD.MaterialCode = SqlInput.ChangeNullToString(row.Cells["MaterialCode"].Value); //料号 row.Cells["StorageQTY"].Value = Bll_Bllb_StockInfo_tbsi.GetQty(cbo_SourceStorage.SelectedValue.ToString(), SqlInput.ChangeNullToString(row.Cells["MaterialCode"].Value)); SCD.QTY = SqlInput.ChangeNullToInt(row.Cells["StorageQTY"].Value, 0); //库存量 SCD.Plan_Qty = SqlInput.ChangeNullToInt(row.Cells["Plan_Qty"].Value, 0); //计划数量 lstMaterial.Add(SCD); SCD = new T_Bllb_StorageDocMaterial_tsdm(); } if (lstMaterial.Count > 0) { if (Bll_Bllb_StorageDoc_tbsd.InsertDoc(SC)) { isSucess = Bll_Bllb_StorageDocMaterial_tsdm.InsertMaterial(lstMaterial); } } } else//修改 { lstMaterial.Clear(); foreach (DataGridViewRow row in dgv_MaterialMoveAdd.Rows) { if (!ValiMaterialCode(row)) { return; } SCD.S_Doc_NO = txt_DOC_NO.Text.Trim(); SCD.RowNumber = SqlInput.ChangeNullToInt(row.Cells["RowNumber"].Value, 0); //行号 SCD.MaterialCode = SqlInput.ChangeNullToString(row.Cells["MaterialCode"].Value); //料号 row.Cells["StorageQTY"].Value = Bll_Bllb_StockInfo_tbsi.GetQty(cbo_SourceStorage.SelectedValue.ToString(), SqlInput.ChangeNullToString(row.Cells["MaterialCode"].Value)); SCD.QTY = SqlInput.ChangeNullToInt(row.Cells["StorageQTY"].Value, 0); //库存量 SCD.Plan_Qty = SqlInput.ChangeNullToInt(row.Cells["Plan_Qty"].Value, 0); //计划数量 lstMaterial.Add(SCD); SCD = new T_Bllb_StorageDocMaterial_tsdm(); } if (lstMaterial.Count > 0) { string strWhere = string.Format("S_Doc_NO ='{0}'", txt_DOC_NO.Text.Trim()); if (Bll_Bllb_StorageDocMaterial_tsdm.DeleteMaterial(strWhere)) { isSucess = Bll_Bllb_StorageDocMaterial_tsdm.InsertMaterial(lstMaterial); } } } if (isSucess) { new PubUtils().ShowNoteOKMsg("保存成功!"); this.result = DialogResult.OK; this.Close(); } }