public void ActionIndex(ModDT_Ky_DaiLy_DonHangModel model)
        {
            // sap xep tu dong
            string orderBy = AutoSort(model.Sort);

            if (model.ModDtKyId <= 0)
            {
                ModDT_KyEntity objModDT_KyEntity = ModDT_KyService.Instance.CreateQuery().OrderByDesc(o => o.ID).Take(1).ToSingle();
                if (objModDT_KyEntity != null)
                {
                    model.ModDtKyId = objModDT_KyEntity.ID;
                    model.DaChotKy  = objModDT_KyEntity.Activity ? (int)EnumValue.Activity.FALSE : (int)EnumValue.Activity.TRUE;
                }
            }

            // tao danh sach
            var dbQuery = ModDT_Ky_DaiLy_DonHangService.Instance.CreateQuery()
                          .Where(o => o.ModDtKyId == (model.ModDtKyId))
                          .Where(model.ModDTKyDaiLyId > 0, o => o.ModDTKyDaiLyId == (model.ModDTKyDaiLyId))
                          .Where(!string.IsNullOrEmpty(model.SearchText), o => o.Name.Contains(model.SearchText))
                          .Take(model.PageSize)
                          .OrderBy(orderBy)
                          .Skip(model.PageIndex * model.PageSize);

            ViewBag.Data      = dbQuery.ToList();
            model.TotalRecord = dbQuery.TotalRecord;
            ViewBag.Model     = model;
        }
Esempio n. 2
0
        public void ActionAdd(ModDT_KyModel model)
        {
            if (model.RecordID > 0)
            {
                item = ModDT_KyService.Instance.GetByID(model.RecordID);

                // khoi tao gia tri mac dinh khi update
                model.DaChotKy = item.Activity ? (int)EnumValue.Activity.FALSE : (int)EnumValue.Activity.TRUE;
            }
            else
            {
                // Kiểm tra xem có kỳ doanh thu nào đang tồn tại không. Nếu có thì không cho phép thêm
                var objCheck = ModDT_KyService.Instance.CreateQuery().Where(o => o.Activity == true).ToSingle();
                if (objCheck != null)
                {
                    CPViewPage.SetMessage("Tồn tại một kỳ doanh thu đang hoạt động. Yêu cầu chốt kỳ doanh thu để có thể thêm mới");
                    CPViewPage.Response.Redirect(CPViewPage.Request.RawUrl.Replace("Add.aspx", "Index.aspx"));
                    return;
                }

                item = new ModDT_KyEntity();

                // khoi tao gia tri mac dinh khi insert
                item.Activity   = CPViewPage.UserPermissions.Approve;
                item.CreateDate = DateTime.Now;
                model.DaChotKy  = (int)EnumValue.Activity.FALSE;
            }

            ViewBag.Data  = item;
            ViewBag.Model = model;
        }
Esempio n. 3
0
        public void ActionAdd(ModDT_Ky_DaiLyModel model)
        {
            if (model.RecordID > 0)
            {
                item = ModDT_Ky_DaiLyService.Instance.GetByID(model.RecordID);

                List <ModDT_Ky_DaiLyEntity> lstListData = new List <ModDT_Ky_DaiLyEntity>();

                // Lấy danh sách các đại lý con bên trong đại lý này
                var dbQuery = ModDT_Ky_DaiLyService.Instance.CreateQuery()
                              .Where(o => o.ModDtKyId == item.ModDtKyId &&
                                     (o.ModProductAgentId == item.ModProductAgentId || o.ModProductAgentParentId == item.ModProductAgentId));

                List <ModDT_Ky_DaiLyEntity> lstData01 = dbQuery.ToList();
                if (lstData01 == null || lstData01.Count <= 0)
                {
                    ViewBag.ListData = lstListData;
                }
                else
                {
                    var dbQueryAllKy = ModDT_Ky_DaiLyService.Instance.CreateQuery()
                                       .Where(o => o.ModDtKyId == item.ModDtKyId);

                    List <ModDT_Ky_DaiLyEntity> lstData02_all = dbQueryAllKy.ToList();

                    foreach (var itemCheck in lstData01)
                    {
                        // Thêm vào danh sách
                        lstListData.Add(itemCheck);

                        // Là Item hiện tại
                        if (itemCheck.ID == item.ID)
                        {
                            continue;
                        }

                        // Duyệt tìm những phần tử con nếu có
                        FindDataChild(lstData02_all, itemCheck, ref lstListData);
                    }
                }

                // khoi tao gia tri mac dinh khi update
                ViewBag.ListData = lstListData;

                // Lấy thông tin kỳ
                ModDT_KyEntity objModDT_KyEntity = ModDT_KyService.Instance.GetByID(item.ModDtKyId);
                model.DaChotKy = objModDT_KyEntity.Activity ? (int)EnumValue.Activity.FALSE : (int)EnumValue.Activity.TRUE;
            }
            else
            {
                item = new ModDT_Ky_DaiLyEntity();

                // khoi tao gia tri mac dinh khi insert
                item.Activity    = CPViewPage.UserPermissions.Approve;
                ViewBag.ListData = new List <ModDT_Ky_DaiLyEntity>();
            }

            ViewBag.Data  = item;
            ViewBag.Model = model;
        }
        public void ActionAddDonHang(ModDT_Ky_DaiLy_DonHangModel model)
        {
            ModDT_Ky_DaiLyEntity objModDT_Ky_DaiLyEntity = ModDT_Ky_DaiLyService.Instance.GetByID(model.ModDTKyDaiLyId);
            ModDT_KyEntity       objModDT_KyEntity       = ModDT_KyService.Instance.GetByID(objModDT_Ky_DaiLyEntity.ModDtKyId);

            // Lưu lại kỳ
            model.ModDtKyId = objModDT_Ky_DaiLyEntity.ModDtKyId;

            if (model.RecordID > 0)
            {
                item = ModDT_Ky_DaiLy_DonHangService.Instance.GetByID(model.RecordID);
            }
            else
            {
                item = new ModDT_Ky_DaiLy_DonHangEntity();

                // khoi tao gia tri mac dinh khi insert
                item.Activity   = CPViewPage.UserPermissions.Approve;
                item.CreateDate = DateTime.Now;
                item.NgayTao    = DateTime.Now;
                item.Code       = objModDT_KyEntity.Code + "." + objModDT_Ky_DaiLyEntity.Code + "." + DateTime.Now.ToString("ddMMyyy.HHmmss");
                item.Name       = item.Code;
            }
            //List<ModDT_Ky_DaiLy_DonHangEntity> lstModDT_Ky_DaiLy_DonHang = ModDT_Ky_DaiLy_DonHangService.Instance.CreateQuery().Where(o=>o.ModDTKyDaiLyId== model.ModDTKyDaiLyId).ToList_Cache();
            ViewBag.KyDaiLy = objModDT_Ky_DaiLyEntity;
            ViewBag.Ky      = objModDT_KyEntity;
            // Đã chốt kỳ hay chưa
            model.DaChotKy = objModDT_KyEntity.Activity ? (int)EnumValue.Activity.FALSE : (int)EnumValue.Activity.TRUE;

            model.lstModProduct_InfoEntity = new List <ModProduct_InfoEntity>();
            model.lstModProduct_InfoEntity.Add(new ModProduct_InfoEntity());
            model.lstModProduct_InfoEntity.Add(new ModProduct_InfoEntity());

            string strDanhSachSanPhanTrongDonHang = string.Empty;

            if (model.RecordID > 0)
            {
                strDanhSachSanPhanTrongDonHang = FormDkKyDaiLyDonHang_ReloadData(model.RecordID, model);
            }

            ViewBag.DanhSachSanPhanTrongDon = strDanhSachSanPhanTrongDonHang;
            ViewBag.Data  = item;
            ViewBag.Model = model;
        }
        public void ActionIndex(ModDT_Ky_DaiLy_DonHang_SanPhamModel model)
        {
            // sap xep tu dong
            string orderBy = AutoSort(model.Sort);

            if (model.ModDtKyId <= 0)
            {
                ModDT_KyEntity objModDT_KyEntity = ModDT_KyService.Instance.CreateQuery().OrderByDesc(o => o.ID).Take(1).ToSingle();
                if (objModDT_KyEntity != null)
                {
                    model.ModDtKyId = objModDT_KyEntity.ID;
                    model.DaChotKy  = objModDT_KyEntity.Activity ? (int)EnumValue.Activity.FALSE : (int)EnumValue.Activity.TRUE;
                }
            }

            // tao danh sach
            var dbQuery = ModDT_Ky_DaiLy_DonHang_SanPhamService.Instance.CreateQuery()
                          .Where(o => o.ModDtKyId == (model.ModDtKyId))
                          .Where(model.ModDTKyDaiLyId > 0, o => o.ModDTKyDaiLyId == (model.ModDTKyDaiLyId))
                          .Take(model.PageSize)
                          .OrderBy(orderBy)
                          .Skip(model.PageIndex * model.PageSize);


            var dbExec   = Lib.LinqToSql.DbExecute.Create(true);
            var DataExec = (from o in dbExec.Mod_DT_Ky_DaiLy_DonHang_SanPhams
                            where o.ModDtKyId == model.ModDtKyId && (model.ModDTKyDaiLyId == 0 || o.ModDTKyDaiLyId == model.ModDTKyDaiLyId)
                            orderby o.ID descending
                            select o)
                           .Take(model.PageSize)
                           .Skip(model.PageIndex * model.PageSize).ToList();

            ViewBag.Data      = dbQuery.ToList();
            ViewBag.DataLazy  = DataExec;
            model.TotalRecord = dbQuery.TotalRecord;
            ViewBag.Model     = model;
        }
        public void ActionAdd(ModDT_Ky_DaiLy_DonHangModel model)
        {
            ModDT_KyEntity       objModDT_KyEntity       = ModDT_KyService.Instance.GetByID(model.ModDtKyId);
            ModDT_Ky_DaiLyEntity objModDT_Ky_DaiLyEntity = new ModDT_Ky_DaiLyEntity();

            if (model.RecordID > 0)
            {
                item = ModDT_Ky_DaiLy_DonHangService.Instance.GetByID(model.RecordID);
                if (model.ModDTKyDaiLyId > 0)
                {
                    model.ModDTKyDaiLyId = item.ModDTKyDaiLyId;
                }
                if (model.ModDtKyId > 0)
                {
                    model.ModDtKyId = item.ModDtKyId;
                }
                if (model.ModDTKyDaiLyId > 0)
                {
                    objModDT_Ky_DaiLyEntity = ModDT_Ky_DaiLyService.Instance.GetByID(model.ModDTKyDaiLyId);
                }
            }
            else
            {
                // Kiểm tra xem kỳ còn hoạt động ko hay chốt kỳ rồi thì ko cho thêm
                if (objModDT_KyEntity.Activity == false)
                {
                    CPViewPage.SetMessage("Kỳ doanh thu bạn chọn đã được đóng, không thể thêm mới đơn hàng.");
                    CPViewPage.Response.Redirect(CPViewPage.Request.RawUrl.Replace("Add.aspx", "Index.aspx"));
                    return;
                }

                item = new ModDT_Ky_DaiLy_DonHangEntity();
                if (model.ModDTKyDaiLyId > 0)
                {
                    objModDT_Ky_DaiLyEntity = ModDT_Ky_DaiLyService.Instance.GetByID(model.ModDTKyDaiLyId);
                }

                // khoi tao gia tri mac dinh khi insert
                item.Activity   = CPViewPage.UserPermissions.Approve;
                item.CreateDate = DateTime.Now;
                item.NgayTao    = DateTime.Now;
                item.Code       = objModDT_KyEntity.Code + "." + objModDT_Ky_DaiLyEntity.Code + "." + DateTime.Now.ToString("ddMMyyy.HHmmss");
                item.Name       = item.Code;
            }

            //List<ModDT_Ky_DaiLy_DonHangEntity> lstModDT_Ky_DaiLy_DonHang = ModDT_Ky_DaiLy_DonHangService.Instance.CreateQuery().Where(o=>o.ModDTKyDaiLyId== model.ModDTKyDaiLyId).ToList_Cache();
            ViewBag.KyDaiLy = objModDT_Ky_DaiLyEntity;
            ViewBag.Ky      = objModDT_KyEntity;
            // Đã chốt kỳ hay chưa
            model.DaChotKy = objModDT_KyEntity.Activity ? (int)EnumValue.Activity.FALSE : (int)EnumValue.Activity.TRUE;

            model.lstModProduct_InfoEntity = new List <ModProduct_InfoEntity>();
            model.lstModProduct_InfoEntity.Add(new ModProduct_InfoEntity());
            model.lstModProduct_InfoEntity.Add(new ModProduct_InfoEntity());

            string strDanhSachSanPhanTrongDonHang = string.Empty;

            if (model.RecordID > 0)
            {
                strDanhSachSanPhanTrongDonHang = FormDkKyDaiLyDonHang_ReloadData(model.RecordID, model);
            }

            ViewBag.DanhSachSanPhanTrongDon = strDanhSachSanPhanTrongDonHang;
            ViewBag.Data  = item;
            ViewBag.Model = model;
        }