protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string strMessage = string.Empty; string strCheck = string.Empty; string strScript = string.Empty; string strUpdatedBy = Session["username"].ToString(); Label lblbudget_receive_doc = (Label)GridView1.Rows[e.RowIndex].FindControl("lblbudget_receive_doc"); cBudget_receive obudget_receive = new cBudget_receive(); try { obudget_receive.SP_BUDGET_RECEIVE_HEAD_DEL(lblbudget_receive_doc.Text); } catch (Exception ex) { if (ex.Message.Contains("REFERENCE constraint")) { MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว"); } else { lblError.Text = ex.Message.ToString(); } } finally { obudget_receive.Dispose(); } BindGridView(0); }
private bool DeleteRecvDetail(string pbudget_receive_doc) { var oBudget_receive = new cBudget_receive(); try { return(oBudget_receive.SP_BUDGET_RECEIVE_DETAIL_DEL(pbudget_receive_doc)); } catch (Exception ex) { if (ex.Message.Contains("REFERENCE constraint")) { MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว"); } else { lblError.Text = ex.Message.ToString(); } } finally { oBudget_receive.Dispose(); } return(false); }
private bool saveBudgetReceive() { bool blnResult = false; Budget_receive_head budget_receive_head = new Budget_receive_head(); cBudget_receive oBudget_receive = new cBudget_receive(); try { #region set Data budget_receive_head.budget_receive_doc = txtbudget_receive_doc.Text; budget_receive_head.budget_receive_date = cCommon.GetDate(txtdeduct_date.Text); budget_receive_head.budget_receive_year = cboYear.SelectedValue; budget_receive_head.budget_type = this.BudgetType; budget_receive_head.budget_plan_code = txtbudget_plan_code.Text; budget_receive_head.degree_code = cboDegree.SelectedValue; budget_receive_head.item_group_detail_id = int.Parse(cboItem_group_detail.SelectedValue); budget_receive_head.budget_receive_comment = txtcomment.Text.Trim(); budget_receive_head.c_created_by = Session["username"].ToString(); budget_receive_head.c_updated_by = Session["username"].ToString(); #endregion if (ViewState["mode"].ToString().ToLower().Equals("edit")) { if (oBudget_receive.SP_BUDGET_RECEIVE_HEAD_UPD(budget_receive_head)) { saveRecvDetail(); oBudget_receive.SP_BUDGET_RECEIVE_TOTAL_UPD(txtbudget_receive_doc.Text); } } else { oBudget_receive.SP_BUDGET_RECEIVE_HEAD_INS(budget_receive_head); txtbudget_receive_doc.Text = budget_receive_head.budget_receive_doc; } blnResult = true; } catch (Exception ex) { if (ex.Message.Contains("duplicate key")) { MsgBox("ข้อมูลซ้ำโปรดตรวจสอบ"); } else { lblError.Text = ex.Message.ToString(); } } finally { oBudget_receive.Dispose(); } return(blnResult); }
private void BindGridView(int nPageNo) { var obudget_receive = new cBudget_receive(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; var budget_receive_head = new view_Budget_receive_head(); string strScript = string.Empty; #region Criteria budget_receive_head.budget_receive_year = cboYear.SelectedValue; budget_receive_head.degree_code = cboDegree.SelectedValue; budget_receive_head.budget_receive_doc = txtbudget_receive_doc.Text.Replace("'", "''").Trim(); budget_receive_head.budget_plan_code = txtbudget_plan_code.Text.Replace("'", "''").Trim(); budget_receive_head.unit_code = cboUnit.SelectedValue; budget_receive_head.budget_code = cboBudget.SelectedValue; budget_receive_head.produce_code = cboProduce.SelectedValue; budget_receive_head.activity_code = cboActivity.SelectedValue; budget_receive_head.plan_code = cboPlan_code.SelectedValue; budget_receive_head.item_group_code = cboItem_group.SelectedValue; budget_receive_head.item_group_detail_code = cboItem_group_detail.SelectedValue; if (!budget_receive_head.budget_receive_year.Equals("")) { strCriteria = strCriteria + " And (budget_receive_year = '" + budget_receive_head.budget_receive_year + "') "; } if (!budget_receive_head.degree_code.Equals("")) { strCriteria = strCriteria + " And (degree_code = '" + budget_receive_head.degree_code + "') "; } if (!string.IsNullOrEmpty(txtdate_begin.Text)) { strCriteria = strCriteria + " And (budget_receive_date >= '" + cCommon.SeekDate(txtdate_begin.Text) + "') "; } if (!string.IsNullOrEmpty(txtdate_end.Text)) { strCriteria = strCriteria + " And (budget_receive_date <= '" + cCommon.SeekDate(txtdate_end.Text) + "') "; } if (!budget_receive_head.budget_receive_doc.Equals("")) { strCriteria = strCriteria + " And (budget_receive_doc LIKE '%" + budget_receive_head.budget_receive_doc + "%') "; } if (!budget_receive_head.budget_plan_code.Equals("")) { strCriteria = strCriteria + " And (budget_plan_code ='" + budget_receive_head.budget_plan_code + "') "; } if (!budget_receive_head.unit_code.Equals("")) { strCriteria = strCriteria + " And (unit_code ='" + budget_receive_head.unit_code + "') "; } if (!budget_receive_head.budget_code.Equals("")) { strCriteria = strCriteria + " And (budget_code ='" + budget_receive_head.budget_code + "') "; } if (!budget_receive_head.produce_code.Equals("")) { strCriteria = strCriteria + " And (produce_code ='" + budget_receive_head.produce_code + "') "; } if (!budget_receive_head.activity_code.Equals("")) { strCriteria = strCriteria + " And (activity_code = '" + budget_receive_head.activity_code + "') "; } if (!budget_receive_head.plan_code.Equals("")) { strCriteria = strCriteria + " And (plan_code = '" + budget_receive_head.plan_code + "') "; } if (!budget_receive_head.item_group_code.Equals("")) { strCriteria = strCriteria + " And (item_group_code = '" + budget_receive_head.item_group_code + "') "; } if (!budget_receive_head.item_group_detail_code.Equals("")) { strCriteria = strCriteria + " And (item_group_detail_code = '" + budget_receive_head.item_group_detail_code + "') "; } if (DirectorLock == "Y") { strCriteria += " and substring(director_code,4,2) = substring('" + DirectorCode + "',4,2) "; } #endregion strCriteria = strCriteria + " and budget_type ='" + this.BudgetType + "' "; try { if (!obudget_receive.SP_BUDGET_RECEIVE_HEAD_SEL(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { try { GridView1.PageIndex = nPageNo; txthTotalRecord.Value = ds.Tables[0].Rows.Count.ToString(); ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } catch { GridView1.PageIndex = 0; txthTotalRecord.Value = ds.Tables[0].Rows.Count.ToString(); ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { obudget_receive.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }
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); }