private void btn_save_Click(object sender, EventArgs e) { if (dgv_doc.Rows.Count == 0) { MsgBox.Error("记录行为0,无需保存!"); return; } List <T_Bllb_StorageDoc_tbsd> List_tbsd = new List <T_Bllb_StorageDoc_tbsd>(); T_Bllb_StorageDoc_tbsd model_tbsd = new T_Bllb_StorageDoc_tbsd(); model_tbsd.S_Doc_NO = dtDoc.Rows[0]["S_Doc_NO"].ToString(); model_tbsd.Source_Storage = dtDoc.Rows[0]["Source_Storage"].ToString(); model_tbsd.S_Doc_Type = dtDoc.Rows[0]["S_Doc_Type"].ToString(); model_tbsd.Creator = PubUtils.uContext.UserID; List_tbsd.Add(model_tbsd); List <T_Bllb_StorageDocMaterial_tsdm> List_tbdm = new List <T_Bllb_StorageDocMaterial_tsdm>(); T_Bllb_StorageDocMaterial_tsdm model_tsdm = new T_Bllb_StorageDocMaterial_tsdm(); foreach (DataRow dr in dtDoc.Rows) { model_tsdm.S_Doc_NO = dr["S_Doc_NO"].ToString(); model_tsdm.MaterialCode = dr["MaterialCode"].ToString(); model_tsdm.Plan_Qty = Convert.ToInt32(dr["Quantity"].ToString()); List_tbdm.Add(model_tsdm); model_tsdm = new T_Bllb_StorageDocMaterial_tsdm(); } if (BLL_Bllb_StorageDoc_tbsd.SaveStorageDoc(List_tbsd, List_tbdm)) { model_tbsd = new T_Bllb_StorageDoc_tbsd(); this.DialogResult = DialogResult.OK; } this.Close(); }
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(); } }