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 lblitem_acc_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblitem_acc_code"); HiddenField hdditem_acc_id = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdditem_acc_id"); cItem_acc oItem_acc = new cItem_acc(); try { if (!oItem_acc.SP_ITEM_ACC_DEL(hdditem_acc_id.Value.ToString(), "N", strUpdatedBy, ref strMessage)) { lblError.Text = strMessage; } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oItem_acc.Dispose(); } BindGridView(0); }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string strMessage = string.Empty; string strCheck = string.Empty; string strScript = string.Empty; Label lblitem_acc_doc = (Label)GridView1.Rows[e.RowIndex].FindControl("lblitem_acc_doc"); cItem_acc oitem_acc = new cItem_acc(); try { if (!oitem_acc.SP_ITEM_ACC_HEAD_DEL(lblitem_acc_doc.Text, ref strMessage)) { lblError.Text = strMessage; } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oitem_acc.Dispose(); } BindGridView(0); }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string strMessage = string.Empty; string strScript = string.Empty; HiddenField hdditem_acc_detail_id = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdditem_acc_detail_id"); cItem_acc oItem_acc = new cItem_acc(); try { if (!oItem_acc.SP_ITEM_ACC_DETAIL_DEL(hdditem_acc_detail_id.Value.ToString(), ref strMessage)) { lblError.Text = strMessage; } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oItem_acc.Dispose(); } BindGridView(); }
private void BindGridView() { string strMessage = string.Empty; string strCriteria = string.Empty; string strunit_code = string.Empty; cItem_acc oItem_acc = new cItem_acc(); DataSet ds = new DataSet(); try { strCriteria = " And item_acc_doc ='" + ViewState["item_acc_doc"].ToString() + "' "; if (!oItem_acc.SP_ITEM_ACC_DETAIL_SEL(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count == 0) { strCriteria = " And pay_month ='" + cboPay_Month.SelectedValue + "' "; strCriteria += " And pay_year ='" + cboPay_Year.SelectedValue + "' "; if (base.myBudgetType == "B") { strCriteria += " And payment_detail_person_group_code in (" + PersonGroupList + ",'') "; } if (base.myBudgetType != "M") { strCriteria += " And payment_detail_budget_type ='" + base.myBudgetType + "' "; } if (!oItem_acc.SP_ITEM_ACC_TMP_SEL(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } } ds.Tables[0].DefaultView.Sort = ViewState["sort"].ToString() + " " + ViewState["direction"].ToString(); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { if (GridView1.Rows.Count == 0) { EmptyGridFix(GridView1); } oItem_acc.Dispose(); ds.Dispose(); } }
private void BindGridView(int nPageNo) { cItem_acc oItem_acc = new cItem_acc(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strActive = string.Empty; string strYear = string.Empty; strYear = cboYear.SelectedValue; if (!strYear.Equals("")) { strCriteria = strCriteria + " And (item_acc_year = '" + strYear + "') "; } strCriteria += " And budget_type ='" + this.BudgetType + "' "; strCriteria += " And c_created_by = '" + UserLoginName + "' "; try { if (!oItem_acc.SP_ITEM_ACC_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 { oItem_acc.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }
private void BindGridView(int nPageNo) { cItem_acc oItem_acc = new cItem_acc(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string stritem_acc_code = string.Empty; string stritem_acc_name = string.Empty; string strActive = string.Empty; string stritem_acc_year = string.Empty; stritem_acc_code = txtitem_acc_code.Text.Replace("'", "''").Trim(); stritem_acc_name = txtitem_acc_name.Text.Replace("'", "''").Trim(); stritem_acc_year = cboYear.SelectedValue; if (!stritem_acc_code.Equals("0")) { strCriteria = strCriteria + " And (item_acc_code like '%" + stritem_acc_code + "%') "; } if (!stritem_acc_name.Equals("0")) { strCriteria = strCriteria + " And (item_acc_name like '%" + stritem_acc_name + "%')"; } if (!stritem_acc_year.Equals("0")) { strCriteria = strCriteria + " And (item_acc_year = '" + stritem_acc_year + "') "; } if (RadioActive.Checked) { strCriteria = strCriteria + " And (c_active ='Y') "; } else if (RadioCancel.Checked) { strCriteria = strCriteria + " And (c_active ='N') "; } try { if (!oItem_acc.SP_ITEM_ACC_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 { oItem_acc.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }
private bool saveData() { bool blnResult = false; string strMessage = string.Empty; //Head string stritem_acc_doc = string.Empty; string stritem_acc_year = string.Empty; string strpay_month = string.Empty; string strpay_year = string.Empty; string stritem_acc_comment = string.Empty; //Detail string stritem_acc_detail_id = "0"; string stritem_acc_deka; string stritem_acc_group; string stritem_acc_amount; string stritem_acc_tax; string stritem_acc_total; string stritem_acc_code; string stritem_project_code; string stritem_code; string strproduce_code; string strc_user = Session["username"].ToString(); string strScript = string.Empty; bool blnDup = false; cItem_acc oItem_acc = new cItem_acc(); DataSet ds = new DataSet(); try { #region set Data stritem_acc_doc = txtitem_acc_doc.Text; stritem_acc_year = cboYear.SelectedValue; strpay_month = cboPay_Month.SelectedValue; strpay_year = cboPay_Year.SelectedValue; stritem_acc_comment = txtcomments.Text; #endregion if (ViewState["mode"].ToString().ToLower().Equals("add")) { #region insert string strCheckDup = string.Empty; strCheckDup = " and pay_year = '" + strpay_year + "' " + " and pay_month = '" + strpay_month + "'" + " and budget_type = '" + this.BudgetType + "'" + " and c_created_by = '" + UserLoginName + "' "; if (!oItem_acc.SP_ITEM_ACC_HEAD_SEL(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { blnDup = true; strScript = "alert(\"ไม่สามารถเพิ่มข้อมูลได้ เนื่องจาก" + "\\n รอบเดือน : " + cboPay_Month.SelectedItem.Text + " ปี : " + strpay_year + "\\nซ้ำ\");\n"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPage", strScript, true); } else { if (!oItem_acc.SP_ITEM_ACC_HEAD_INS(stritem_acc_year, strpay_month, strpay_year, stritem_acc_comment, strc_user, "B", ref strMessage)) { lblError.Text = strMessage; } else { DataSet dsCHK = new DataSet(); strCheckDup = " and pay_year = '" + strpay_year + "' " + " and pay_month = '" + strpay_month + "' " + " and budget_type = '" + this.BudgetType + "'" + " and c_created_by = '" + UserLoginName + "' "; if (!oItem_acc.SP_ITEM_ACC_HEAD_SEL(strCheckDup, ref dsCHK, ref strMessage)) { lblError.Text = strMessage; } else { stritem_acc_doc = dsCHK.Tables[0].Rows[0]["item_acc_doc"].ToString(); ViewState["item_acc_doc"] = stritem_acc_doc; blnResult = true; } } } } #endregion } else { #region update if (!oItem_acc.SP_ITEM_ACC_HEAD_UPD(stritem_acc_doc, stritem_acc_year, strpay_month, strpay_year, stritem_acc_comment, strc_user, ref strMessage)) { lblError.Text = strMessage; } else { #region insert detail GridViewRow gviewRow; int i; for (i = 0; i <= GridView1.Rows.Count - 1; i++) { gviewRow = GridView1.Rows[i]; Label lblitem_acc_code = (Label)gviewRow.FindControl("lblitem_acc_code"); //if (lblitem_acc_code.Text != "") //{ HiddenField hdditem_acc_detail_id = (HiddenField)gviewRow.FindControl("hdditem_acc_detail_id"); TextBox txtitem_acc_deka = (TextBox)gviewRow.FindControl("txtitem_acc_deka"); TextBox txtitem_acc_group = (TextBox)gviewRow.FindControl("txtitem_acc_group"); TextBox txtitem_project_code = (TextBox)gviewRow.FindControl("txtitem_project_code"); AwNumeric txtitem_acc_amount = (AwNumeric)gviewRow.FindControl("txtitem_acc_amount"); AwNumeric txtitem_acc_tax = (AwNumeric)gviewRow.FindControl("txtitem_acc_tax"); AwNumeric txtitem_acc_total = (AwNumeric)gviewRow.FindControl("txtitem_acc_total"); //Label lblitem_acc_code = (Label)gviewRow.FindControl("txtitem_code"); Label lblitem_code = (Label)gviewRow.FindControl("lblitem_code"); Label lblproduce_code = (Label)gviewRow.FindControl("lblproduce_code"); Label lblperson_group_code_acc = (Label)gviewRow.FindControl("lblperson_group_code_acc"); Label lblpayment_back_type = (Label)gviewRow.FindControl("lblpayment_back_type"); stritem_acc_detail_id = hdditem_acc_detail_id.Value.ToString(); stritem_acc_deka = txtitem_acc_deka.Text.Trim(); stritem_acc_group = txtitem_acc_group.Text.Trim(); stritem_acc_amount = txtitem_acc_amount.Value.ToString(); stritem_acc_tax = txtitem_acc_tax.Value.ToString(); stritem_acc_total = txtitem_acc_total.Value.ToString(); stritem_acc_code = lblitem_acc_code.Text; stritem_project_code = txtitem_project_code.Text.Trim(); strproduce_code = lblproduce_code.Text; stritem_code = lblitem_code.Text; if (stritem_acc_detail_id != "0") { if (!oItem_acc.SP_ITEM_ACC_DETAIL_UPD(stritem_acc_detail_id, txtitem_acc_doc.Text.Trim(), stritem_acc_deka, stritem_acc_group, stritem_acc_amount, stritem_acc_tax, stritem_acc_total, stritem_acc_code, stritem_project_code, stritem_code, strproduce_code, ref strMessage)) { lblError.Text = strMessage; } } else { if (!oItem_acc.SP_ITEM_ACC_DETAIL_INS(txtitem_acc_doc.Text.Trim(), stritem_acc_deka, stritem_acc_group, stritem_acc_amount, stritem_acc_tax, stritem_acc_total, stritem_acc_code, stritem_project_code, stritem_code, strproduce_code, lblperson_group_code_acc.Text.Trim(), lblpayment_back_type.Text, ref strMessage)) { lblError.Text = strMessage; } } //} } #endregion blnResult = true; } #endregion } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oItem_acc.Dispose(); } return(blnResult); }
private bool saveData() { bool blnResult = false; bool blnDup = false; string strMessage = string.Empty; string stritem_acc_code = string.Empty, stritem_acc_year = string.Empty, stritem_acc_name = string.Empty, strActive = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty; string strScript = string.Empty; cItem_acc oItem_acc = new cItem_acc(); DataSet ds = new DataSet(); try { #region set Data stritem_acc_code = txtitem_acc_code.Text.Trim(); stritem_acc_name = txtitem_acc_name.Text; stritem_acc_year = cboYear.SelectedItem.Value; if (chkStatus.Checked == true) { strActive = "Y"; } else { strActive = "N"; } strCreatedBy = Session["username"].ToString(); strUpdatedBy = Session["username"].ToString(); #endregion if (ViewState["mode"].ToString().ToLower().Equals("edit")) { #region edit if (!blnDup) { if (oItem_acc.SP_ITEM_ACC_UPD(hdditem_acc_id.Value.ToString(), stritem_acc_code, stritem_acc_year, stritem_acc_name, strActive, strUpdatedBy, ref strMessage)) { blnResult = true; } else { lblError.Text = strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true); } #endregion } else { #region check dup string strCheckDup = string.Empty; strCheckDup = " and item_acc_name = '" + stritem_acc_name.Trim() + "' and item_acc_year = '" + stritem_acc_year + "' "; if (!oItem_acc.SP_ITEM_ACC_SEL(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + stritem_acc_name.Trim() + " ปี " + stritem_acc_year.Trim() + " ซ้ำ\");\n"; blnDup = true; } } #endregion #region insert if (!blnDup) { if (oItem_acc.SP_ITEM_ACC_INS(stritem_acc_year, stritem_acc_code, stritem_acc_name, strActive, strCreatedBy, ref strMessage)) { string strGetcode = " and item_acc_name = '" + stritem_acc_name.Trim() + "' and item_acc_year = '" + stritem_acc_year + "' "; if (!oItem_acc.SP_ITEM_ACC_SEL(strGetcode, ref ds, ref strMessage)) { lblError.Text = strMessage; } if (ds.Tables[0].Rows.Count > 0) { stritem_acc_code = ds.Tables[0].Rows[0]["item_acc_id"].ToString(); } ViewState["item_acc_id"] = stritem_acc_code; blnResult = true; } else { lblError.Text = strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true); } #endregion } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oItem_acc.Dispose(); } return(blnResult); }