Example #1
0
 // This method is called when the grid requests data
 public JsonResult CustomerOrdersSearchGridDataRequested()
 {
     //// Get both the grid Model and the data Model
     var gridModel = new SkladJqGridModel();
     var datacontextModel = new SkladDataContext();
     // customize the default grid model with our custom settings
     CustomerOrdersSetupGrid(gridModel.DocumentGrid);
     return GetDocumentList(gridModel, datacontextModel, EntityEnum.DocumentTypeEnum.CustomerOrders);
 }
Example #2
0
        // This method is called when the grid requests data
        public JsonResult CancellationSearchGridDataRequested()
        {
            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();
            // customize the default grid model with our custom settings
            CancellationSetupGrid(gridModel.DocumentGrid);

            return gridModel.DocumentGrid.DataBind(datacontextModel.Documents.Where(x =>
                x.DocumentTypeId == (int)EntityEnum.DocumentTypeEnum.Cancellation));
        }
Example #3
0
        public ActionResult Posting()
        {
            ViewBag.Title = "Оприходования";
            // Get the model (setup) of the grid defined in the /Models folder.
            var gridModel = new SkladJqGridModel();
            var grid = gridModel.DocumentGrid;

            //// NOTE: you need to call this method in the action that fetches the data as well,
            //// so that the models match
            PostingSetupGrid(grid);

            // Pass the custmomized grid model to the View
            return View(gridModel);
        }
Example #4
0
        public ActionResult CustomerOrders()
        {
            ViewBag.Title = "Заказы покупателя";
            // Get the model (setup) of the grid defined in the /Models folder.
            var gridModel = new SkladJqGridModel();
            var grid = gridModel.DocumentGrid;

            //// NOTE: you need to call this method in the action that fetches the data as well,
            //// so that the models match
            CustomerOrdersSetupGrid(grid);
            /*
            public int? ContractId { get; set; }
            public int? EmployeeId { get; set; }
             */

            // Pass the custmomized grid model to the View
            return View(gridModel);
        }
Example #5
0
        public ActionResult ExportToExcelRefundsByDay(DateTime? refundsReportDate)
        {
            if(!refundsReportDate.HasValue)
                refundsReportDate = DateTime.Now;

            var gridModel = new SkladJqGridModel();
            var skladModel = new SkladDataContext();
            var grid = gridModel.ProductLineGrid;

            // Get the last grid state the we saved before in Session in the DataRequested action
            JQGridState gridState = Session["refundsProductLinesGridState"] as JQGridState;

            // Need to set grid options again
            SetUpRefundsProductLineColumns(grid);
            SetUpRefundsProductLineGroupingGrandTotal(grid);

            //if (String.IsNullOrEmpty(exportType))
            //    exportType = "1";
            // refundsReportDate
            //switch (exportType)
            //{
            //    case "1":

               // grid.ExportToExcel(GetRefundsProductLines(skladModel, refundsReportDate.Value), "refundsByDateGrid.xls", gridState);
                    //break;
            //    case "2":
            //        grid.ExportSettings.ExportDataRange = ExportDataRange.Filtered;
            //        grid.ExportToExcel(northWindModel.Orders, "grid.xls", gridState);
            //        break;
            //    case "3":
            //        grid.ExportSettings.ExportDataRange = ExportDataRange.FilteredAndPaged;
            //        grid.ExportToExcel(northWindModel.Orders, "grid.xls", gridState);
            //        break;
            //}

            return View();
        }
Example #6
0
        public ActionResult ContractorEditRows(Contractor editedItem)
        {
            // Get the grid and database models
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();

            // If we are in "Edit" mode
            if (gridModel.ContractorGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                PrepareContractorData(editedItem);

                string validationMessage = ValidateContractorData(datacontextModel.Contractors, editedItem, false);
                if (!String.IsNullOrEmpty(validationMessage))
                    return gridModel.ContractorGrid.ShowEditValidationMessage(validationMessage);

                // Get the data from and find the item corresponding to the edited row
                Contractor item = (from x in datacontextModel.Contractors
                               where x.ContractorId == editedItem.ContractorId
                               select x).First<Contractor>();

                // update the item information
                UpdateContractor(item, editedItem);

                datacontextModel.SaveChanges();
                logger.InfoFormat("контрагент изменён {0}", item.Code);

            }

            if (gridModel.ContractorGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow)
            {
                PrepareContractorData(editedItem);

                string validationMessage = ValidateContractorData(datacontextModel.Contractors, editedItem, true);
                if (!String.IsNullOrEmpty(validationMessage))
                    return gridModel.ContractorGrid.ShowEditValidationMessage(validationMessage);

                // since we are adding a new item, create a new istance
                Contractor item = new Contractor() { IsArchived = false, CreatedAt = DateTime.Now };
                // set the new item information
                UpdateContractor(item, editedItem);

                datacontextModel.Contractors.Add(item);
                datacontextModel.SaveChanges();
                logger.InfoFormat("контрагент добавлен {0}", item.Code);

            }
            if (gridModel.ContractorGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                Contractor item = (from x in datacontextModel.Contractors
                                   where x.ContractorId == editedItem.ContractorId
                               select x)
                               .First<Contractor>();

                // delete the record
                datacontextModel.Contractors.Remove(item);
                datacontextModel.SaveChanges();
                logger.InfoFormat("контрагент удалён {0}", item.Code);
            }

            return RedirectToAction("Contractor", "Reference");
        }
Example #7
0
        // This method is called when the grid requests data
        public JsonResult ContractorSearchGridDataRequested()
        {
            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();
            // customize the default grid model with our custom settings
            ContractorSetupGrid(gridModel.ContractorGrid);

            // return the result of the DataBind method, passing the datasource as a parameter
            // jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc
            return gridModel.ContractorGrid.DataBind(datacontextModel.Contractors);
        }
Example #8
0
        public ActionResult ContactList(int contractorId)
        {
            if (contractorId <= 0)
            {
                // log error
                return null;
            }

            ContactListModel list = new ContactListModel();
            var gridModel = new SkladJqGridModel();
            var grid = gridModel.MyEmployeesGrid;
            var datacontextModel = new SkladDataContext();

            var company = datacontextModel.Contractors
                .Where(x => x.ContractorId == contractorId).Include(x => x.Responsible).First();
            list.Company = company;

            ContactListSetupGrid(grid);

            list.Grid = grid;

            return View(list);
        }
Example #9
0
        public ActionResult LegalEntity()
        {
            ViewBag.Title = "Юр. лица";
            // Get the model (setup) of the grid defined in the /Models folder.
            var gridModel = new SkladJqGridModel();
            var grid = gridModel.LegalEntityGrid;

            // NOTE: you need to call this method in the action that fetches the data as well,
            // so that the models match
            LegalEntitySetupGrid(grid);

            // Pass the custmomized grid model to the View
            return View(gridModel);
        }
Example #10
0
        public JsonResult RefundsProductSearchGridDataRequested(DateTime? refundsReportDate)
        {
            if (!refundsReportDate.HasValue)
                refundsReportDate = DateTime.Now;

            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();
            SetUpRefundsProductLineColumns(gridModel.ProductLineGrid);
            SetUpRefundsProductLineGroupingGrandTotal(gridModel.ProductLineGrid);
            // customize the default grid model with our custom settings
            //JQGridState gridState = gridModel.ProductLineGrid.GetState();

            // Need this to enable ExportToExcelRefundsByDay
            // Session["refundsProductLinesGridState"] = gridState;
            int contractorId = 0;
            if (Request.Params["contractorId"] != null)
                Int32.TryParse(Request.Params["contractorId"].ToString(), out contractorId);

            int managerId = 0;
            if (Request.Params["managerId"] != null)
                Int32.TryParse(Request.Params["managerId"].ToString(), out managerId);

            return gridModel.ProductLineGrid.DataBind(GetRefundsProductLines(datacontextModel, refundsReportDate.Value, contractorId, managerId));
        }
Example #11
0
        private JsonResult GetDocumentList(SkladJqGridModel gridModel, 
            SkladDataContext datacontextModel, EntityEnum.DocumentTypeEnum docType)
        {
            string contractorIdStr = Request.QueryString["ContractorId"];
            if (!String.IsNullOrEmpty(contractorIdStr))
            {
                var contractor = datacontextModel.Contractors.Where(x =>
                    x.Code.ToLower() == contractorIdStr.ToLower()).FirstOrDefault();
                if (contractor != null)
                {
                    // ContractorName
                    return gridModel.DocumentGrid.DataBind(datacontextModel
                        .Documents.Include("Contractor").Where(x => x.ContractorId == contractor.ContractorId &&
                           x.DocumentTypeId == (int)docType));
                }
            }

            return gridModel.DocumentGrid.DataBind(datacontextModel.Documents.Include("Contractor").Where(x =>
                x.DocumentTypeId == (int)docType));
        }
Example #12
0
        public ActionResult WarehouseEditRows(Warehouse editedItem)
        {
            // Get the grid and database models
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();

            // If we are in "Edit" mode
            if (gridModel.WarehouseGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                // Get the data from and find the item corresponding to the edited row
                Warehouse item = (from x in datacontextModel.Warehouses
                                    where x.WarehouseId == editedItem.WarehouseId
                                    select x).First<Warehouse>();

                // update the item information
                UpdateWarehouse(item, editedItem);

                datacontextModel.SaveChanges();
            }

            if (gridModel.WarehouseGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow)
            {
                // since we are adding a new item, create a new istance
                Warehouse item = new Warehouse();
                // set the new item information
                UpdateWarehouse(item, editedItem);

                datacontextModel.Warehouses.Add(item);
                datacontextModel.SaveChanges();
            }
            if (gridModel.WarehouseGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                Warehouse item = (from x in datacontextModel.Warehouses
                                    where x.WarehouseId == editedItem.WarehouseId
                                    select x)
                               .First<Warehouse>();

                // delete the record
                datacontextModel.Warehouses.Remove(item);
                datacontextModel.SaveChanges();
            }

            return RedirectToAction("Warehouse", "MyCompany");
        }
Example #13
0
        public ActionResult Contractor()
        {
            ViewBag.Title = "Контрагент";
            // Get the model (setup) of the grid defined in the /Models folder.
            var gridModel = new SkladJqGridModel();
            var grid = gridModel.ContractorGrid;

            // NOTE: you need to call this method in the action that fetches the data as well,
            // so that the models match
            ContractorSetupGrid(grid);

            // Pass the custmomized grid model to the View
            return View(gridModel);
        }
Example #14
0
        // parentRowID is automatically passed from the parent grid to the child grid. Note: parentRowID is case sensitive
        public JsonResult TwoLevel_ProductsDataRequested(int parentRowID)
        {
            int contractorId = 0;
            Int32.TryParse(Request.QueryString["contractorId"], out contractorId);
            if (contractorId <= 0)
                return null;

            var gridModel = new SkladDataContext();
            var model = new SkladJqGridModel();

            ContractorDetailsSetupGrid(model);

            var contractor = gridModel.Contractors.Where(x => x.ContractorId == contractorId).FirstOrDefault();

            if (contractor == null)
                return null;

            IQueryable<ProductLine> products = GetContractorDocuments(gridModel, parentRowID, contractor);
            //if (contractor.ContractorTypeId == (int)EntityEnum.ContractorTypeEnum.Factory)
            //{
            //    products = from o in gridModel.ProductLines
            //                   where o.DocumentId == parentRowID && o.SupplierId == contractorId
            //                   select o;
            //}
            //else
            //{
            //    products = from o in gridModel.ProductLines
            //               where o.DocumentId == parentRowID
            //               select o;
            //}

            return model.ProductLineGrid.DataBind(products);
        }
Example #15
0
        public ActionResult Warehouse()
        {
            ViewBag.Title = "Склады";
            // Get the model (setup) of the grid defined in the /Models folder.
            var gridModel = new SkladJqGridModel();
            var grid = gridModel.WarehouseGrid;

            // NOTE: you need to call this method in the action that fetches the data as well,
            // so that the models match
            WarehouseSetupGrid(grid);

            // Pass the custmomized grid model to the View
            return View(gridModel);
        }
Example #16
0
        public JsonResult TwoLevel_DocumentsDataRequested()
        {
            int contractorId = 0;
            Int32.TryParse(Request.QueryString["contractorId"], out contractorId);
            if (contractorId <= 0)
                return null;

            DateTime periodFrom = SqlDateTime.MinValue.Value, periodTo = SqlDateTime.MaxValue.Value;

            DateTime.TryParse(Request.QueryString["periodFrom"], out periodFrom);
            DateTime.TryParse(Request.QueryString["periodTo"], out periodTo);

            // Set default values
            if (periodTo < SqlDateTime.MaxValue.Value && periodTo > SqlDateTime.MinValue.Value)
                periodTo = periodTo.AddMonths(1);
            else
                periodTo = SqlDateTime.MaxValue.Value;

            if (!(periodFrom < SqlDateTime.MaxValue.Value && periodFrom > SqlDateTime.MinValue.Value))
                periodFrom = SqlDateTime.MinValue.Value;

            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new SkladDataContext();
            var model = new SkladJqGridModel();
            ContractorDetailsSetupGrid(model);

            // return the result of the DataBind method, passing the datasource as a parameter
            // jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc

            var contractor = gridModel.Contractors.Where(x => x.ContractorId == contractorId).FirstOrDefault();

            if (contractor == null)
                return null;

            IQueryable<Document> documentSet = GetContractorDocuments(gridModel, contractor, periodFrom, periodTo);
            //if (contractor.ContractorTypeId == (int)EntityEnum.ContractorTypeEnum.Factory) {

            //    var documentIds = gridModel.ProductLines.Where(x => x.Document.IsCommitted &&

            //        x.SupplierId == contractor.ContractorId)
            //        .GroupBy(x => x.DocumentId).Select(k => k.Key).ToArray();
            //    documentSet = gridModel.Documents.Where(x => documentIds.Contains(x.DocumentId) && x.CreatedOf >= periodFrom && x.CreatedOf <= periodTo);
            //}
            //else
            //    documentSet = gridModel.Documents.Where(x => x.ContractorId == contractorId);

            return model.DocumentGrid.DataBind(documentSet);
        }
Example #17
0
        public ActionResult MyEmployeesEditRows(UserProfile editedItem)
        {
            // Get the grid and database models
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();

            // If we are in "Edit" mode
            if (gridModel.MyEmployeesGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                if (editedItem.UserName == "admin" && !User.IsInRole("admin"))
                    return gridModel.MyEmployeesGrid.ShowEditValidationMessage("Эту запись изменить нельзя");

                PrepareUsersData(editedItem);

                string validationMessage = ValidateUsersData(datacontextModel.UserProfiles, editedItem, false);
                if (!String.IsNullOrEmpty(validationMessage))
                    return gridModel.MyEmployeesGrid.ShowEditValidationMessage(validationMessage);

                // Get the data from and find the item corresponding to the edited row
                UserProfile item = (from x in datacontextModel.UserProfiles
                                   where x.UserId == editedItem.UserId
                                   select x).First<UserProfile>();
                if (editedItem.UserId == item.UserId)
                {
                    // update the item information
                    UpdateMyEmployees(item, editedItem);

                    datacontextModel.SaveChanges();
                    UpdateUserRole(datacontextModel, item);
                    logger.InfoFormat("изменён контакт {0}", editedItem.DisplayName);

                    // Change password if need it
                    if (!String.IsNullOrEmpty(editedItem.NewPassword))
                    {
                        string resetToken = WebSecurity.GeneratePasswordResetToken(editedItem.UserName);
                        WebSecurity.ResetPassword(resetToken, editedItem.NewPassword);
                        logger.InfoFormat("изменён пароль контакта {0}", editedItem.DisplayName);
                    }
                }
            }

            if (gridModel.MyEmployeesGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow)
            {
                PrepareUsersData(editedItem);
                string validationMessage = ValidateUsersData(datacontextModel.UserProfiles, editedItem, true);
                if (!String.IsNullOrEmpty(validationMessage))
                    return gridModel.MyEmployeesGrid.ShowEditValidationMessage(validationMessage);

                    // since we are adding a new item, create a new istance
                    string newPassword = editedItem.NewPassword;
                    if (String.IsNullOrEmpty(newPassword))
                        editedItem.NewPassword = System.Web.Security.Membership.GeneratePassword(5, 1);

                    // Create membership account
                    WebSecurity.CreateUserAndAccount(editedItem.UserName, editedItem.NewPassword);
                    UserProfile item = (from x in datacontextModel.UserProfiles
                                        where x.UserName == editedItem.UserName
                                        select x).First<UserProfile>();
                    // set the new item information
                    UpdateMyEmployees(item, editedItem);

                    datacontextModel.SaveChanges();
                    UpdateUserRole(datacontextModel, item);
                    logger.InfoFormat("добавлен контакт {0} с паролем - {1}", editedItem.DisplayName, editedItem.NewPassword);
            }
            if (gridModel.MyEmployeesGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                UserProfile item = (from x in datacontextModel.UserProfiles
                                    where x.UserId == editedItem.UserId
                                    select x)
                               .First<UserProfile>();

                if (item.ContactTypeId == 1)
                    return gridModel.MyEmployeesGrid.ShowEditValidationMessage("Невозможно удалить сотрудника");

                // delete the record
                Membership.DeleteUser(item.UserName);
                logger.InfoFormat("удален контакт {0}", editedItem.DisplayName);
            }

            return RedirectToAction("MyEmployees", "MyCompany");
        }
Example #18
0
        public ActionResult LegalEntityEditRows(LegalEntity editedItem)
        {
            // Get the grid and database models
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();

            // If we are in "Edit" mode
            if (gridModel.LegalEntityGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                // Get the data from and find the item corresponding to the edited row
                LegalEntity item = (from x in datacontextModel.LegalEntities
                                    where x.LegalEntityId == editedItem.LegalEntityId
                               select x).First<LegalEntity>();

                // update the Order information
                UpdateLegalEntity(item, editedItem);

                datacontextModel.SaveChanges();
            }

            if (gridModel.LegalEntityGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow)
            {
                // since we are adding a new item, create a new istance
                LegalEntity item = new LegalEntity();
                // set the new item information
                UpdateLegalEntity(item, editedItem);

                datacontextModel.LegalEntities.Add(item);
                datacontextModel.SaveChanges();
            }
            if (gridModel.LegalEntityGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                LegalEntity item = (from x in datacontextModel.LegalEntities
                                    where x.LegalEntityId == editedItem.LegalEntityId
                               select x)
                               .First<LegalEntity>();

                // delete the record
                datacontextModel.LegalEntities.Remove(item);
                datacontextModel.SaveChanges();
            }

            return RedirectToAction("LegalEntity", "MyCompany");
        }
Example #19
0
        public ActionResult ProductEditRows(Product editedItem)
        {
            // Get the grid and database models
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();

            // If we are in "Edit" mode
            if (gridModel.WarehouseGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                // Get the data from and find the item corresponding to the edited row
                Product item = (from x in datacontextModel.Products
                                where x.ProductId == editedItem.ProductId
                                  select x).First<Product>();

                // update the item information
                UpdateProduct(item, editedItem);

                datacontextModel.SaveChanges();
            }

            if (gridModel.WarehouseGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                Product item = (from x in datacontextModel.Products
                                where x.ProductId == editedItem.ProductId
                                  select x)
                               .First<Product>();

                // delete the record
                datacontextModel.Products.Remove(item);
                datacontextModel.SaveChanges();
            }

            return RedirectToAction("Product", "Reference");
        }
Example #20
0
        private void ContractorDetailsSetupGrid(SkladJqGridModel model)
        {
            int contractorId = 0;
            Int32.TryParse(Request.QueryString["contractorId"], out contractorId);
            if (contractorId <= 0)
                return;

            var datacontextModel = new SkladDataContext();
            var contractor = datacontextModel.Contractors.Where(x => x.ContractorId == contractorId).FirstOrDefault();
            if (contractor == null)
                return;

            var documentsGrid = model.DocumentGrid;
            var productsGrid = model.ProductLineGrid;

            //DateTime periodFrom = SqlDateTime.MinValue.Value, periodTo = SqlDateTime.MaxValue.Value;

            //DateTime.TryParse(Request.QueryString["periodFrom"], out periodFrom);
            //DateTime.TryParse(Request.QueryString["periodTo"], out periodTo);

            string periodFrom = Request.QueryString["periodFrom"], periodTo = Request.QueryString["periodTo"];

            documentsGrid.ID = "Documents1";
            documentsGrid.DataUrl = Url.Action("TwoLevel_DocumentsDataRequested", new { contractorId = contractorId,
                                                                                        periodFrom = periodFrom,
                                                                                        periodTo = periodTo
            });
            documentsGrid.ClientSideEvents.SubGridRowExpanded = "showProductsSubGrid";
            documentsGrid.ToolBarSettings.ShowDeleteButton = false;
            documentsGrid.ToolBarSettings.ShowAddButton = false;
            documentsGrid.ToolBarSettings.ShowEditButton = false;

            documentsGrid.HierarchySettings.HierarchyMode = HierarchyMode.Parent;
            documentsGrid.HierarchySettings.ReloadOnExpand = true;
            documentsGrid.HierarchySettings.SelectOnExpand = true;

            /*documentsGrid.HierarchySettings.PlusIcon = Convert.ToString(ViewData["plusIcon"]);
            documentsGrid.HierarchySettings.MinusIcon = Convert.ToString(ViewData["minusIcon"]);
            documentsGrid.HierarchySettings.OpenIcon = Convert.ToString(ViewData["openIcon"]);*/

            productsGrid.ID = "Products1";
            productsGrid.DataUrl = Url.Action("TwoLevel_ProductsDataRequested", new { contractorId = contractorId });
            productsGrid.HierarchySettings.HierarchyMode = HierarchyMode.Child;

            JQGridColumn documentColumn1 = documentsGrid.Columns.Find(c => c.DataField == "ContractorName");

            JQGridColumn documentColumn2 = documentsGrid.Columns.Find(c => c.DataField == "ContractorId");
            JQGridColumn documentColumn3 = documentsGrid.Columns.Find(c => c.DataField == "Sum");
            JQGridColumn documentColumn4 = documentsGrid.Columns.Find(c => c.DataField == "SaleSum");
            JQGridColumn productsColumn1 = documentsGrid.Columns.Find(c => c.DataField == "SaleSum");

            if (contractor.ContractorTypeId == (int)EntityEnum.ContractorTypeEnum.Factory)
            {
                documentColumn1.Visible = true;
                documentColumn2.Visible = true;
                documentColumn3.Visible = false;
                documentColumn4.Visible = false;
                productsGrid.Height = Unit.Pixel(70);
                documentsGrid.HierarchySettings.ExpandOnLoad = true;
            }

            else {
                documentColumn1.Visible = false;
                documentColumn2.Visible = false;
                documentsGrid.HierarchySettings.ExpandOnLoad = false;
            }

            //SetUpGrid(grid, "ContractorDetails1",
            //    Url.Action("ContractorDetailsSearchGridDataRequested", new { contractorId = contractorId }),
            //    Url.Action("ContractorDetailsEditRows"));

            ////SetUpContactListDropDown(grid);

            //grid.Height = 100;
            //grid.ToolBarSettings.ShowDeleteButton = false;
            //grid.ToolBarSettings.ShowAddButton = false;
            //grid.ToolBarSettings.ShowEditButton = false;
        }
Example #21
0
        // This method is called when the grid requests data
        public JsonResult ProductSearchGridDataRequested()
        {
            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();
            // customize the default grid model with our custom settings
            ProductSetupGrid(gridModel.ProductGrid);

            string contractorIdStr = Request.QueryString["ContractorId"];
            if (!String.IsNullOrEmpty(contractorIdStr))
            {
                var contractor = datacontextModel.Contractors.Where(x =>
                    x.Code.ToLower() == contractorIdStr.ToLower()).FirstOrDefault();
                if (contractor != null)
                {

                    return gridModel.ProductGrid.DataBind(datacontextModel
                        .Products.Where(x => x.ContractorId == contractor.ContractorId).Include(x => x.Supplier));
                }
            }

            // return the result of the DataBind method, passing the datasource as a parameter
            // jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc
            return gridModel.ProductGrid.DataBind(datacontextModel.Products.Include(x => x.Supplier));
        }
Example #22
0
        public ActionResult Document(int? documentTypeId, int? documentId)
        {
            // Get the model (setup) of the grid defined in the /Models folder.
            var gridModel = new SkladJqGridModel();
            var grid = gridModel.ProductLineGrid;

            var datacontextModel = new SkladDataContext();

            DocumentProductLineModel model = new DocumentProductLineModel
            {
                WarehouseList = datacontextModel.Warehouses.ToList(),
                OurCompanyList = datacontextModel.LegalEntities.ToList(),
                EmployeeList = datacontextModel.UserProfiles.Where(x => x.ContactTypeId == (int)EntityEnum.ContactTypeEnum.Employee).ToList(),
                //DocumentItem = (documentTypeId != null || documentTypeId >= 0) ?
                //(new Document { DocumentTypeId = (int)documentTypeId,
                //    DocumentType = datacontextModel.DocumentTypes.Where(x =>x.DocumentTypeId == documentTypeId).First(),
                //    CreatedOf = DateTime.Now
                //}) :
                //(datacontextModel.Documents
                //.Include("DocumentType")
                //.Include("FromWarehouse")
                //.Include("ToWarehouse")
                //.Include("Contract")
                //.Include("Employee")
                //.Where(x => x.DocumentId == documentId)).First(),
                Products = grid,
            };

            if (documentTypeId != null)
            {
                model.DocumentItem = new Document { DocumentTypeId = (int)documentTypeId,
                    DocumentType = datacontextModel.DocumentTypes.Where(x =>x.DocumentTypeId == documentTypeId).First(),
                    CreatedOf = DateTime.Now,
                    IsCommitted = true, IsReportOutdated = true,
                };
            }
            else if (documentId != null)
            {
                model.DocumentItem = (datacontextModel.Documents
                .Include("DocumentType")
                .Include("FromWarehouse")
                .Include("ToWarehouse")
                .Include("Contract")
                .Include("Employee")
                .Include("Contractor")
                .Where(x => x.DocumentId == documentId)).First();
            }

            if (model.DocumentItem != null)
            {
                ViewBag.Title = model.DocumentItem.DocumentType.Name;
            }
            model.JGridName = "DocumentGrid1";

            // NOTE: you need to call this method in the action that fetches the data as well,
            // so that the models match
            DocumentSetupGrid(grid, documentId);

            return View(model);
        }
Example #23
0
        public ActionResult Refunds()
        {
            ViewBag.Title = "Возвраты покупателя";
            // Get the model (setup) of the grid defined in the /Models folder.
            var gridModel = new SkladJqGridModel();
            var grid = gridModel.DocumentGrid;

            //// NOTE: you need to call this method in the action that fetches the data as well,
            //// so that the models match
            RefundsSetupGrid(grid);

            // Создать grid со списком товаров с возвратом за определённый день
            // Можно сделать просто полный список всех товаров из проведённых
            // документов возвратов
            var gridProducts = gridModel.ProductLineGrid;
            RefundsProductSetupGrid(gridProducts);
            ViewBag.GridProducts = gridProducts;

            // Pass the custmomized grid model to the View
            return View(gridModel);
        }
Example #24
0
        // This method is called when the grid requests data
        public JsonResult ContactListSearchGridDataRequested()
        {
            int contractorId = 0;
            Int32.TryParse(Request.QueryString["contractorId"], out contractorId);
            if (contractorId <= 0)
                return null;

            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();
            // customize the default grid model with our custom settings
            ContactListSetupGrid(gridModel.MyEmployeesGrid);

            // return the result of the DataBind method, passing the datasource as a parameter
            // jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc
            return gridModel.MyEmployeesGrid.DataBind(datacontextModel.Contractors
                .Where(x => x.ContractorId == contractorId).SelectMany(x => x.Users));
        }
Example #25
0
        // This method is called when the grid requests data
        public JsonResult ShipmentSearchGridDataRequested()
        {
            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();
            // customize the default grid model with our custom settings
            ShipmentSetupGrid(gridModel.DocumentGrid);

            return GetDocumentList(gridModel, datacontextModel, EntityEnum.DocumentTypeEnum.Shipment);
        }
Example #26
0
        public ActionResult DocumentItemEditRows(Document editedItem)
        {
            // Get the grid and database models
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();

            // If we are in "Edit" mode
            if (gridModel.DocumentGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                return RedirectToAction("Document", new { documentId = editedItem.DocumentId });
            }

            if (gridModel.DocumentGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                Document item = (from x in datacontextModel.Documents
                                    where x.DocumentId == editedItem.DocumentId
                                    select x)
                               .First<Document>();

                DocumentOperation operation = new DocumentOperation();
                operation.DeleteDocument(datacontextModel, item);

                datacontextModel.Documents.Remove(item);
                datacontextModel.SaveChanges();

                logger.InfoFormat("удален документ {0} от {1}", editedItem.Number, editedItem.CreatedOf);
            }

            return RedirectToDocumentList(editedItem.DocumentTypeId);
        }
Example #27
0
        public ActionResult ContactListEditRows(UserProfile editedItem)
        {
            int contractorId = 0;

            Int32.TryParse(Request.QueryString["contractorId"], out contractorId);

            if (contractorId <= 0)
                return null;

            // Get the grid and database models
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();

            // If we are in "Edit" mode
            if (gridModel.MyEmployeesGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                PrepareUsersData(editedItem);

                string validationMessage = ValidateUsersData(datacontextModel.UserProfiles, editedItem, false);
                if (!String.IsNullOrEmpty(validationMessage))
                    return gridModel.MyEmployeesGrid.ShowEditValidationMessage(validationMessage);

                // Get the data from and find the item corresponding to the edited row
                UserProfile item = (from x in datacontextModel.UserProfiles
                                    where x.UserId == editedItem.UserId
                                    select x).First<UserProfile>();

                if (item.ContactTypeId != 3)
                    return null;

                // update the item information
                UpdateMyEmployees(item, editedItem);

                datacontextModel.SaveChanges();
                logger.InfoFormat("контакт {0} изменён", item.DisplayName);

                // Change password if need it
                if (!String.IsNullOrEmpty(editedItem.NewPassword))
                {
                    string resetToken = WebSecurity.GeneratePasswordResetToken(editedItem.UserName);
                    WebSecurity.ResetPassword(resetToken, editedItem.NewPassword);
                    logger.InfoFormat("у контакта {0} был изменён пароль", editedItem.DisplayName);
                }
            }

            if (gridModel.MyEmployeesGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {

                UserProfile item = (from x in datacontextModel.UserProfiles.Include(x => x.Contractors)
                                    where x.UserId == editedItem.UserId
                                    select x)
                               .First<UserProfile>();

                Contractor contractor = datacontextModel.Contractors
                    .Where(x => x.ContractorId == contractorId).FirstOrDefault<Contractor>();
                item.Contractors.Remove(contractor);
                datacontextModel.SaveChanges();
            }

            return RedirectToAction("ContactList", "MyCompany", new { contractorId = contractorId });
        }
Example #28
0
        // This method is called when the grid requests data
        public JsonResult DocumentSearchGridDataRequested(int? documentId)
        {
            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();
            // customize the default grid model with our custom settings
            DocumentSetupGrid(gridModel.ProductLineGrid, documentId);

            if (documentId == null)
                documentId = 0;

            // return the result of the DataBind method, passing the datasource as a parameter
            // jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc
            return gridModel.ProductLineGrid.DataBind(datacontextModel.ProductLines.Where(x => x.DocumentId == (int)documentId));
        }
Example #29
0
        public ActionResult DocumentEditRows(ProductLine editedItem)
        {
            // Get the grid and database models
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();

            int documentId = -1;
            // If we are in "Edit" mode

            if (gridModel.ProductLineGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                // Get the data from and find the item corresponding to the edited row
                ProductLine item = (from x in datacontextModel.ProductLines
                                    where x.ProductLineId == editedItem.ProductLineId
                                    select x).First<ProductLine>();

                // update the Order information
                UpdateProductLine(item, editedItem);

                // save comment to iriginal product item description
                var product = datacontextModel.Products.Where(x => x.ProductId == item.ProductId).FirstOrDefault();
                if (product != null)
                {
                    if (String.IsNullOrEmpty(product.Description))
                    { product.Description = editedItem.Comment; }
                    else if (product.Description.IndexOf(editedItem.Comment) == -1)
                    {
                        product.Description += ". " + editedItem.Comment;
                    }
                    else
                        product.Description = editedItem.Comment;
                }

                documentId = item.DocumentId;
                datacontextModel.SaveChanges();
            }

            if (gridModel.ProductLineGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                ProductLine item = (from x in datacontextModel.ProductLines
                                    where x.ProductLineId == editedItem.ProductLineId
                                    select x)
                               .First<ProductLine>();
                documentId = item.DocumentId;
                // delete the record
                datacontextModel.ProductLines.Remove(item);
                datacontextModel.SaveChanges();
            }

            var document = datacontextModel.Documents.Where(x => x.DocumentId == documentId).FirstOrDefault();

            if (document != null)
            {
                document.IsReportOutdated = true;
                datacontextModel.SaveChanges();
            }

            // Add
            //DocumentOperation operation = new DocumentOperation();
            //operation.UpdateDocument(datacontextModel, documentId);

            return RedirectToAction("Document", "Home", new { documentId = documentId });
        }
Example #30
0
        public ActionResult ContractorDetails(int contractorId, DateTime? periodFrom, DateTime? periodTo)
        {
            if (contractorId <= 0)
            {
                // log error
                return null;
            }

            ContractorDetailsModel list = new ContractorDetailsModel();
            var gridModel = new SkladJqGridModel();
            var datacontextModel = new SkladDataContext();

                //.Where(x => x.Doc == contractorId).Include(x => x.Responsible).First();
            var company = datacontextModel.Contractors
                 .Where(x => x.ContractorId == contractorId).Include(x => x.Responsible).First();
            list.Company = company;

            ContractorDetailsSetupGrid(gridModel);
            list.DocumentGrid = gridModel.DocumentGrid;
            list.ProductLineGrid = gridModel.ProductLineGrid;
            return View(list);
        }