示例#1
0
        public ActionResult Create([Bind(Include = "tid,name")] Type type)
        {
            if (ModelState.IsValid)
            {
                db.Types.Add(type);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(type));
        }
示例#2
0
        public ActionResult Create([Bind(Include = "uid,username,password,name,accessLevel")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
示例#3
0
        public ActionResult Create([Bind(Include = "mid,name")] Manufacturer manufacturer)
        {
            if (ModelState.IsValid)
            {
                db.Manufacturers.Add(manufacturer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(manufacturer));
        }
        public ActionResult Create([Bind(Include = "cid,fname,mname,lname,gender,dob,phone,mob,mobAlt,email,address,dlNo,tinNo")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.gender = new SelectList(db.Genders, "value", "value", customer.gender);
            return(View(customer));
        }
        public ActionResult Create([Bind(Include = "pid,name,weight,tid,mid,mrp,rate,vat,discount")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.mid = new SelectList(db.Manufacturers, "mid", "name", product.mid);
            ViewBag.tid = new SelectList(db.Types, "tid", "name", product.tid);
            return(View(product));
        }
示例#6
0
        public ActionResult GenerateNewInvoice(Invoice mdl)
        {
            int?invoiceId = db.Invoice_IdMax().First();

            mdl.id     = (int)invoiceId + 1;
            mdl.date   = DateTime.Now;
            mdl.uid    = 1;
            mdl.status = 11;
            db.Invoices.Add(mdl);
            db.SaveChanges();
            return(RedirectToAction("GenerateInvoice", new { id = mdl.id }));
            //return View("GenerateInvoice", mdl);
        }
示例#7
0
        public ActionResult Create([Bind(Include = "iid,pid,quantity,exDate,batchNo,status")] Inventory inventory)
        {
            if (ModelState.IsValid)
            {
                db.Inventories.Add(inventory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.pid    = new SelectList(db.Products, "pid", "name", inventory.pid);
            ViewBag.status = new SelectList(db.Status, "id", "description", inventory.status);
            return(View(inventory));
        }
        public ActionResult Create([Bind(Include = "id,cid,uid,date,dueDate,status")] Invoice invoice)
        {
            if (ModelState.IsValid)
            {
                db.Invoices.Add(invoice);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.cid    = new SelectList(db.Customers, "cid", "fname", invoice.cid);
            ViewBag.status = new SelectList(db.Status, "id", "description", invoice.status);
            ViewBag.uid    = new SelectList(db.Users, "uid", "username", invoice.uid);
            return(View(invoice));
        }
示例#9
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");
        }
 protected void imgbtnDelete_Click(object sender, ImageClickEventArgs e)
 {
     try
     {
         ImageButton imb = new ImageButton();
         imb = (ImageButton)sender;
         if (imb != null)
         {
             Int32           ID = ToInt32(imb.CommandArgument);
             TransSaleHeader o  = new TransSaleHeader();
             using (BillingEntities cre = new BillingEntities())
             {
                 o = cre.TransSaleHeaders.FirstOrDefault(w => w.SaleHeaderID.Equals(ID));
                 if (o != null)
                 {
                     cre.TransSaleHeaders.Remove(o);
                     cre.SaveChanges();
                 }
             };
         }
         ShowMessageBox("ลบรายการสำเร็จ.");
         BindData();
     }
     catch (Exception ex)
     {
     }
 }
示例#11
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());
            }
        }
示例#12
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());
     }
 }
        public ActionResult Delete(int id)
        {
            BillingEntities db      = new BillingEntities();
            var             getdata = db.Bills.FirstOrDefault(m => m.B_no == id);

            db.Bills.Remove(getdata);
            db.SaveChanges();
            return(RedirectToAction("Display", "Home"));
        }
        public ActionResult Insert(BillModel d)
        {
            BillingEntities db = new BillingEntities();
            Bill            B  = new Bill();

            B.Product = d.Product;
            B.Price   = d.Price;
            B.Date    = d.Date;
            db.Bills.Add(B);
            db.SaveChanges();
            ViewBag.Text = "Details Inserted";

            return(RedirectToAction("Display", "Home"));
        }
        public ActionResult Update(int ID, BillModel dt)
        {
            BillingEntities db = new BillingEntities();

            var getdata = db.Bills.FirstOrDefault(m => m.B_no == ID);

            getdata.Product = (string)dt.Product;
            getdata.Price   = (Decimal)dt.Price;
            getdata.Date    = (DateTime)dt.Date;
            db.SaveChanges();

            ViewBag.Text = "Details Updated";


            return(RedirectToAction("Display", "Home"));
        }
示例#16
0
        protected void LoginUser_LoggedIn(object sender, EventArgs e)
        {
            var loginForm = (System.Web.UI.WebControls.Login)sender;
            BillingEntities db = new BillingEntities();
            User user = db.Users.FirstOrDefault(s => s.Login.ToLower() == loginForm.UserName.ToLower());
            if (user == null) return;

            db.UsersLogs.AddObject(new UsersLog
                                       {
                                           Date = DateTime.Now,
                                           Text = "User logged in from Ip " + Request.UserHostAddress,
                                           UserId = user.Id
                                       });
            //user.IpAddress = Request.UserHostAddress;

            db.SaveChanges();
        }
示例#17
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());
            }
        }
 public virtual T Add(T t)
 {
     _context.Set <T>().Add(t);
     _context.SaveChanges();
     return(t);
 }