Exemple #1
0
        public ActionResult Edit(PhieuEditModel model)
        {
            model.DichVus  = JsonConvert.DeserializeObject <List <PhieuDichVuModel> >(model.jsonDichVus);
            model.PhuTungs = JsonConvert.DeserializeObject <List <PhieuPhuTungModel> >(model.jsonPhuTungs);
            var rs = BLLReceipt.Instance.Edit(App_Global.AppGlobal.Connectionstring, model);

            ViewBag.NhanViens = BLLUser.Instance.GetLookUp(App_Global.AppGlobal.Connectionstring, 0);
            ViewBag.Works     = JsonConvert.SerializeObject(BLLDichVu.Instance.GetLookUp(App_Global.AppGlobal.Connectionstring, model.LoaiXeId));
            ViewBag.Phutungs  = JsonConvert.SerializeObject(BLLPhuTung.Instance.GetLookUp(App_Global.AppGlobal.Connectionstring));
            return(RedirectToAction("phieumo"));
        }
Exemple #2
0
        public ResponseModel Edit(string connectString, PhieuEditModel model)
        {
            var result = new ResponseModel();

            result.IsSuccess = true;
            using (var db = new HMSEntities(connectString))
            {
                try
                {
                    H_Receiption receiptInfo = db.H_Receiption.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
                    if (receiptInfo != null)
                    {
                        receiptInfo.NV_KTTruong  = model.KTDKyId;
                        receiptInfo.NV_SuaXe     = model.SuaXeId;
                        receiptInfo.NV_ThuNgan   = model.ThuNganId;
                        receiptInfo.NV_TiepNhan  = model.TiepNhanId;
                        receiptInfo.NV_KTCuoi    = model.KTraCuoiId;
                        receiptInfo.Required     = model.YeuCau;
                        receiptInfo.CheckResult  = model.NhanXet;
                        receiptInfo.StatusBefore = model.TrangThai;
                        receiptInfo.Note         = model.GhiChu;
                        receiptInfo.Total_Cong   = model.DichVus.Sum(x => x.GiaCK);
                        receiptInfo.Total_PTung  = model.PhuTungs.Sum(x => x.GiaCK);
                        receiptInfo.Total        = receiptInfo.Total_Cong + receiptInfo.Total_PTung;
                        receiptInfo.Total_NhapPT = model.PhuTungs.Sum(x => x.GiaBan * x.SoLuong);
                        receiptInfo.SL_PT        = model.PhuTungs.Count(x => x.PTId != null);
                        receiptInfo.Date         = (model.NgaySua.Year == 1 ? DateTime.Now : model.NgaySua);
                        string query = "";
                        if (model.DichVus != null && model.DichVus.Count > 0)
                        {
                            query += (" update [H_Receipt_DichVu] set isdeleted=1 where ReceiptId=" + model.Id);

                            receiptInfo.H_Receipt_DichVu = new List <H_Receipt_DichVu>();
                            for (int i = 0; i < model.DichVus.Count; i++)
                            {
                                if (model.DichVus[i].DVId > 0)
                                {
                                    query += " INSERT INTO [dbo].[H_Receipt_DichVu] ([ReceiptId],[DichVuId],[Index],[Price],[Percent],[PricePercent],[IsDeleted]) VALUES (" + model.Id + "," + model.DichVus[i].DVId + ",1,'" + model.DichVus[i].GiaBan.ToString().Replace(',', '.') + "','" + model.DichVus[i].CKhau.ToString().Replace(',', '.') + "','" + model.DichVus[i].GiaCK.ToString().Replace(',', '.') + "',0)";
                                }
                            }
                        }
                        if (model.PhuTungs != null && model.PhuTungs.Count > 0)
                        {
                            query += (" update [H_Receipt_PT] set isdeleted=1 where ReceiptId=" + model.Id);

                            receiptInfo.H_Receipt_DichVu = new List <H_Receipt_DichVu>();
                            for (int i = 0; i < model.PhuTungs.Count; i++)
                            {
                                if (model.PhuTungs[i].PTId > 0)
                                {
                                    query += " INSERT INTO [dbo].[H_Receipt_PT] ([ReceiptId],[PT_Id],[Index],[Quantities],[Price],[Percent],[PricePercent],[Total],[IsDeleted]) VALUES (" + model.Id + "," + model.PhuTungs[i].PTId + ",1," + model.PhuTungs[i].SoLuong + ",'" + model.PhuTungs[i].GiaBan.ToString().Replace(',', '.') + "','" + model.PhuTungs[i].CKhau.ToString().Replace(',', '.') + "','" + model.PhuTungs[i].GiaCK.ToString().Replace(',', '.') + "','" + (model.PhuTungs[i].SoLuong * model.PhuTungs[i].GiaCK).ToString().Replace(',', '.') + "',0)";
                                }
                            }
                        }
                        if (!string.IsNullOrEmpty(query))
                        {
                            db.Database.ExecuteSqlCommand(query);
                        }
                        db.SaveChanges();
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.sms       = "Phiếu dịch vụ này đã bị xóa hoặc không tồn tại trong hệ thống. Vui lòng kiểm tra lại.";
                    }
                }
                catch (Exception ex)
                {
                }
                return(result);
            }
        }