Пример #1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUser.Text == "")
            {
                lbMsg.Text = "กรุณาระบุ Username !!!";
                return;
            }

            if (txtPass.Text == "")
            {
                lbMsg.Text = "กรุณาระบุ Password !!!";
                return;
            }

            MasUserLogin o = new MasUserLogin();

            Session["Username"] = txtUser.Text;
            using (BillingEntities cre = new BillingEntities())
            {
                o = cre.MasUserLogins.FirstOrDefault(w => w.Username.Equals(txtUser.Text) && w.Password.Equals(txtPass.Text));
                if (o != null && o.Active == "Y")
                {
                    Session["Username"] = o.Username;
                    o.LastLogin         = DateTime.Now;
                    cre.SaveChanges();
                }
                else
                {
                    lbMsg.Text = "Username, Password ไม่ถูกต้อง !!!";
                    return;
                }
            };

            Response.Redirect("/Default.aspx");
        }
Пример #2
0
 protected void imgbtnDelete_Click(object sender, ImageClickEventArgs e)
 {
     try
     {
         ImageButton imb = (ImageButton)sender;
         if (imb != null)
         {
             MasUserLogin obj   = new MasUserLogin();
             int          objID = ToInt32(imb.CommandArgument);
             using (BillingEntities cre = new BillingEntities())
             {
                 obj        = cre.MasUserLogins.FirstOrDefault(w => w.Username.Equals(imb.CommandArgument));
                 obj.Active = "N";
                 cre.SaveChanges();
             };
             BindData();
         }
         else
         {
             SendMailError("imb is null", System.Reflection.MethodBase.GetCurrentMethod());
         }
     }
     catch (Exception ex)
     {
         ShowMessageBox("เกิดข้อผิดพลาด กรุณาติดต่อผู้ดูแลระบบ.");
         SendMailError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod());
     }
 }
Пример #3
0
        protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                ImageButton  imb = (ImageButton)sender;
                MasUserLogin obj = new MasUserLogin();
                if (imb != null)
                {
                    using (BillingEntities cre = new BillingEntities())
                    {
                        obj = cre.MasUserLogins.FirstOrDefault(w => w.Username.Equals(imb.CommandArgument));
                    };

                    if (obj != null)
                    {
                        txtMUsername.Text = obj.Username;
                        chkActive.Checked = obj.Active == "Y" ? true : false;

                        ModalPopupExtender1.Show();
                        hddMode.Value = "Edit";
                    }
                    else
                    {
                        SendMailError("obj is null, objID = " + imb.CommandArgument, System.Reflection.MethodBase.GetCurrentMethod());
                    }
                }
                else
                {
                    SendMailError("imb is null", System.Reflection.MethodBase.GetCurrentMethod());
                }
            }
            catch (Exception ex)
            {
                ShowMessageBox("เกิดข้อผิดพลาด กรุณาติดต่อผู้ดูแลระบบ.");
                SendMailError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }
Пример #4
0
        protected void btnModalSave_Click(object sender, EventArgs e)
        {
            try
            {
                //Validate
                if (txtMNewPass.Text == "" || txtMCheckPass.Text == "")
                {
                    ShowMessageBox("กรุณาระบุ Password !!!");
                    ModalPopupExtender1.Show();
                    return;
                }

                if (txtMNewPass.Text != txtMCheckPass.Text)
                {
                    ShowMessageBox("ระบุ Password ไม่ตรงกัน !!!");
                    ModalPopupExtender1.Show();
                    return;
                }

                MasUserLogin o = new MasUserLogin();
                if (hddMode.Value == "Add") // Add
                {
                    o          = new MasUserLogin();
                    o.Username = txtMUsername.Text;
                    o.Password = txtMNewPass.Text;
                    o.Active   = chkActive.Checked ? "Y" : "N";
                    using (BillingEntities cre = new BillingEntities())
                    {
                        cre.MasUserLogins.Add(o);
                        cre.SaveChanges();
                    };

                    BindData();
                    ShowMessageBox("บันทึกข้อมูลสำเร็จ.");
                }
                else //Edit
                {
                    using (BillingEntities cre = new BillingEntities())
                    {
                        o = cre.MasUserLogins.FirstOrDefault(w => w.Username.Equals(txtMUsername.Text));
                        if (o != null)
                        {
                            if (o.Password != txtMOldPass.Text)
                            {
                                ShowMessageBox("Password ไม่ถูกต้อง !!!");
                                ModalPopupExtender1.Show();
                            }
                            else
                            {
                                o.Password = txtMNewPass.Text;
                                o.Active   = chkActive.Checked ? "Y" : "N";
                                cre.SaveChanges();

                                BindData();
                                ShowMessageBox("บันทึกข้อมูลสำเร็จ.");
                            }
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                ShowMessageBox("เกิดข้อผิดพลาด กรุณาติดต่อผู้ดูแลระบบ.");
                SendMailError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }