private void InitcboMajor() { cMajor oMajor = new cMajor(); string strMessage = string.Empty, strCriteria = string.Empty; string strYear = cboYear.SelectedValue; string strmajor_code = cboMajor.SelectedValue; DataSet ds = new DataSet(); DataTable dt = new DataTable(); strCriteria = " and major_year = '" + strYear + "' and c_active='Y' "; if (MajorLock == "Y") { strCriteria += " and major_code = '" + PersonMajorCode + "' "; } if (oMajor.SP_SEL_Major(strCriteria, ref ds, ref strMessage)) { dt = ds.Tables[0]; cboMajor.Items.Clear(); cboMajor.Items.Add(new ListItem("---- เลือกข้อมูลทั้งหมด ----", "")); int i; for (i = 0; i <= dt.Rows.Count - 1; i++) { cboMajor.Items.Add(new ListItem(dt.Rows[i]["major_name"].ToString(), dt.Rows[i]["major_code"].ToString())); } if (cboMajor.Items.FindByValue(strmajor_code) != null) { cboMajor.SelectedIndex = -1; cboMajor.Items.FindByValue(strmajor_code).Selected = true; } } }
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 lblmajor_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblmajor_code"); cMajor oMajor = new cMajor(); try { if (!oMajor.SP_DEL_Major(lblmajor_code.Text)) { lblError.Text = strMessage; } } catch (Exception ex) { if (ex.Message.Contains("REFERENCE constraint")) { MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว"); } else { lblError.Text = ex.Message.ToString(); } } finally { oMajor.Dispose(); } BindGridView(0); }
private void BindGridItem() { cMajor oMajor = new cMajor(); string strMessage = string.Empty, strCriteria = string.Empty; DataSet ds = new DataSet(); DataTable dt = new DataTable(); var strYear = string.Empty; if (this.BudgetType == "B") { strYear = ((DataSet)Application["xmlconfig"]).Tables["default"].Rows[0]["yearnow"].ToString(); } else { strYear = ((DataSet)Application["xmlconfig"]).Tables["default"].Rows[0]["yearnow2"].ToString(); } try { strCriteria = " AND c_active = 'Y' AND major_year = '" + strYear + "' AND major_code not in (Select major_code From Budget_money_major where budget_money_detail_id = '" + ViewState["budget_money_detail_id"].ToString() + "') order by major_order"; if (oMajor.SP_SEL_Major(strCriteria, ref ds, ref strMessage)) { dt = ds.Tables[0]; GridView1.DataSource = dt; GridView1.DataBind(); } } catch (Exception ex) { lblError.Text = ex.Message; } finally { if (GridView1.Rows.Count == 0) { EmptyGridFix(GridView1); } oMajor.Dispose(); ds.Dispose(); } }
private void BindGridItem() { cMajor oMajor = new cMajor(); string strMessage = string.Empty, strCriteria = string.Empty; DataSet ds = new DataSet(); DataTable dt = new DataTable(); try { strCriteria = " AND major_code not in (Select major_code From Budget_money_major where budget_money_detail_id = '" + ViewState["budget_money_detail_id"].ToString() + "') "; if (MajorLock == "Y") { strCriteria += " and major_code = '" + PersonMajorCode + "' "; } if (oMajor.SP_SEL_Major(strCriteria, ref ds, ref strMessage)) { dt = ds.Tables[0]; GridView1.DataSource = dt; GridView1.DataBind(); } } catch (Exception ex) { lblError.Text = ex.Message; } finally { if (GridView1.Rows.Count == 0) { EmptyGridFix(GridView1); } oMajor.Dispose(); ds.Dispose(); } }
private void BindGridView(int nPageNo) { cMajor oMajor = new cMajor(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strmajor_code = string.Empty; string strmajor_name = string.Empty; string strActive = string.Empty; string strmajor_year = string.Empty; strmajor_code = txtmajor_code.Text.Replace("'", "''").Trim(); strmajor_name = txtmajor_name.Text.Replace("'", "''").Trim(); strmajor_year = cboYear.SelectedValue; if (!strmajor_code.Equals("0")) { strCriteria = strCriteria + " And (major_code like '%" + strmajor_code + "%') "; } if (!strmajor_name.Equals("0")) { strCriteria = strCriteria + " And (major_name like '%" + strmajor_name + "%')"; } if (!strmajor_year.Equals("0")) { strCriteria = strCriteria + " And (major_year = '" + strmajor_year + "') "; } if (RadioActive.Checked) { strCriteria = strCriteria + " And (c_active ='Y') "; } else if (RadioCancel.Checked) { strCriteria = strCriteria + " And (c_active ='N') "; } try { if (!oMajor.SP_SEL_Major(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 { oMajor.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }
private void setData() { cMajor oMajor = new cMajor(); DataSet ds = new DataSet(); string strMessage = string.Empty, strCriteria = string.Empty; string strmajor_code = string.Empty, strmajor_name = string.Empty, strmajor_abbrev = string.Empty, strmajor_order = string.Empty, strYear = string.Empty, strC_active = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty, strCreatedDate = string.Empty, strUpdatedDate = string.Empty; try { strCriteria = " and major_code = '" + ViewState["major_code"].ToString() + "' "; if (!oMajor.SP_SEL_Major(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { #region get Data strmajor_code = ds.Tables[0].Rows[0]["major_code"].ToString(); strmajor_name = ds.Tables[0].Rows[0]["major_name"].ToString(); strmajor_abbrev = ds.Tables[0].Rows[0]["major_abbrev"].ToString(); strmajor_order = ds.Tables[0].Rows[0]["major_order"].ToString(); strYear = ds.Tables[0].Rows[0]["major_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 txtmajor_code.Text = strmajor_code; txtmajor_name.Text = strmajor_name; txtmajor_abbrev.Text = strmajor_abbrev; txtmajor_order.Value = strmajor_order; InitcboYear(); if (cboYear.Items.FindByValue(strYear) != null) { cboYear.SelectedIndex = -1; cboYear.Items.FindByValue(strYear).Selected = true; } if (strC_active.Equals("Y")) { txtmajor_name.ReadOnly = false; txtmajor_name.CssClass = "textbox"; chkStatus.Checked = true; } else { txtmajor_name.ReadOnly = true; txtmajor_name.CssClass = "textboxdis"; chkStatus.Checked = false; } cboYear.Enabled = false; cboYear.CssClass = "textboxdis"; txtUpdatedBy.Text = strUpdatedBy; txtUpdatedDate.Text = strUpdatedDate; #endregion } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } }
private bool saveData() { bool blnResult = false; bool blnDup = false; string strMessage = string.Empty; string strmajor_code = string.Empty, strmajor_year = string.Empty, strmajor_name = string.Empty, strmajor_abbrev = string.Empty, strmajor_order = string.Empty, strActive = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty; string strScript = string.Empty; cMajor oMajor = new cMajor(); DataSet ds = new DataSet(); try { #region set Data strmajor_code = txtmajor_code.Text.Trim(); strmajor_name = txtmajor_name.Text; strmajor_year = cboYear.SelectedItem.Value; strmajor_abbrev = txtmajor_abbrev.Text; strmajor_order = txtmajor_order.Value.ToString(); 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 (oMajor.SP_UPD_Major(strmajor_code, strmajor_year, strmajor_name, strmajor_abbrev, strmajor_order, 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 major_name = '" + strmajor_name.Trim() + "' and major_year = '" + strmajor_year + "' "; if (!oMajor.SP_SEL_Major(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strmajor_name.Trim() + " ปี " + strmajor_year.Trim() + " ซ้ำ\");\n"; blnDup = true; } } #endregion #region insert if (!blnDup) { if (oMajor.SP_INS_Major(strmajor_year, strmajor_name, strmajor_abbrev, strmajor_order, strActive, strCreatedBy, ref strMessage)) { string strGetcode = " and major_name = '" + strmajor_name.Trim() + "' and major_year = '" + strmajor_year + "' "; if (!oMajor.SP_SEL_Major(strGetcode, ref ds, ref strMessage)) { lblError.Text = strMessage; } if (ds.Tables[0].Rows.Count > 0) { strmajor_code = ds.Tables[0].Rows[0]["major_code"].ToString(); } ViewState["major_code"] = strmajor_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 { oMajor.Dispose(); } return(blnResult); }