Ejemplo n.º 1
0
    public void btnSave_Click(object sender, System.EventArgs e)
    {
        try
        {
            logger.Info(HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            if (btnCP_Save.Text == "แก้ไข")
            {
                GetDetailsDataToForm(txtCP_User_ID.Text, "Edit");
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
            }
            else
            {
                if (txtCP_Password.Text == string.Empty)
                {
                    txtCP_Password.Text = hdfPasswrod.Value;
                }

                Validate("CPValidation");

                if (Page.IsValid)
                {
                    //string User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value;
                    dbo_UserClass user_class = dbo_UserDataClass.Select_Record(hdfUser_ID.Value);

                    Regex  r        = new Regex("^(?=.*[a-zA-Z])(?=.*[0-9])");
                    string Pass_Old = user_class.Password.ToString();
                    List <dbo_PasswordHistoryClass> item = dbo_PasswordHistoryDataClass.Search(txtCP_UserName.Text);
                    dbo_PasswordHistoryClass        pass = item.OrderByDescending(f => f.Last_Password_Change_Or_Reset).Take(3).FirstOrDefault(f => f.Password == txtCP_Password.Text);

                    string cntUsername = CheckUsername.Check_Username(txtCP_UserName.Text, txtCP_User_ID.Text);
                    string cntUserID   = CheckUsername.Check_UserID(txtCP_User_ID.Text);
                    bool   flag        = false;

                    if (Pass_Old.ToString() != txtCP_Password.Text)
                    {
                        if (pass != null)
                        {
                            flag = true;
                            //ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                            //Show("รหัสผ่านต้องไม่ซ้ำกันกับ 3 ครั้งที่ผ่านมา");
                        }
                    }
                    //else
                    //{
                    //    if (Pass_Old.ToString() != txtCP_Password.Text)
                    //    {
                    //        if (pass != null)
                    //        {
                    //            flag = true;
                    //            //ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                    //            //Show("รหัสผ่านต้องไม่ซ้ำกันกับ 3 ครั้งที่ผ่านมา");
                    //        }
                    //    }
                    //}

                    if (txtCP_Password.Text.Length < 8)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                        Show("รหัสผ่านควรมีอย่างน้อย 8 ตัวอักษร");
                    }
                    else if (!r.IsMatch(txtCP_Password.Text))
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                        Show("รหัสผ่านควรประกอบด้วยตัวเลขและตัวอักษร");
                    }
                    //else if (pass != null)
                    //{
                    //    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                    //    Show("รหัสผ่านต้องไม่ซ้ำกันกับ 3 ครั้งที่ผ่านมา");
                    //}
                    else if (flag == true)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                        Show("รหัสผ่านต้องไม่ซ้ำกันกับ 3 ครั้งที่ผ่านมา");
                        flag = false;
                    }
                    else if (cntUserID != "0" && btnSaveMode.Value == "บันทึก")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                        // Show("รหัสพนักงานไม่สามารถซ้ำได้");
                        Show("เนื่องจากรหัสพนักงาน " + txtCP_User_ID.Text + " ถูกสร้างขึ้นแล้ว ระบบจะทำการสร้างรหัสพนักงานให้ใหม่");
                        txtCP_User_ID.Text = GenerateID.UserID_CP();
                    }
                    else if (cntUsername != "0")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                        Show("ชื่อผู้ใช้งานไม่สามารถซ้ำได้");
                    }
                    else
                    {
                        if (btnSaveMode.Value == "บันทึก")
                        {
                            InsertRecord();
                            if (hdfPasswrod.Value != txtCP_Password.Text)
                            {
                                dbo_PasswordHistoryClass password = new dbo_PasswordHistoryClass();
                                password.Last_Password_Change_Or_Reset = DateTime.Now;
                                password.Password = txtCP_Password.Text;
                                password.User_ID  = txtCP_UserName.Text;
                                dbo_PasswordHistoryDataClass.Add(password);
                            }
                        }
                        else
                        {
                            UpdateRecord();
                            if (hdfPasswrod.Value != txtCP_Password.Text)
                            {
                                dbo_PasswordHistoryClass password = new dbo_PasswordHistoryClass();
                                password.Last_Password_Change_Or_Reset = DateTime.Now;
                                password.Password = txtCP_Password.Text;
                                password.User_ID  = txtCP_UserName.Text;

                                dbo_PasswordHistoryDataClass.Add(password);
                            }
                        }

                        SearchSubmit();

                        System.Threading.Thread.Sleep(500);
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                    Show("กรุณากรอกข้อมูลที่จำเป็นให้ครบถ้วน");
                }
            }
        }
        catch (Exception ex)
        {
            logger.Debug(ex.Message);
        }
    }
Ejemplo n.º 2
0
    private void GetDetailsDataToForm(string id, string Mode)
    {
        logger.Info(HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name);

        try
        {
            showPanel("pnlCPMeiji");

            txtCP_FirstName.Text      = string.Empty;
            txtCP_LastName.Text       = string.Empty;
            txtCP_First_Name_Eng.Text = string.Empty;
            txtCP_Last_Name_Eng.Text  = string.Empty;
            txtCP_Phone.Text          = string.Empty;
            txtCP_Mobile.Text         = string.Empty;
            txtCP_UserName.Text       = " ";

            txtCP_Password.Text = "";
            txtCP_Password.Text = null;

            txtCP_Email.Text = string.Empty;


            ddlCP_TitleID.ClearSelection();
            ddlCP_Position.ClearSelection();
            ddlCP_UserRole.ClearSelection();
            ddlCP_ShowDashboard.ClearSelection();
            ddlCP_Status.ClearSelection();
            txtCP_User_ID.Enabled = false;
            ddlLocation_Region.ClearSelection();

            hdfPasswrod.Value = string.Empty;



            if (!string.IsNullOrEmpty(id))
            {
                dbo_UserClass user_class = dbo_UserDataClass.Select_Record(id);

                txtCP_User_ID.Text        = user_class.User_ID;
                txtCP_FirstName.Text      = user_class.First_Name;
                txtCP_LastName.Text       = user_class.Last_Name;
                txtCP_First_Name_Eng.Text = user_class.First_Name_Eng;
                txtCP_Last_Name_Eng.Text  = user_class.Last_Name_Eng;
                txtCP_Phone.Text          = user_class.Home_Phone_No;
                txtCP_Mobile.Text         = user_class.Mobile;
                txtCP_Email.Text          = user_class.Email;
                txtCP_UserName.Text       = user_class.Username;
                txtCP_Password.Text       = user_class.Password;
                hdfPasswrod.Value         = user_class.Password;

                if (user_class.Title_ID != null)
                {
                    if (ddlCP_TitleID.Items.FindByText(user_class.Title_ID.Trim()) != null)
                    {
                        ddlCP_TitleID.Items.FindByText(user_class.Title_ID.Trim()).Selected = true;
                    }
                }

                if (user_class.Region != null)
                {
                    foreach (string region in user_class.Region.Split(',').ToList())
                    {
                        if (ddlLocation_Region.Items.FindByText(region) != null)
                        {
                            ddlLocation_Region.Items.FindByText(region).Selected = true;
                        }
                    }
                }

                if (user_class.Position != null)
                {
                    if (ddlCP_Position.Items.FindByText(user_class.Position.Trim()) != null)
                    {
                        ddlCP_Position.Items.FindByText(user_class.Position.Trim()).Selected = true;
                    }
                }
                if (user_class.Role_ID != null)
                {
                    //if (ddlCP_UserRole.Items.FindByText(user_class.Role_ID.Trim()) != null)
                    //    ddlCP_UserRole.Items.FindByText(user_class.Role_ID.Trim()).Selected = true;
                    if (ddlCP_UserRole.Items.FindByValue(user_class.Role_ID.Trim()) != null)
                    {
                        ddlCP_UserRole.Items.FindByValue(user_class.Role_ID.Trim()).Selected = true;
                    }
                }
                if (user_class.ShowDashboard != null)
                {
                    if (ddlCP_ShowDashboard.Items.FindByText(user_class.ShowDashboard.Trim()) != null)
                    {
                        ddlCP_ShowDashboard.Items.FindByText(user_class.ShowDashboard.Trim()).Selected = true;
                    }
                }

                if (user_class.Status != null)
                {
                    if (ddlCP_Status.Items.FindByText(user_class.Status.Trim()) != null)
                    {
                        ddlCP_Status.Items.FindByText(user_class.Status.Trim()).Selected = true;
                    }
                }
            }

            bool enable = Mode != "View";

            txtCP_UserName.Enabled = enable;
            txtCP_Password.Enabled = enable;
            ddlCP_Status.Enabled   = enable;
            // ddlCP_Approval.Enabled = enable;

            txtCP_FirstName.Enabled      = enable;
            txtCP_LastName.Enabled       = enable;
            txtCP_First_Name_Eng.Enabled = enable;
            txtCP_Last_Name_Eng.Enabled  = enable;
            txtCP_Phone.Enabled          = enable;
            txtCP_Mobile.Enabled         = enable;
            txtCP_Email.Enabled          = enable;
            ddlCP_UserRole.Enabled       = enable;
            ddlCP_ShowDashboard.Enabled  = enable;
            ddlCP_TitleID.Enabled        = enable;
            ddlCP_Position.Enabled       = enable;

            ddlLocation_Region.Enabled = enable;
            if (Mode == "View")
            {
                btnCP_Save.Visible   = true;
                btnCP_Save.Text      = "แก้ไข";
                btnCP_Cancel.Text    = "กลับไปหน้าค้นหา";
                btnSaveMode.Value    = "แก้ไข";
                LabelPageHeader.Text = "รายละเอียดข้อมูล User";
            }
            else if (Mode == "Edit")
            {
                btnCP_Save.Visible   = true;
                btnCP_Save.Text      = "บันทึก";
                btnCP_Cancel.Text    = "ยกเลิก";
                btnSaveMode.Value    = "แก้ไข";
                LabelPageHeader.Text = "แก้ไขข้อมูล User";
            }
            else if (string.IsNullOrEmpty(Mode))
            {
                btnCP_Save.Visible   = true;
                btnCP_Save.Text      = "บันทึก";
                btnCP_Cancel.Text    = "ยกเลิก";
                btnSaveMode.Value    = "บันทึก";
                txtCP_User_ID.Text   = GenerateID.UserID_CP();
                LabelPageHeader.Text = "สร้างข้อมูล User";
            }
        }
        catch (Exception)
        {
        }
    }