private void InitcboUser_group() { cUser_group oUser_group = new cUser_group(); string strMessage = string.Empty, strCriteria = string.Empty, struser_group_code = string.Empty; struser_group_code = cbouser_group.SelectedValue; int i; DataSet ds = new DataSet(); DataTable dt = new DataTable(); strCriteria = " and c_active='Y' "; if (oUser_group.sp_USER_GROUP_SEL(strCriteria, ref ds, ref strMessage)) { dt = ds.Tables[0]; cbouser_group.Items.Clear(); cbouser_group.Items.Add(new ListItem("---- เลือกข้อมูลทั้งหมด ----", "")); for (i = 0; i <= dt.Rows.Count - 1; i++) { cbouser_group.Items.Add(new ListItem(dt.Rows[i]["user_group_name"].ToString(), dt.Rows[i]["user_group_code"].ToString())); } if (cbouser_group.Items.FindByValue(struser_group_code) != null) { cbouser_group.SelectedIndex = -1; cbouser_group.Items.FindByValue(struser_group_code).Selected = true; } } }
private void setData() { cUser_group oUser_group = new cUser_group(); DataSet ds = new DataSet(); string strMessage = string.Empty, strCriteria = string.Empty; string struser_group_code = string.Empty, struser_group_name = string.Empty, strC_active = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty, strCreatedDate = string.Empty, strUpdatedDate = string.Empty; try { strCriteria = " and user_group_code = '" + ViewState["user_group_code"].ToString() + "' "; if (!oUser_group.SP_USER_GROUP_SEL(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { #region get Data struser_group_code = ds.Tables[0].Rows[0]["user_group_code"].ToString(); struser_group_name = ds.Tables[0].Rows[0]["user_group_name"].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 txtuser_group_code.Text = struser_group_code; txtuser_group_name.Text = struser_group_name; if (strC_active.Equals("Y")) { txtuser_group_name.ReadOnly = false; txtuser_group_name.CssClass = "textbox"; chkStatus.Checked = true; } else { txtuser_group_name.ReadOnly = true; txtuser_group_name.CssClass = "textboxdis"; chkStatus.Checked = false; } txtUpdatedBy.Text = strUpdatedBy; txtUpdatedDate.Text = strUpdatedDate; #endregion } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } }
private void GotoUserMode(string user_group_code) { cUser_group objUserGroup = new cUser_group(); DataTable dt = new DataTable(); DataSet ds = new DataSet(); string strCriteria = " and user_group_code = '" + user_group_code + "' "; string strMessage = string.Empty; objUserGroup.SP_USER_GROUP_SEL(strCriteria, ref ds, ref strMessage); dt = ds.Tables[0]; if (dt.Rows.Count > 0) { this.IsLogin = "******"; this.DirectorLock = Helper.CStr(dt.Rows[0]["director_lock"]); this.MajorLock = Helper.CStr(dt.Rows[0]["unit_lock"]); string[] strperson_group_list = Helper.CStr(dt.Rows[0]["person_group_list"]).Split(','); for (int i = 0; i <= (strperson_group_list.GetUpperBound(0)); i++) { PersonGroupList = PersonGroupList + "'" + strperson_group_list[i] + "',"; } PersonGroupList = PersonGroupList.Substring(0, PersonGroupList.Length - 1); cPerson objPerson = new cPerson(); strCriteria = " And person_id='" + base.PersonId + "' "; objPerson.SP_PERSON_LIST_SEL(strCriteria, ref ds, ref strMessage); dt = ds.Tables[0]; if (dt.Rows.Count > 0) { this.UserLoginName = Helper.CStr(dt.Rows[0]["person_thai_name"]) + " " + Helper.CStr(dt.Rows[0]["person_thai_surname"]); this.PersonMajorCode = Helper.CStr(dt.Rows[0]["major_code"]); this.PersonMajorName = Helper.CStr(dt.Rows[0]["major_name"]); this.PersonMajorAbbrev = Helper.CStr(dt.Rows[0]["major_abbrev"]); this.DirectorCode = Helper.CStr(dt.Rows[0]["director_code"]); this.DirectorName = Helper.CStr(dt.Rows[0]["director_name"]); Session["username"] = Helper.CStr(dt.Rows[0]["person_thai_name"]) + " " + Helper.CStr(dt.Rows[0]["person_thai_surname"]); } Response.Redirect("Menu_control.aspx"); } }
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 lbluser_group_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lbluser_group_code"); cUser_group oUser_group = new cUser_group(); try { if (!oUser_group.SP_USER_GROUP_DEL(lbluser_group_code.Text, "N", strUpdatedBy, ref strMessage)) { if (strMessage.Contains("REFERENCE constraint")) { MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว"); } else { lblError.Text = strMessage; } } } catch (Exception ex) { if (ex.Message.Contains("REFERENCE constraint")) { MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว"); } else { lblError.Text = ex.Message.ToString(); } } finally { oUser_group.Dispose(); } BindGridView(0); }
protected void imgSaveOnly_Click(object sender, ImageClickEventArgs e) { string strMessage = string.Empty; string strScript = string.Empty; cUser_group oUser_group = new cUser_group(); DataSet ds = new DataSet(); try { string strCheck = string.Empty; strCheck = " and [user_group_code] = '" + cboUserGroup.SelectedValue + "' "; if (!oUser_group.SP_USER_GROUP_SEL(strCheck, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count == 0) { strScript = "alert('ไม่สามารถบันข้อมูลได้ เนื่องจาก" + "\\nไม่พบข้อมูล User Group : " + cboUserGroup.SelectedItem.Text + "');"; MsgBox(strScript); return; } } string struser_group_code = ds.Tables[0].Rows[0]["user_group_code"].ToString(); saveData(struser_group_code); } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oUser_group.Dispose(); ds.Dispose(); } }
private void BindGridView(int nPageNo) { cUser_group oUser_group = new cUser_group(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string struser_group_code = string.Empty; string struser_group_name = string.Empty; string strActive = string.Empty; struser_group_code = txtuser_group_code.Text.Replace("'", "''").Trim(); struser_group_name = txtuser_group_name.Text.Replace("'", "''").Trim(); if (!struser_group_code.Equals("0")) { strCriteria = strCriteria + " And (user_group_code like '%" + struser_group_code + "%') "; } if (!struser_group_name.Equals("0")) { strCriteria = strCriteria + " And (user_group_name like '%" + struser_group_name + "%')"; } if (RadioActive.Checked) { strCriteria = strCriteria + " And (c_active ='Y') "; } else if (RadioCancel.Checked) { strCriteria = strCriteria + " And (c_active ='N') "; } try { if (!oUser_group.SP_USER_GROUP_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 { oUser_group.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }
private void GotoUserMode(string user_group_code) { //if (user_group_code == "001") //{ // if (SetPersonUserProfile(txtUser.Text, ref _strMessage)) // { // Response.Redirect("Menu_control.aspx"); // } //} //else //{ cUser_group objUserGroup = new cUser_group(); DataTable dt = new DataTable(); DataSet ds = new DataSet(); string strCriteria = " and user_group_code = '" + user_group_code + "' "; string strMessage = string.Empty; objUserGroup.sp_USER_GROUP_SEL(strCriteria, ref ds, ref strMessage); dt = ds.Tables[0]; if (dt.Rows.Count > 0) { this.IsLogin = "******"; this.DirectorLock = Helper.CStr(dt.Rows[0]["director_lock"]); try { this.UnitLock = Helper.CStr(dt.Rows[0]["unit_lock"]); } catch { this.UnitLock = "N"; } if (this.UnitLock == "Y") { this.UnitCodeList = string.Empty; string[] strunit_code_list = Helper.CStr(dt.Rows[0]["unit_code_list"]).Split(','); for (int i = 0; i <= (strunit_code_list.GetUpperBound(0)); i++) { this.UnitCodeList += "'" + strunit_code_list[i].Substring(3, 5) + "',"; } this.UnitCodeList = this.UnitCodeList.Substring(0, this.UnitCodeList.Length - 1); } string[] strperson_group_list = Helper.CStr(dt.Rows[0]["person_group_list"]).Split(','); for (int i = 0; i <= (strperson_group_list.GetUpperBound(0)); i++) { PersonGroupList = PersonGroupList + "'" + strperson_group_list[i] + "',"; } PersonGroupList = PersonGroupList.Substring(0, PersonGroupList.Length - 1); cPerson objPerson = new cPerson(); strCriteria = " And person_code='" + this.PersonCode + "' "; objPerson.SP_PERSON_LIST_SEL(strCriteria, ref ds, ref strMessage); dt = ds.Tables[0]; if (dt.Rows.Count > 0) { this.UserLoginName = Helper.CStr(dt.Rows[0]["person_thai_name"]) + " " + Helper.CStr(dt.Rows[0]["person_thai_surname"]); this.DirectorCode = Helper.CStr(dt.Rows[0]["director_code"]); this.DirectorName = Helper.CStr(dt.Rows[0]["director_name"]); Session["username"] = Helper.CStr(dt.Rows[0]["person_thai_name"]) + " " + Helper.CStr(dt.Rows[0]["person_thai_surname"]); } Response.Redirect("Menu_control.aspx"); } // } }
private bool saveData() { bool blnResult = false; bool blnDup = false; string strMessage = string.Empty; string struser_group_code = string.Empty, struser_group_name = string.Empty, strActive = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty; string strScript = string.Empty; cUser_group oUser_group = new cUser_group(); DataSet ds = new DataSet(); try { #region set Data struser_group_code = txtuser_group_code.Text.Trim(); struser_group_name = txtuser_group_name.Text; 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 (oUser_group.SP_USER_GROUP_UPD(struser_group_code, struser_group_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 user_group_code = '" + struser_group_code.Trim() + "' "; if (!oUser_group.SP_USER_GROUP_SEL(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + struser_group_code.Trim() + " : " + struser_group_name.Trim() + " ซ้ำ\");\n"; blnDup = true; } } #endregion #region insert if (!blnDup) { if (oUser_group.SP_USER_GROUP_INS(struser_group_code, struser_group_name, strActive, strCreatedBy, ref strMessage)) { ViewState["user_group_code"] = struser_group_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 { oUser_group.Dispose(); } return(blnResult); }
private void BindGridView() { cUser_group_menu objUserMenu = new cUser_group_menu(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string struser_group_code = cboUserGroup.SelectedValue; try { strCriteria = " and user_group_code='" + struser_group_code + "' "; strCriteria += " And Menu_Status='Y' "; objUserMenu.SP_USER_GROUP_MENU_MANAGE_SEL(strCriteria, ref ds, ref strMessage); GridView1.DataSource = ds; GridView1.DataBind(); cUser_group oUser_group = new cUser_group(); string strCheck = string.Empty; strCheck = " and [user_group_code] = '" + struser_group_code + "' "; if (!oUser_group.SP_USER_GROUP_SEL(strCheck, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count == 0) { string strScript = "alert('ไม่สามารถบันข้อมูลได้ เนื่องจาก" + "\\nไม่พบข้อมูล User Group : " + cboUserGroup.SelectedItem.Text + "');"; MsgBox(strScript); return; } else { //this.myDirectorCode = ds.Tables[0].Rows[0]["director_code"].ToString(); this.myUnitCodeList = ds.Tables[0].Rows[0]["unit_code_list"].ToString(); hddperson_group_list.Value = ds.Tables[0].Rows[0]["person_group_list"].ToString(); if (ds.Tables[0].Rows[0]["director_lock"].ToString().Equals("Y")) { chkdirector_lock.Checked = true; } else { chkdirector_lock.Checked = false; } if (ds.Tables[0].Rows[0]["unit_lock"].ToString().Equals("Y")) { chkunit_lock.Checked = true; } else { chkunit_lock.Checked = false; } } } if (GridView1.Rows.Count > 0) { TabContainer1.Visible = true; TabContainer1.ActiveTabIndex = 0; imgSaveOnly.Visible = true; chkdirector_lock.Visible = true; chkunit_lock.Visible = true; } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { objUserMenu.Dispose(); ds.Dispose(); } }
private bool saveData(string struser_group_code) { bool blnResult = false; string strMessage = string.Empty; string strActive = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty; string strScript = string.Empty; int i; cUser_group_menu oUser_group_menu = new cUser_group_menu(); cUser_group oUser_group = new cUser_group(); DataSet ds = new DataSet(); try { string strCanView; string strCanInsert; string strCanEdit; string strCanDelete; string strCanApprove; string strCanExtra; oUser_group_menu.SP_USER_GROUP_MENU_DEL(struser_group_code, ref strMessage); for (i = 0; i <= (GridView1.Rows.Count - 1); i++) { GridViewRow row = GridView1.Rows[i]; HiddenField hddMenuID = (HiddenField)row.FindControl("hddMenuID"); CheckBox chkCanView = (CheckBox)row.FindControl("chkCanView"); CheckBox chkCanInsert = (CheckBox)row.FindControl("chkCanInsert"); CheckBox chkCanEdit = (CheckBox)row.FindControl("chkCanEdit"); CheckBox chkCanDelete = (CheckBox)row.FindControl("chkCanDelete"); CheckBox chkCanApprove = (CheckBox)row.FindControl("chkCanApprove"); CheckBox chkCanExtra = (CheckBox)row.FindControl("chkCanExtra"); string intMenuId = hddMenuID.Value; strCanView = chkCanView.Checked == true ? "Y" : "N"; strCanInsert = chkCanInsert.Checked == true ? "Y" : "N"; strCanEdit = chkCanEdit.Checked == true ? "Y" : "N"; strCanDelete = chkCanDelete.Checked == true ? "Y" : "N"; strCanApprove = chkCanApprove.Checked == true ? "Y" : "N"; strCanExtra = chkCanExtra.Checked == true ? "Y" : "N"; oUser_group_menu.SP_USER_GROUP_MENU_INS(struser_group_code, intMenuId, strCanView, strCanInsert, strCanEdit, strCanDelete, strCanApprove, strCanExtra, UserLoginName, ref strMessage); } string strperson_group_list = string.Empty; for (i = 0; i <= (GridView2.Rows.Count - 1); i++) { GridViewRow row = GridView2.Rows[i]; CheckBox chkPersonGroup = (CheckBox)row.FindControl("chkPersonGroup"); if (chkPersonGroup.Checked) { Label lblperson_group_code = (Label)row.FindControl("lblperson_group_code"); strperson_group_list += lblperson_group_code.Text + ","; } } if (strperson_group_list.Length > 0) { strperson_group_list = strperson_group_list.Substring(0, strperson_group_list.Length - 1); } string strdirector_lock = "N"; if (chkdirector_lock.Checked) { strdirector_lock = "Y"; } string strunit_lock = "N"; if (chkunit_lock.Checked) { strunit_lock = "Y"; } oUser_group.SP_USER_GROUP_PERSON_GROUP_UPD(struser_group_code, strperson_group_list, strdirector_lock, strunit_lock, UserLoginName, ref strMessage); blnResult = true; MsgBox("บันทึกข้อมูลสมบูรณ์"); } catch (Exception ex) { blnResult = false; lblError.Text = ex.Message.ToString(); } finally { oUser_group_menu.Dispose(); } return(blnResult); }