コード例 #1
0
        private bool CheckExists(KhachHangModel KhachHang, HMSEntities db)
        {
            H_KhachHang obj = null;

            if (!string.IsNullOrEmpty(KhachHang.Ma))
            {
                obj = db.H_KhachHang.FirstOrDefault(x => !x.IsDeleted && x.Id != KhachHang.Id && x.Code.Trim().ToUpper().Equals(KhachHang.Ma.Trim().ToUpper()));
            }
            return(obj != null ? true : false);
        }
コード例 #2
0
        //public  SellReceiptModel  GetByCode(string connectString,string code)
        //{
        //    using (var db = new HMSEntities(connectString))
        //    {
        //        try
        //        {
        //            return (from x in db.H_SellReceipt
        //                    where !x.IsDeleted && x.Code.Trim().ToUpper() == code.Trim().ToUpper()
        //                    select new SellReceiptModel()
        //                    {
        //                        Id = x.Id,
        //                        Ma = x.Code,
        //                        Ten = x.Name,
        //                        NSinh = x.Birthday,
        //                        GTinh = x.Gender,
        //                        DThoai = x.Phone,
        //                        DChi = x.Address,
        //                        TPho = x.City,
        //                        Huyen = x.District,
        //                        Phuong = x.Wards,
        //                        strModel = (x.H_Model != null ? x.H_Model.Note : ""),
        //                        ModelId = x.ModelId,
        //                        Note = x.Note,
        //                        BienSo = x.LicenseNumber,
        //                        SoMay = x.MachineNumber,
        //                        SoSuon = x.ChassisNumber,
        //                        Km = x.Km,
        //                        NNghiep = (x.H_NgheNghiep != null ? x.H_NgheNghiep.Code : ""),
        //                        JobId = x.JobId
        //                    }).FirstOrDefault();
        //        }
        //        catch (Exception ex)
        //        {
        //            throw ex;
        //        }
        //    }
        //}

        //public List<ModelSelectItem> GetLookUp(string connectString, int loaiNV)
        //{
        //    using (var db = new HMSEntities(connectString))
        //    {
        //        //if (loaiNV != 0)
        //          //  return db.H_SellReceipt.Where(x => !x.IsDeleted && !x.H_LoaiNhanVien.IsDeleted && x.LoaiNVId == loaiNV).Select(x => new ModelSelectItem() { Id = x.Id, Name = x.Code }).ToList();
        //        return db.H_SellReceipt.Where(x => !x.IsDeleted).Select(x => new ModelSelectItem() { Id = x.Id, Name = x.Code }).ToList();
        //    }
        //}

        public ResponseModel Insert(string connectString, SellReceiptModel model)
        {
            var result = new ResponseModel();

            result.IsSuccess = true;
            using (var db = new HMSEntities(connectString))
            {
                if (!CheckExists(model, db))
                {
                    H_SellReceipt sellInfo;
                    double        gt = 0;
                    if (model.ChietKhau == 0)
                    {
                        gt = model.GiaBan;
                    }
                    else
                    {
                        gt = (model.GiaBan - ((model.GiaBan * model.ChietKhau) / 100));
                    }
                    H_KhachHang khObj = null;
                    if (model.Id == 0)
                    {
                        khObj = new H_KhachHang()
                        {
                            Code     = model.Ma,
                            Name     = model.Ten,
                            Gender   = model.GTinh,
                            Birthday = model.NSinh,
                            Phone    = model.DThoai,
                            Address  = model.DChi,
                            City     = model.TPho,
                            District = model.Huyen,
                            Wards    = model.Phuong,
                            JobId    = model.JobId,
                            Note     = model.GhiChu
                        };
                        khObj.H_SellReceipt = new List <H_SellReceipt>();
                    }

                    sellInfo = new H_SellReceipt()
                    {
                        KHId            = model.Id,
                        H_KhachHang     = khObj,
                        SoPhieu         = model.SoPhieu,
                        ModelId         = model.ModelId,
                        LicenseNumber   = model.BienSo,
                        MachineNumber   = model.SoMay,
                        ChassisNumber   = model.SoKhung,
                        NV_TuVan        = model.TuVanId,
                        Price           = model.GiaBan,
                        Discount        = model.ChietKhau,
                        Total           = gt,
                        Note            = model.Note,
                        CreatedDate     = (model.Ngay.Year == 1 ? DateTime.Now : model.Ngay),
                        Index           = model.Index,
                        WorkTypeId      = model.WorkTypeId,
                        GuaranteeNumber = model.SoBaoHanh
                    };
                    db.H_SellReceipt.Add(sellInfo);
                    if (result.IsSuccess)
                    {
                        db.SaveChanges();
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.sms       = "Số phiếu này đã tồn tại trong hệ thống. Vui lòng nhập lại số phiếu khác.";
                }
                return(result);
            }
        }
コード例 #3
0
        public ResponseModel InsertOrUpdate(string connectString, KhachHangModel model)
        {
            var result = new ResponseModel();

            result.IsSuccess = true;
            using (var db = new HMSEntities(connectString))
            {
                if (!CheckExists(model, db))
                {
                    H_KhachHang nv;
                    if (model.Id == 0)
                    {
                        //var last = db.H_KhachHang.OrderByDescending(x => x.Index).FirstOrDefault();
                        //int _index = 1;
                        //if (last != null)
                        //    _index = last.Index + 1;
                        //string code = "KH-" + DateTime.Now.ToString("ddMMyy") + "-" + getNumber(_index);
                        nv = new H_KhachHang()
                        {
                            Code     = model.Ma,
                            Name     = model.Ten,
                            Gender   = model.GTinh,
                            Birthday = model.NSinh,
                            Phone    = model.DThoai,
                            Address  = model.DChi,
                            City     = model.TPho,
                            District = model.Huyen,
                            Wards    = model.Phuong,
                            JobId    = model.JobId,
                            Note     = model.Note
                        };
                        //if (!string.IsNullOrEmpty(model.TaiKhoan) && !string.IsNullOrEmpty(model.MatKhau))
                        //{
                        //    H_Account acc = new H_Account() { AccName = model.TaiKhoan, Password = GlobalFunction.EncryptMD5(model.MatKhau) };
                        //    acc.H_KhachHang = nv;
                        //    nv.H_Account = new List<H_Account>();
                        //    nv.H_Account.Add(acc);
                        //}
                        db.H_KhachHang.Add(nv);
                    }
                    else
                    {
                        nv = db.H_KhachHang.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
                        if (nv != null)
                        {
                            nv.Code     = model.Ma;
                            nv.Name     = model.Ten;
                            nv.Gender   = model.GTinh;
                            nv.Birthday = model.NSinh;
                            nv.Address  = model.DChi;
                            nv.Phone    = model.DThoai;
                            nv.Note     = model.Note;
                            nv.City     = model.TPho;
                            nv.District = model.Huyen;
                            nv.Wards    = model.Phuong;
                            nv.JobId    = model.JobId;
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.sms       = "Khách hàng đã bị xóa hoặc không tồn tại trong hệ thống.!";
                        }
                    }
                    if (result.IsSuccess)
                    {
                        result.Data = nv.Id;
                        db.SaveChanges();
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.sms       = "Mã này đã tồn tại trong hệ thống. Vui lòng chọn lại mã khác.";
                }
                return(result);
            }
        }
コード例 #4
0
        public ResponseModel Insert(string connectString, PhieuModel model)
        {
            var result = new ResponseModel();

            result.IsSuccess = true;
            using (var db = new HMSEntities(connectString))
            {
                if (!CheckExists(model, db))
                {
                    try
                    {
                        H_Receiption receiptInfo;
                        H_KhachHang  khObj = null;
                        receiptInfo = new H_Receiption();
                        if (model.Id == 0)
                        {
                            khObj = new H_KhachHang()
                            {
                                Code     = model.Ma,
                                Name     = model.Ten,
                                Gender   = model.GTinh,
                                Birthday = model.NSinh,
                                Phone    = model.DThoai,
                                Address  = model.DChi,
                                City     = model.TPho,
                                District = model.Huyen,
                                Wards    = model.Phuong,
                                JobId    = model.JobId,
                                Note     = model.Note
                            };
                            khObj.H_Receiption = new List <H_Receiption>();
                        }

                        receiptInfo.KHId          = model.Id;
                        receiptInfo.H_KhachHang   = khObj;
                        receiptInfo.Code          = model.SoPhieu;
                        receiptInfo.ModelId       = model.ModelId;
                        receiptInfo.LicenseNumber = model.BienSo;
                        receiptInfo.MachineNumber = model.SoMay;
                        receiptInfo.ChassisNumber = model.SoKhung;
                        receiptInfo.New_Km        = model.Km;
                        receiptInfo.Required      = model.Yeucau;
                        receiptInfo.CheckResult   = model.Nhanxet;
                        receiptInfo.StatusBefore  = model.Trangthai;
                        receiptInfo.Note          = model.GhiChu;
                        receiptInfo.WorkTypeId    = model.WTypeId;
                        receiptInfo.CreatedDate   = DateTime.Now;
                        receiptInfo.Date          = (model.Ngay.Year == 1 ? DateTime.Now : model.Ngay);
                        receiptInfo.QMSServiceId  = model.QMSServiceId;
                        receiptInfo.Index         = model.Index;
                        if (model.XeId > 0)
                        {
                            receiptInfo.SellReceiptId = model.XeId;
                            var xe = db.H_SellReceipt.FirstOrDefault(x => !x.IsDeleted && x.Id == model.XeId);
                            if (xe != null)
                            {
                                xe.LicenseNumber = model.BienSo;
                            }
                        }

                        db.H_Receiption.Add(receiptInfo);
                        if (result.IsSuccess)
                        {
                            db.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.sms       = "Số phiếu này đã tồn tại trong hệ thống. Vui lòng nhập lại số phiếu khác.";
                }
                return(result);
            }
        }