Example #1
0
        private void setData()
        {
            cUser   oUser = new cUser();
            DataSet ds = new DataSet();
            string  strMessage = string.Empty, strCriteria = string.Empty;

            try
            {
                strCriteria = " and UserID = '" + ViewState["userID"].ToString() + "' ";
                if (!oUser.SP_USER_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        hddUserID.Value           = ds.Tables[0].Rows[0]["UserID"].ToString();
                        txtperson_code.Text       = ds.Tables[0].Rows[0]["person_code"].ToString();
                        txtperson_name.Text       = ds.Tables[0].Rows[0]["person_thai_name"].ToString() + "  " + ds.Tables[0].Rows[0]["person_thai_surname"].ToString();
                        txtperson_group_name.Text = ds.Tables[0].Rows[0]["person_group_name"].ToString();
                        txtdirector_name.Text     = ds.Tables[0].Rows[0]["director_name"].ToString();
                        txtunit_name.Text         = ds.Tables[0].Rows[0]["unit_name"].ToString();
                        txtemail.Text             = ds.Tables[0].Rows[0]["email"].ToString();
                        txtloginname.Text         = ds.Tables[0].Rows[0]["loginname"].ToString();
                        hddusername.Value         = ds.Tables[0].Rows[0]["loginname"].ToString();
                        txtpassword.Text          = Cryptorengine.Decrypt(ds.Tables[0].Rows[0]["password"].ToString(), true);
                        string strBudget_type = ds.Tables[0].Rows[0]["budget_type"].ToString();
                        InitcboBudgetType();
                        if (cboBudget_type.Items.FindByValue(strBudget_type) != null)
                        {
                            cboBudget_type.SelectedIndex = -1;
                            cboBudget_type.Items.FindByValue(strBudget_type).Selected = true;
                        }
                        if (ds.Tables[0].Rows[0]["status"].ToString() == "Y")
                        {
                            chkStatus.Checked = true;
                        }
                        else
                        {
                            chkStatus.Checked = false;
                        }
                        InitcboUser_group();
                        cbouser_group.SelectedValue = ds.Tables[0].Rows[0]["user_group_code"].ToString();
                        txtUpdatedBy.Text           = ds.Tables[0].Rows[0]["UpdatedBy"].ToString();;
                        txtUpdatedDate.Text         = cCommon.CheckDate(ds.Tables[0].Rows[0]["UpdatedDate"].ToString());

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
Example #2
0
        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();
            }
        }
Example #3
0
        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();
            }
        }
Example #4
0
        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;
                }
            }
        }
Example #5
0
        protected bool SetUserProfile(string strUserName, string strPassword, ref string _strError)
        {
            bool      booResult = false;
            cUser     objUser   = new cUser();
            DataTable dt        = new DataTable();
            DataSet   ds        = new DataSet();
            string    strCriteria;
            string    strMessage         = string.Empty;
            string    strDecryptPassword = string.Empty;

            strCriteria = " And LoginName='" + strUserName + "' ";
            objUser.SP_USER_SEL(strCriteria, ref ds, ref strMessage);
            dt = ds.Tables[0];
            if (dt.Rows.Count > 0)
            {
                strDecryptPassword = Cryptorengine.Decrypt(Helper.CStr(dt.Rows[0]["Password"]), true);
                if (strDecryptPassword.Equals(strPassword))
                {
                    this.IsLogin       = "******";
                    this.UserID        = Helper.CInt(dt.Rows[0]["UserID"]);
                    this.UserLoginName = Helper.CStr(dt.Rows[0]["LoginName"]);
                    this.DirectorLock  = Helper.CStr(dt.Rows[0]["director_lock"]);
                    this.DirectorCode  = Helper.CStr(dt.Rows[0]["director_code"]);
                    this.DirectorName  = Helper.CStr(dt.Rows[0]["director_name"]);

                    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);
                    }

                    this.myBudgetType = Helper.CStr(dt.Rows[0]["budget_type"]);
                    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);

                    cItem     objItem = new cItem();
                    DataTable dt2     = new DataTable();
                    DataSet   ds2     = new DataSet();
                    string    strYear = ((DataSet)Application["xmlconfig"]).Tables["default"].Rows[0]["yearnow"].ToString();
                    strCriteria  = " And person_group_code in (" + PersonGroupList + ") And lot_code<>'' ";
                    strCriteria += " And item_year = " + strYear;
                    objItem.SP_ITEM_LOT_GROUP_SEL(strCriteria, ref ds2, ref strMessage);
                    LotCodeList = string.Empty;
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        LotCodeList = LotCodeList + "'" + ds2.Tables[0].Rows[i]["lot_code"].ToString() + "',";
                    }
                    if (LotCodeList.Length > 0)
                    {
                        LotCodeList = LotCodeList.Substring(0, LotCodeList.Length - 1);
                    }
                    booResult = true;
                }
                else
                {
                    _strError = "รหัสผ่านไม่ถูกต้อง";
                }
            }
            else
            {
                _strError = "ไม่พบผู้ใช้งานนี้";
            }
            return(booResult);
        }
Example #6
0
        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);
        }
Example #7
0
        private void BindGridView()
        {
            cUser_menu objUserMenu  = new cUser_menu();
            DataSet    ds           = new DataSet();
            string     strMessage   = string.Empty;
            string     strCriteria  = string.Empty;
            string     strloginname = txtloginname.Text;

            try
            {
                strCriteria  = " and loginname='" + strloginname + "' ";
                strCriteria += " And Menu_Status='Y' ";

                objUserMenu.SP_USER_MENU_MANAGE_SEL(strCriteria, ref ds, ref strMessage);
                GridView1.DataSource = ds;
                GridView1.DataBind();

                cUser  oUser    = new cUser();
                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)
                    {
                        string strScript =
                            "alert('ไม่สามารถบันข้อมูลได้ เนื่องจาก" +
                            "\\nไม่พบข้อมูล Username : "******"');";
                        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();
            }
        }