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 lblperson_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblperson_code"); HiddenField hdduserID = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdduserID"); cUser oUser = new cUser(); try { if (!oUser.SP_USER_DEL(hdduserID.Value.ToString(), ref strMessage)) { lblError.Text = strMessage; } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oUser.Dispose(); } BindGridView(0); }
private bool saveData() { bool blnResult = false; string strUpdatedBy = string.Empty; string struser_group_list = string.Empty; strUpdatedBy = Session["username"].ToString(); CheckBox chkSelect; HiddenField hddg_code; foreach (GridViewRow gvRow in GridView1.Rows) { chkSelect = (CheckBox)gvRow.FindControl("chkSelect"); hddg_code = (HiddenField)gvRow.FindControl("hddg_code"); if (chkSelect.Checked) { struser_group_list += hddg_code.Value + ","; } } if (struser_group_list.Length > 0) { struser_group_list = struser_group_list.Substring(0, struser_group_list.Length - 1); } var objUser = new cUser(); try { #region update if (objUser.SP_PERSON_USER_GROUP_UPD(hddperson_code.Value, struser_group_list, strUpdatedBy)) { blnResult = true; } #endregion } catch (Exception ex) { lblError.Text = ex.Message; } finally { objUser.Dispose(); } return(blnResult); }
protected void imgSaveOnly_Click(object sender, ImageClickEventArgs e) { string strMessage = string.Empty; string strScript = string.Empty; cUser oUser = new cUser(); DataSet ds = new DataSet(); try { string strCheck = string.Empty; strCheck = " and [loginname] = '" + txtloginname.Text.Trim() + "' "; if (!oUser.SP_USER_SEL(strCheck, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count == 0) { strScript = "alert('ไม่สามารถบันข้อมูลได้ เนื่องจาก" + "\\nไม่พบข้อมูล Username : "******"');"; MsgBox(strScript); return; } } string strUserID = ds.Tables[0].Rows[0]["userID"].ToString(); saveData(strUserID); } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oUser.Dispose(); ds.Dispose(); } }
private void BindGridView() { cUser oUser = new cUser(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strActive = string.Empty; string strperson_code = string.Empty; string strperson_name = string.Empty; string strloginname = string.Empty; strperson_code = txtperson_code.Text.Replace("'", "''").Trim(); strperson_name = txtperson_name.Text.Replace("'", "''").Trim(); strloginname = txtloginname.Text.Replace("'", "''").Trim(); if (!strperson_code.Equals("")) { strCriteria = strCriteria + " And (person_code= '" + strperson_code + "') "; } if (!strperson_name.Equals("")) { strCriteria = strCriteria + " And (person_thai_name like '%" + strperson_name + "%' " + " OR person_thai_surname like '%" + strperson_name + "%' " + " OR person_eng_name like '%" + strperson_name + "%' " + " OR person_eng_surname like '%" + strperson_name + "%')"; } if (!strloginname.Equals("")) { strCriteria = strCriteria + " And (loginname Like '%" + strloginname + "%') "; } strCriteria = strCriteria + " And ([status] ='Y') "; try { if (!oUser.SP_USER_SEL(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count == 1) { string strScript = string.Empty; strperson_code = ds.Tables[0].Rows[0]["loginname"].ToString(); strperson_name = ds.Tables[0].Rows[0]["person_thai_name"].ToString() + " " + ds.Tables[0].Rows[0]["person_thai_surname"].ToString(); if (!ViewState["show"].ToString().Equals("1")) { strScript = "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strperson_code + "';\n " + "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strperson_name + "';\n" + "ClosePopUp('" + ViewState["show"].ToString() + "');"; } else { strScript = "window.parent.document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strperson_code + "';\n " + "window.parent.document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strperson_name + "';\n" + "ClosePopUp('" + ViewState["show"].ToString() + "');"; } ScriptManager.RegisterStartupScript(Page, Page.GetType(), "close", strScript, true); } else { 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.Dispose(); ds.Dispose(); } }
private void BindGridView(int nPageNo) { InitcboPerson_group(); //InitcboDirector(); // InitcboUnit(); cUser oUser = new cUser(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strYear = string.Empty; string strActive = string.Empty; string strloginname = string.Empty; string strperson_group_code = string.Empty; string strperson_group_name = string.Empty; string strdirector_code = string.Empty; string strunit_code = string.Empty; string strperson_code = string.Empty; string strperson_name = string.Empty; string strloginnames = string.Empty; string struser_group_code = string.Empty; strloginnames = txtloginname.Text; strperson_group_code = cboPerson_group.SelectedValue; strdirector_code = cboDirector.SelectedValue; strunit_code = cboUnit.SelectedValue; strperson_code = txtperson_code.Text.Replace("'", "''").Trim(); strperson_name = txtperson_name.Text.Replace("'", "''").Trim(); struser_group_code = cbouser_group.SelectedValue; //if (!strYear.Equals("")) //{ // strCriteria = strCriteria + " And (budget_plan_year = '" + strYear + "') "; //} if (!strloginnames.Equals("")) { strCriteria = strCriteria + " And (loginname like '%" + strloginnames + "%') "; } if (!strperson_group_code.Equals("")) { strCriteria = strCriteria + " And (person_group_code like '%" + strperson_group_code + "%') "; } if (!strdirector_code.Equals("")) { strCriteria = strCriteria + " And (director_code = '" + strdirector_code + "') "; } if (!strunit_code.Equals("")) { strCriteria = strCriteria + " And (unit_code= '" + strunit_code + "') "; } if (!strperson_code.Equals("")) { strCriteria = strCriteria + " And (person_code= '" + strperson_code + "') "; } if (!struser_group_code.Equals("")) { strCriteria = strCriteria + " And (user_group_code= '" + struser_group_code + "') "; } if (!strperson_name.Equals("")) { strCriteria = strCriteria + " And (person_thai_name like '%" + strperson_name + "%' " + " OR person_thai_surname like '%" + strperson_name + "%' " + " OR person_eng_name like '%" + strperson_name + "%' " + " OR person_eng_surname like '%" + strperson_name + "%')"; } try { if (!oUser.SP_USER_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.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }
private bool saveData() { bool blnResult = false; bool blnDup = false; string strMessage = string.Empty; //Tab 1 string strUserID = Helper.CStr(Helper.CInt(hddUserID.Value)), strperson_code = string.Empty, strloginname = string.Empty, strpassword = string.Empty, stremail = string.Empty, struser_group_code = string.Empty, strStatus = string.Empty, strRemark = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty; string strScript = string.Empty; cUser oUser = new cUser(); DataSet ds = new DataSet(); try { #region set Data strperson_code = txtperson_code.Text; strloginname = txtloginname.Text; strpassword = txtpassword.Text; stremail = txtemail.Text; struser_group_code = cbouser_group.SelectedValue; if (chkStatus.Checked == true) { strStatus = "Y"; } else { strStatus = "N"; } strCreatedBy = Session["username"].ToString(); strUpdatedBy = Session["username"].ToString(); #endregion if (ViewState["mode"].ToString().ToLower().Equals("edit")) { #region edit #region check dup string strCheckDup = string.Empty; strCheckDup = " and [loginname] = '" + strloginname + "' and [loginname] <> '" + hddusername.Value.ToString() + "' "; if (!oUser.SP_USER_SEL(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก" + "\\nข้อมูล Username : "******"\\nซ้ำ\");\n"; blnDup = true; } } #endregion if (!blnDup) { if (oUser.SP_USER_UPD(strUserID, strperson_code, strloginname, strpassword, stremail, struser_group_code, strStatus, strRemark, strUpdatedBy, cboBudget_type.SelectedValue, 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 [loginname] = '" + strloginname + "' "; if (!oUser.SP_USER_SEL(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถเพิ่มข้อมูลได้ เนื่องจาก" + "\\nข้อมูล Username : "******"\\nซ้ำ\");\n"; blnDup = true; } } #endregion #region insert if (!blnDup) { if (oUser.SP_USER_INS(ref strUserID, strperson_code, strloginname, strpassword, stremail, struser_group_code, strStatus, strRemark, strCreatedBy, cboBudget_type.SelectedValue, ref strMessage)) { string strCode = " and [loginname] = '" + strloginname + "' "; if (!oUser.SP_USER_SEL(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { ViewState["userID"] = ds.Tables[0].Rows[0]["userID"].ToString(); } } 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 { oUser.Dispose(); } return(blnResult); }