예제 #1
0
 protected void imgbtnDelete_Click(object sender, ImageClickEventArgs e)
 {
     try
     {
         ImageButton imb = (ImageButton)sender;
         if (imb != null)
         {
             MasAccount obj   = new MasAccount();
             int        objID = ToInt32(imb.CommandArgument);
             using (BillingEntities cre = new BillingEntities())
             {
                 obj = cre.MasAccounts.FirstOrDefault(w => w.AccountID.Equals(objID));
                 cre.MasAccounts.Remove(obj);
                 cre.SaveChanges();
             };
             BindData();
         }
         else
         {
             SendMailError("imb is null", System.Reflection.MethodBase.GetCurrentMethod());
         }
     }
     catch (Exception ex)
     {
         ShowMessageBox("เกิดข้อผิดพลาด กรุณาติดต่อผู้ดูแลระบบ.");
         SendMailError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod());
     }
 }
예제 #2
0
        protected void btnModalSave_Click(object sender, EventArgs e)
        {
            try
            {
                //Validate
                //if (txtMCode.Text == "")
                //{
                //    ShowMessageBox("กรุณาระบุ รหัสสินค้า !!!");
                //    ModalPopupExtender1.Show();
                //    return;
                //}

                if (txtMAccountName.Text == "")
                {
                    ShowMessageBox("กรุณาระบุ ชื่อลูกค้า !!!");
                    ModalPopupExtender1.Show();
                    return;
                }

                MasAccount o = new MasAccount();
                if (hddMode.Value == "Add") // Add
                {
                    o             = new MasAccount();
                    o.AccountName = txtMAccountName.Text;
                    o.Address     = txtMAddress.Text;
                    o.CreatedBy   = GetUsername();
                    o.CreatedDate = DateTime.Now;
                    using (BillingEntities cre = new BillingEntities())
                    {
                        cre.MasAccounts.Add(o);
                        cre.SaveChanges();
                    };
                }
                else //Edit
                {
                    int objID = ToInt32(hddID.Value);
                    using (BillingEntities cre = new BillingEntities())
                    {
                        o = cre.MasAccounts.FirstOrDefault(w => w.AccountID.Equals(objID));
                        if (o != null)
                        {
                            o.AccountName = txtMAccountName.Text;
                            o.Address     = txtMAddress.Text;
                            o.UpdatedBy   = GetUsername();
                            o.UpdatedDate = DateTime.Now;
                        }
                        cre.SaveChanges();
                    };
                }

                BindData();
                ShowMessageBox("บันทึกข้อมูลสำเร็จ.");
            }
            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;
                MasAccount  obj = new MasAccount();
                if (imb != null)
                {
                    int objID = ToInt32(imb.CommandArgument);
                    using (BillingEntities cre = new BillingEntities())
                    {
                        obj = cre.MasAccounts.FirstOrDefault(w => w.AccountID.Equals(objID));
                    };

                    if (obj != null)
                    {
                        hddID.Value          = imb.CommandArgument;
                        txtMAccountName.Text = obj.AccountName;
                        txtMAddress.Text     = obj.Address;

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