private bool saveRecvDetail() { bool blnResult = false; cBudget_receive oBudget_receive = new cBudget_receive(); cBudget_money oBudget_money = new cBudget_money(); cCommon oCommon = new cCommon(); var ds = new DataSet(); DataTable dt = null; var major_director_code = string.Empty; oCommon.SEL_SQL("select g_code from General where g_type = 'main_director_code'", ref ds, ref _strMessage); dt = ds.Tables[0]; if (dt.Rows.Count > 0) { major_director_code = "M" + cboYear.SelectedValue.Substring(2, 2) + dt.Rows[0]["g_code"].ToString(); } _strCriteria = " and budget_money_doc = '" + txtbudget_money_doc.Text + "' "; _strCriteria += " and major_code in (select '" + major_director_code + "' union all select '" + cboMajor.SelectedValue + "') "; var listBudget_major = oBudget_money.GETMONEYDETAILS(_strCriteria); if (listBudget_major != null) { List <Budget_receive_detail> listBudget_receive_detail = new List <Budget_receive_detail>(); try { decimal detail_contribute = 0; foreach (var row in listBudget_major) { if (row.major_code == major_director_code) { detail_contribute = decimal.Parse(txtdeduct_total_reduce_director.Value.ToString()); } else { detail_contribute = decimal.Parse(txtdeduct_total_remain.Value.ToString()); } listBudget_receive_detail.Add(new Budget_receive_detail { budget_receive_doc = txtbudget_receive_doc.Text, budget_money_major_id = row.budget_money_major_id, budget_receive_detail_contribute = detail_contribute, c_created_by = Session["username"].ToString(), c_updated_by = Session["username"].ToString() }); } DeleteRecvDetail(txtbudget_receive_doc.Text); if (listBudget_receive_detail.Any()) { foreach (var major in listBudget_receive_detail) { oBudget_receive.SP_BUDGET_RECEIVE_DETAIL_INS(major); } } blnResult = true; } catch (Exception ex) { if (ex.Message.Contains("duplicate key")) { MsgBox("ข้อมูลซ้ำโปรดตรวจสอบ"); } else { lblError.Text = ex.Message.ToString(); } } finally { oBudget_receive.Dispose(); } } return(blnResult); }