Пример #1
0
        public JsonResult LuuThongTinXe(ThongTinXeVaKhauHaoModel thongTinXeVaKhauHaoModel)
        {
            var message = new RMessage { ErrorMessage = "Lưu thông tin xe không thành công.", Result = false };
            try
            {
                //if (ModelState.IsValid)
                {
                    //Kiểm tra thông tin đầu vào.
                    var keyHangSanXuatXe = Request.Form["KeyHangSanXuatXe"];
                    var keyLoaiXe = Request.Form["KeyLoaiXe"];
                    var xeKey = Request.Form["XeKey"];
                    var coWifi = Request.Form["hdCoWifi"];
                    var coTivi = Request.Form["hdCoTivi"];
                    var coCameraHanhTrinh = Request.Form["hdCoCameraHanhTrinh"];
                    if (String.IsNullOrEmpty(keyHangSanXuatXe) || String.IsNullOrEmpty(keyLoaiXe)
                        || String.IsNullOrEmpty(thongTinXeVaKhauHaoModel.BangSoXe) || String.IsNullOrEmpty(thongTinXeVaKhauHaoModel.SoSan))
                    {
                        return Json(new { Result = false, Message = Message.DataIsNullOrEmpty, Title = TitleMessageBox.ErrorTitle });
                    }
                    if (String.IsNullOrEmpty(xeKey)) xeKey = "0";
                    thongTinXeVaKhauHaoModel.HangSanXuatXeKey = DefaultValueWhenNull.ConvertShort(keyHangSanXuatXe);
                    thongTinXeVaKhauHaoModel.LoaiXeKey = int.Parse(keyLoaiXe);
                    thongTinXeVaKhauHaoModel.XeKey = int.Parse(xeKey);
                    if (coWifi.ToUpper().Equals("TRUE")) thongTinXeVaKhauHaoModel.CoWifi = true;
                    else thongTinXeVaKhauHaoModel.CoWifi = false;
                    if (coTivi.ToUpper().Equals("TRUE")) thongTinXeVaKhauHaoModel.CoTivi = true;
                    else thongTinXeVaKhauHaoModel.CoTivi = false;
                    if (coCameraHanhTrinh.ToUpper().Equals("TRUE")) thongTinXeVaKhauHaoModel.CoCameraHanhTrinh = true;
                    else thongTinXeVaKhauHaoModel.CoCameraHanhTrinh = false;

                    //Kiểm tra xe có tồn tại trong hệ thống hay chưa?
                    if (thongTinXeVaKhauHaoModel.XeKey <= 0)
                    {
                        var xeTonTai = _db.Xes.FirstOrDefault(r => r.BangSoXe == thongTinXeVaKhauHaoModel.BangSoXe && r.SoSan == thongTinXeVaKhauHaoModel.SoSan);
                        if (xeTonTai != null && xeTonTai.XeKey > 0)
                        {
                            return Json(new { Result = false, Message = "Xe này đã tồn tại trong hệ thống.", Title = TitleMessageBox.ErrorTitle });
                        }
                    }

                    if (thongTinXeVaKhauHaoModel.NgayBatDauKhauHao < thongTinXeVaKhauHaoModel.NgayCapPhep)
                    {
                        return Json(new { Result = false, Message = "Ngày bắt đầu khấu hao phải lớn hơn ngày cấp phép.", Title = TitleMessageBox.ErrorTitle });
                    }

                    if (thongTinXeVaKhauHaoModel.NgayBatDauKhauHao > thongTinXeVaKhauHaoModel.NgayKetThucKhauHao)
                    {
                        return Json(new { Result = false, Message = "Ngày kết thúc khấu hao phải lớn hơn ngày bắt đầu khấu hao.", Title = TitleMessageBox.ErrorTitle });
                    }

                    new ThongTinXeVaKhauHaoBll().LuuThongTinXeVaKhauHao(thongTinXeVaKhauHaoModel);
                    return Json(new { Result = true, Message = Message.SuccessDataAction, Title = TitleMessageBox.CompleteTitle });
                }
                //else { return Json(new { Result = false, Message = ".", Title = TitleMessageBox.ErrorTitle }); }
            }
            catch (Exception) { return Json(new { Result = false, Title = TitleMessageBox.FailureTitle, Message = Message.FailureDataAction }, JsonRequestBehavior.AllowGet); }
        }
Пример #2
0
        }//EndFunction

        public bool LuuThongTinXeVaKhauHao(ThongTinXeVaKhauHaoModel thongTinXeVaKhauHaoModel)
        {
            using (var dbContextTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    //Kiểm tra thêm mới hay chỉnh sửa.
                    var row = _db.Xes.FirstOrDefault(r => r.XeKey == thongTinXeVaKhauHaoModel.XeKey);
                    if (row == null)
                    {
                        row = new Models.Xe();
                        row.XeAlternateKey = thongTinXeVaKhauHaoModel.XeKey.ToString();
                        _db.Xes.Add(row);
                    }
                    row.BangSoXe = thongTinXeVaKhauHaoModel.BangSoXe;
                    row.CoCameraHanhTrinh = thongTinXeVaKhauHaoModel.CoCameraHanhTrinh;
                    row.CoTivi = thongTinXeVaKhauHaoModel.CoTivi;
                    row.CoWifi = thongTinXeVaKhauHaoModel.CoWifi;
                    row.GhiChu = thongTinXeVaKhauHaoModel.GhiChuThongTinXe;
                    row.GiaMua = thongTinXeVaKhauHaoModel.GiaMua;
                    row.LoaiXeKey = thongTinXeVaKhauHaoModel.LoaiXeKey;
                    row.Mau = thongTinXeVaKhauHaoModel.Mau;
                    row.NgayCapPhep = thongTinXeVaKhauHaoModel.NgayCapPhep;
                    row.SoSan = thongTinXeVaKhauHaoModel.SoSan;
                    _db.SaveChanges();

                    var dongMoiThem = _db.Xes.FirstOrDefault(r => r.BangSoXe == thongTinXeVaKhauHaoModel.BangSoXe && r.SoSan == thongTinXeVaKhauHaoModel.SoSan);
                    if (dongMoiThem != null && dongMoiThem.XeKey > 0)
                    {
                        var dongKhauHao = _db.KhauHaos.FirstOrDefault(r => r.XeKey == dongMoiThem.XeKey);
                        if (dongKhauHao == null)
                        {
                            dongKhauHao = new Models.KhauHao();
                            dongKhauHao.KhauHaoAlternateKey = dongKhauHao.KhauHaoKey.ToString();
                            _db.KhauHaos.Add(dongKhauHao);
                        }
                        dongKhauHao.GhiChu = thongTinXeVaKhauHaoModel.GhiChuKhauHaoXe;
                        dongKhauHao.NgayBatDauKhauHao = thongTinXeVaKhauHaoModel.NgayBatDauKhauHao;
                        dongKhauHao.NgayKetThucKhauHao = thongTinXeVaKhauHaoModel.NgayKetThucKhauHao;
                        dongKhauHao.SoThangKhauHao = thongTinXeVaKhauHaoModel.SoThangKhauHao;
                        dongKhauHao.TienKhauHaoHangThang = thongTinXeVaKhauHaoModel.TienKhauHaoHangThang;
                        dongKhauHao.TongTienKhauHao = thongTinXeVaKhauHaoModel.TongTienKhauHao;
                        dongKhauHao.XeKey = dongMoiThem.XeKey;
                        _db.SaveChanges();
                    }
                    dbContextTransaction.Commit();
                    return true;
                }
                catch(Exception ex)
                {
                    dbContextTransaction.Rollback();
                    throw (ex);
                }
            }
        }//EndFunction
Пример #3
0
 public ActionResult NhapThongTinXe()
 {
     _ThongTinXeVaKhauHaoModel = new ThongTinXeVaKhauHaoModel();
     _ThongTinXeVaKhauHaoModel.XeKey = 0;
     _ThongTinXeVaKhauHaoModel.BangSoXe = string.Empty;
     _ThongTinXeVaKhauHaoModel.CoCameraHanhTrinh = true;
     _ThongTinXeVaKhauHaoModel.CoTivi = true;
     _ThongTinXeVaKhauHaoModel.CoWifi = true;
     _ThongTinXeVaKhauHaoModel.GhiChuKhauHaoXe = string.Empty;
     _ThongTinXeVaKhauHaoModel.GhiChuThongTinXe = string.Empty;
     _ThongTinXeVaKhauHaoModel.GiaMua = 0;
     _ThongTinXeVaKhauHaoModel.LoaiXeKey = 0;
     _ThongTinXeVaKhauHaoModel.HangSanXuatXeKey = 0;
     _ThongTinXeVaKhauHaoModel.Mau = string.Empty;
     _ThongTinXeVaKhauHaoModel.NgayBatDauKhauHao = DateTime.Today;
     _ThongTinXeVaKhauHaoModel.NgayCapPhep = DateTime.Today;
     _ThongTinXeVaKhauHaoModel.NgayKetThucKhauHao = DateTime.Today.AddMonths(12);
     _ThongTinXeVaKhauHaoModel.SoSan = string.Empty;
     _ThongTinXeVaKhauHaoModel.SoThangKhauHao = 12;
     _ThongTinXeVaKhauHaoModel.TienKhauHaoHangThang = 0;
     _ThongTinXeVaKhauHaoModel.TongTienKhauHao = 0;
     return View(_ThongTinXeVaKhauHaoModel);
 }