예제 #1
0
        protected void btnModalSave_Click(object sender, EventArgs e)
        {
            try
            {
                //Validate
                if (txtMUnitCode.Text == "")
                {
                    ShowMessageBox("กรุณาระบุ ชื่อลูกค้า !!!");
                    ModalPopupExtender1.Show();
                    return;
                }

                if (txtMUnitName.Text == "")
                {
                    ShowMessageBox("กรุณาระบุ รหัส !!!");
                    ModalPopupExtender1.Show();
                    return;
                }

                MasUnit o = new MasUnit();
                if (hddMode.Value == "Add") // Add
                {
                    o             = new MasUnit();
                    o.UnitCode    = txtMUnitCode.Text;
                    o.UnitName    = txtMUnitName.Text;
                    o.Active      = "Y";
                    o.CreatedBy   = GetUsername();
                    o.CreatedDate = DateTime.Now;
                    using (BillingEntities cre = new BillingEntities())
                    {
                        cre.MasUnits.Add(o);
                        cre.SaveChanges();
                    };
                }
                else //Edit
                {
                    int objID = ToInt32(hddID.Value);
                    using (BillingEntities cre = new BillingEntities())
                    {
                        o = cre.MasUnits.FirstOrDefault(w => w.UnitID.Equals(objID));
                        if (o != null)
                        {
                            o.UnitCode    = txtMUnitCode.Text;
                            o.UnitName    = txtMUnitName.Text;
                            o.UpdatedBy   = GetUsername();
                            o.UpdatedDate = DateTime.Now;
                        }
                        cre.SaveChanges();
                    };
                }

                BindData();
                ShowMessageBox("บันทึกข้อมูลสำเร็จ.");
            }
            catch (Exception ex)
            {
                ShowMessageBox("เกิดข้อผิดพลาด กรุณาติดต่อผู้ดูแลระบบ.");
                SendMailError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }
예제 #2
0
 protected void imgbtnDelete_Click(object sender, ImageClickEventArgs e)
 {
     try
     {
         ImageButton imb = (ImageButton)sender;
         if (imb != null)
         {
             MasUnit obj   = new MasUnit();
             int     objID = ToInt32(imb.CommandArgument);
             using (BillingEntities cre = new BillingEntities())
             {
                 obj = cre.MasUnits.FirstOrDefault(w => w.UnitID.Equals(objID));
                 if (obj != null)
                 {
                     obj.Active      = "N";
                     obj.UpdatedBy   = GetUsername();
                     obj.UpdatedDate = DateTime.Now;
                 }
                 //cre.MasUnits.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());
     }
 }
예제 #3
0
        public List <MasUnit> GetSearchUnit()
        {
            List <MasUnit> lst = new List <MasUnit>();

            try
            {
                List <SqlParameter> param = new List <SqlParameter>();
                DataSet             ds    = conn.GetDataSet("GetSearchUnit", param);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null)
                {
                    MasUnit o = new MasUnit();
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        o          = new MasUnit();
                        o.UnitID   = Convert.ToInt32(dr["UnitID"].ToString());
                        o.UnitCode = dr["UnitCode"].ToString();
                        o.UnitName = dr["UnitName"].ToString();
                        o.Active   = dr["Active"].ToString();
                        lst.Add(o);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(lst);
        }
예제 #4
0
        protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                ImageButton imb = (ImageButton)sender;
                MasUnit     obj = new MasUnit();
                if (imb != null)
                {
                    int objID = ToInt32(imb.CommandArgument);
                    using (BillingEntities cre = new BillingEntities())
                    {
                        obj = cre.MasUnits.FirstOrDefault(w => w.UnitID.Equals(objID));
                    };

                    if (obj != null)
                    {
                        hddID.Value       = imb.CommandArgument;
                        txtMUnitCode.Text = obj.UnitCode;
                        txtMUnitName.Text = obj.UnitName;

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