private void InitcboProduce() { cProduce oProduce = new cProduce(); string strMessage = string.Empty, strCriteria = string.Empty, strbudget_code = string.Empty, strproduce_code = string.Empty, strproduce_name = string.Empty; strbudget_code = cboBudget.SelectedValue; strproduce_code = cboProduce.SelectedValue;; int i; DataSet ds = new DataSet(); DataTable dt = new DataTable(); strCriteria = " and produce.budget_code= '" + strbudget_code + "' and produce.c_active='Y' "; strCriteria = strCriteria + " And produce.budget_type ='" + this.BudgetType + "' "; if (oProduce.SP_SEL_PRODUCE(strCriteria, ref ds, ref strMessage)) { dt = ds.Tables[0]; cboProduce.Items.Clear(); cboProduce.Items.Add(new ListItem("---- เลือกข้อมูลทั้งหมด ----", "")); for (i = 0; i <= dt.Rows.Count - 1; i++) { cboProduce.Items.Add(new ListItem(dt.Rows[i]["produce_name"].ToString(), dt.Rows[i]["produce_code"].ToString())); } if (cboProduce.Items.FindByValue(strproduce_code) != null) { cboProduce.SelectedIndex = -1; cboProduce.Items.FindByValue(strproduce_code).Selected = true; } } }
private void BindGridView() { cProduce oproduce = new cProduce(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strbudget_code = string.Empty; strbudget_code = cboBudget.SelectedValue; strCriteria = strCriteria + " And (produce.budget_code = '" + strbudget_code + "') "; try { if (!oproduce.SP_SEL_PRODUCE(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { try { ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } catch { GridView1.PageIndex = 0; 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 { //if (this.BudgetType == "R") //{ // foreach (Control c in GridView1.Controls) // { // base.SetLabel(c, old_str, new_str); // base.SetLabel(c, "แผนงบประมาณ", "แผนงาน"); // } //} oproduce.Dispose(); ds.Dispose(); } }
private void setData() { cProduce oproduce = new cProduce(); DataSet ds = new DataSet(); string strMessage = string.Empty, strCriteria = string.Empty; string strproduce_code = string.Empty, strproduce_name = string.Empty, strbudget_code = string.Empty, strbudget_name = string.Empty, strYear = string.Empty, strC_active = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty, strCreatedDate = string.Empty, strUpdatedDate = string.Empty; try { strCriteria = " and produce_code = '" + ViewState["produce_code"].ToString() + "' "; if (!oproduce.SP_SEL_PRODUCE(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { #region get Data strproduce_code = ds.Tables[0].Rows[0]["produce_code"].ToString(); strproduce_name = ds.Tables[0].Rows[0]["produce_name"].ToString(); strbudget_code = ds.Tables[0].Rows[0]["budget_code"].ToString(); strbudget_name = ds.Tables[0].Rows[0]["budget_name"].ToString(); strYear = ds.Tables[0].Rows[0]["produce_year"].ToString(); strC_active = ds.Tables[0].Rows[0]["c_active"].ToString(); strCreatedBy = ds.Tables[0].Rows[0]["c_created_by"].ToString(); strUpdatedBy = ds.Tables[0].Rows[0]["c_updated_by"].ToString(); strCreatedDate = ds.Tables[0].Rows[0]["d_created_date"].ToString(); strUpdatedDate = ds.Tables[0].Rows[0]["d_updated_date"].ToString(); #endregion #region set Control txtproduce_code.Text = strproduce_code; txtproduce_name.Text = strproduce_name; txtbudget_code.Text = strbudget_code; txtbudget_name.Text = strbudget_name; txtyear.Text = strYear; if (strC_active.Equals("Y")) { chkStatus.Checked = true; } else { chkStatus.Checked = false; } txtUpdatedBy.Text = strUpdatedBy; txtUpdatedDate.Text = strUpdatedDate; #endregion } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } }
private void setData() { cProduce oProduce = new cProduce(); DataSet ds = new DataSet(); string strMessage = string.Empty, strCriteria = string.Empty; string strproduce_code = string.Empty, strproduce_name = string.Empty, strbudget_code = string.Empty, strbudget_name = string.Empty, strYear = string.Empty, strC_active = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty, strCreatedDate = string.Empty, strUpdatedDate = string.Empty; try { strCriteria = " and produce_code = '" + ViewState["produce_code"].ToString() + "' "; if (!oProduce.SP_SEL_PRODUCE(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { #region get Data strproduce_code = ds.Tables[0].Rows[0]["produce_code"].ToString(); strproduce_name = ds.Tables[0].Rows[0]["produce_name"].ToString(); strbudget_code = ds.Tables[0].Rows[0]["budget_code"].ToString(); strbudget_name = ds.Tables[0].Rows[0]["budget_name"].ToString(); strYear = ds.Tables[0].Rows[0]["produce_year"].ToString(); strC_active = ds.Tables[0].Rows[0]["c_active"].ToString(); strCreatedBy = ds.Tables[0].Rows[0]["c_created_by"].ToString(); strUpdatedBy = ds.Tables[0].Rows[0]["c_updated_by"].ToString(); strCreatedDate = ds.Tables[0].Rows[0]["d_created_date"].ToString(); strUpdatedDate = ds.Tables[0].Rows[0]["d_updated_date"].ToString(); #endregion #region set Control txtproduce_code.Text = strproduce_code; txtproduce_name.Text = strproduce_name; InitcboYear(); if (cboYear.Items.FindByValue(strYear) != null) { cboYear.SelectedIndex = -1; cboYear.Items.FindByValue(strYear).Selected = true; } InitcboBudget(); if (cboBudget.Items.FindByValue(strbudget_code) != null) { cboBudget.SelectedIndex = -1; cboBudget.Items.FindByValue(strbudget_code).Selected = true; } if (strC_active.Equals("Y")) { txtproduce_name.ReadOnly = false; txtproduce_name.CssClass = "textbox"; chkStatus.Checked = true; } else { txtproduce_name.ReadOnly = true; txtproduce_name.CssClass = "textboxdis"; chkStatus.Checked = false; } cboBudget.Enabled = false; cboBudget.CssClass = "textboxdis"; cboYear.Enabled = false; cboYear.CssClass = "textboxdis"; txtUpdatedBy.Text = strUpdatedBy; txtUpdatedDate.Text = strUpdatedDate; BindGridView(); #endregion } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } }
private bool saveData() { // InitcboYear(); // InitcboBudget(); bool blnResult = false; bool blnDup = false; string strMessage = string.Empty; string strproduce_code = string.Empty, strproduce_year = string.Empty, strproduce_name = string.Empty, strbudget_code = string.Empty, strActive = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty; string strScript = string.Empty; cProduce oProduce = new cProduce(); DataSet ds = new DataSet(); try { #region set Data strproduce_code = txtproduce_code.Text; strproduce_name = txtproduce_name.Text; //produce_year strproduce_year = cboYear.SelectedValue; //budget_code strbudget_code = cboBudget.SelectedValue; if (Request.Form["ctl00$ASPxRoundPanel1$ContentPlaceHolder1$cboBudget"] != null) { strbudget_code = Request.Form["ctl00$ASPxRoundPanel1$ContentPlaceHolder1$cboBudget"].ToString(); } if (chkStatus.Checked == true) { strActive = "Y"; } else { strActive = "N"; } strCreatedBy = Session["username"].ToString(); strUpdatedBy = Session["username"].ToString(); #endregion string strCheckAdd = " and produce.produce_code = '" + strproduce_code.Trim() + "' "; if (!oProduce.SP_SEL_PRODUCE(strCheckAdd, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { #region check dup string strCheckDup = string.Empty; strCheckDup = " and produce.produce_name = '" + strproduce_name.Trim() + "' and produce.produce_year = '" + strproduce_year.Trim() + "' " + " and produce.budget_code='" + strbudget_code.Trim() + "' and produce.produce_code <> '" + strproduce_code.Trim() + "' "; if (!oProduce.SP_SEL_PRODUCE(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก" + "\\nข้อมูล : " + strproduce_name.Trim() + "\\nข้อมูล : " + cboBudget.SelectedItem.Text + "\\n ปี : " + strproduce_year.Trim() + "\\nซ้ำ\");\n"; blnDup = true; } } #endregion #region edit if (!blnDup) { if (oProduce.SP_UPD_PRODUCE(strproduce_code, strproduce_year, strproduce_name, strbudget_code, strActive, strUpdatedBy, this.BudgetType, ref strMessage)) { blnResult = true; } else { lblError.Text = strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "chkdup", strScript, true); } #endregion } else { #region check dup string strCheckDup = string.Empty; strCheckDup = " and produce.produce_name = '" + strproduce_name.Trim() + "' and produce.produce_year = '" + strproduce_year + "' " + " and produce.budget_code='" + strbudget_code.Trim() + "' "; if (!oProduce.SP_SEL_PRODUCE(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถเพิ่มข้อมูลได้ เนื่องจาก" + "\\nข้อมูล : " + strproduce_name.Trim() + "\\nข้อมูล : " + cboBudget.SelectedItem.Text + "\\n ปี : " + strproduce_year.Trim() + "\\nซ้ำ\");\n"; blnDup = true; } } #endregion #region insert if (!blnDup) { if (oProduce.SP_INS_PRODUCE(strproduce_year, strproduce_name, strbudget_code, strActive, strCreatedBy, this.BudgetType, ref strMessage)) { string strGetcode = " and produce_name = '" + strproduce_name.Trim() + "' and produce_year = '" + strproduce_year + "' " + " and produce.budget_code='" + strbudget_code.Trim() + "' "; if (!oProduce.SP_SEL_PRODUCE(strGetcode, ref ds, ref strMessage)) { lblError.Text = strMessage; } if (ds.Tables[0].Rows.Count > 0) { strproduce_code = ds.Tables[0].Rows[0]["produce_code"].ToString(); } ViewState["produce_code"] = strproduce_code; blnResult = true; } else { lblError.Text = strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "close", strScript, true); } #endregion } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oProduce.Dispose(); } return(blnResult); }
private void BindGridView(int nPageNo) { InitcboYear(); InitcboBudget(); cProduce oproduce = new cProduce(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strproduce_code = string.Empty; string strproduce_name = string.Empty; string strbudget_code = string.Empty; string strActive = string.Empty; string strproduce_year = string.Empty; strproduce_code = txtproduce_code.Text.Replace("'", "''").Trim(); strproduce_name = txtproduce_name.Text.Replace("'", "''").Trim(); strproduce_year = cboYear.SelectedValue; if (cboBudget.SelectedValue != "") { strbudget_code = cboBudget.SelectedValue; } else { strbudget_code = ""; } if (!strproduce_code.Equals("")) { strCriteria = strCriteria + " And (produce.produce_code like '%" + strproduce_code + "%') "; } if (!strproduce_name.Equals("")) { strCriteria = strCriteria + " And (produce.produce_name like '%" + strproduce_name + "%')"; } if (!strproduce_year.Equals("")) { strCriteria = strCriteria + " And (produce.produce_year = '" + strproduce_year + "') "; } if (!strbudget_code.Equals("")) { strCriteria = strCriteria + " And (produce.budget_code = '" + strbudget_code + "') "; } if (RadioActive.Checked) { strCriteria = strCriteria + " And (produce.c_active ='Y') "; } else if (RadioCancel.Checked) { strCriteria = strCriteria + " And (produce.c_active ='N') "; } strCriteria = strCriteria + " And produce.budget_type ='" + this.BudgetType + "' "; try { if (!oproduce.SP_SEL_PRODUCE(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 { oproduce.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } //if (this.BudgetType == "R") //{ // foreach (Control c in GridView1.Controls) // { // base.SetLabel(c, old_str, new_str); // base.SetLabel(c, "แผนงบประมาณ ", "แผนงาน(เงินรายได้)"); // } //} } }