コード例 #1
0
ファイル: ReferenceController.cs プロジェクト: sidby/sklad
 private void UpdateContractor(Contractor item, Contractor editedItem)
 {
     item.Name = (editedItem.Name ?? String.Empty).Trim();
     item.Code = (editedItem.Code ?? String.Empty).Trim();
     item.Phone = (editedItem.Phone ?? String.Empty).Trim();
     item.Fax = (editedItem.Fax ?? String.Empty).Trim();
     item.Email = (editedItem.Email ?? String.Empty).Trim();
     item.Region = (editedItem.Region ?? String.Empty).Trim();
     item.ActualAddress = (editedItem.ActualAddress ?? String.Empty).Trim();
     item.Comment = (editedItem.Comment ?? String.Empty).Trim();
     item.ResponsibleId = editedItem.ResponsibleId;
     item.ContractorTypeId = editedItem.ContractorTypeId;
     item.ContactPersonName = editedItem.ContactPersonName;
     item.MarginAbs = editedItem.MarginAbs;
 }
コード例 #2
0
ファイル: ReferenceController.cs プロジェクト: sidby/sklad
        private string ValidateContractorData(DbSet<Contractor> dbSet, Contractor contractor, bool isNew)
        {
            if (String.IsNullOrEmpty(contractor.Name))
                return "Имя пользователя обязательно";

            if (String.IsNullOrEmpty(contractor.Code))
                return "Отображаемое имя обязательно";

            if (isNew)
            {
                Contractor item = dbSet.Where(x =>
                    String.Compare(x.Code, contractor.Code, StringComparison.OrdinalIgnoreCase) == 0
                    || x.Name == contractor.Name).FirstOrDefault<Contractor>();

                if (item != null)
                    return "Контрагент с таким именем существует";
            }
            else
            {
                Contractor item = (from x in dbSet
                                   where x.ContractorId == contractor.ContractorId
                                   select x).First<Contractor>();

                // if DisplayName was changed
                if (item.Name.ToLower() != contractor.Name.ToLower())
                {
                    if ((from x in dbSet
                         where String.Compare(x.Name, contractor.Name, StringComparison.OrdinalIgnoreCase) == 0
                         select x).FirstOrDefault<Contractor>() != null)
                        return "Контрагент с таким именем существует";
                }

                // if UserName was changed
                if (item.Code.ToLower() != contractor.Code.ToLower())
                {
                    if ((from x in dbSet
                         where String.Compare(x.Code, contractor.Code, StringComparison.OrdinalIgnoreCase) == 0
                         select x).FirstOrDefault<Contractor>() != null)
                        return "Контрагент с таким именем существует";
                }
            }

            if (!String.IsNullOrEmpty(contractor.Email))
            {
                if (!ValidationHelper.IsValidEmail(contractor.Email))
                    return "Неверный формат email";
            }

            return String.Empty;
        }
コード例 #3
0
ファイル: ReferenceController.cs プロジェクト: sidby/sklad
        private void PrepareContractorData(Contractor contractor)
        {
            contractor.Name = (contractor.Name ?? String.Empty).Trim();
            contractor.Code = (contractor.Code ?? String.Empty).Trim();
            contractor.Phone = (contractor.Phone ?? String.Empty).Trim();
            contractor.Fax = (contractor.Fax ?? String.Empty).Trim();
            contractor.Email = (contractor.Email ?? String.Empty).Trim();
            contractor.ActualAddress = (contractor.ActualAddress ?? String.Empty).Trim();
            contractor.Comment = (contractor.Comment ?? String.Empty).Trim();
            contractor.ContactPersonName = (contractor.ContactPersonName ?? String.Empty).Trim();

            if (String.IsNullOrEmpty(contractor.Name))
                contractor.Name = contractor.Code;

            if (String.IsNullOrEmpty(contractor.Code))
                contractor.Code = contractor.Name;
        }
コード例 #4
0
ファイル: ReferenceController.cs プロジェクト: sidby/sklad
        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");
        }
コード例 #5
0
ファイル: MyCompanyController.cs プロジェクト: sidby/sklad
        private string GetSaleReportByContractorFile(Contractor contractor,
           List<Document> documents,
           int grandTotalQuantity, DateTime? periodFrom, DateTime? periodTo)
        {
            string relativePath = "../" + Constants.SalesByContractorReportPath;
            string rootPath = Server.MapPath(relativePath);
            string reportFile = String.Empty;

            // Check if file already exists.
            // Than check Modified date of the file in file name
            string docPath = Path.Combine(rootPath, contractor.ContractorId.ToString());

            if (!Directory.Exists(docPath))
                Directory.CreateDirectory(docPath);

              //  string dateSeparator = "-";
            string extension = ".xls";
            string mask = String.Format("{0}*{1}", Constants.SalesByContractorReportPrefix, extension);

            var directory = new DirectoryInfo(docPath);
            // get last created file in directory
            var existingFile = directory.GetFiles(mask).OrderByDescending(f => f.LastWriteTime).FirstOrDefault();

            // check if file is actual upon document modified date
            if (existingFile != null)
            {
                // Cache 1 minute
                if (existingFile.CreationTime.AddSeconds(10) > DateTime.Now)
                {
                    // return cached file
                    return String.Format("{0}/{1}/{2}", relativePath, contractor.ContractorId.ToString(),
                         existingFile.Name);
                }
                else
                {
                    // delete outdate file
                    existingFile.Delete();
                }
            }

            string fileName = String.Format("{0}{1}", Constants.SalesByContractorReportPrefix,
                extension);

            // create report
            ExcelReportInfo reportInfo = new ExcelReportInfo
            {
                CreatedOf = DateTime.Now,
                FileName = fileName,
                FilePath = docPath,
                DocumentSubject = "Список документов для " + contractor.Name + "(" + contractor.Code + ")",
                SheetName = Constants.SalesByContractorReportPrefix,
                TitleLeft = contractor.Code,
                TitleCenter = (periodFrom != null ? "За период "+periodFrom.Value.ToString("dd.MM.yyyy") : "")
                + (periodTo != null ? "-" + periodTo.Value.ToString("dd.MM.yyyy") : "") + " Общее кол-во: " + grandTotalQuantity,
                TitleRight = ""
            };

            ReportHelper.GenerateContractorSalesReport(documents, reportInfo);
            // ../Reports/Document/1093/e4fmt/Report-2014-10-09.xls
            //  /Reports/Refunds/RefundsReport-2014-10-09.xls
            reportFile = String.Format("{0}/{1}/{2}", relativePath, contractor.ContractorId.ToString(),
                fileName);

            return reportFile;
        }
コード例 #6
0
ファイル: MyCompanyController.cs プロジェクト: sidby/sklad
        private IQueryable<ProductLine> GetContractorDocuments(SkladDataContext datacontextModel, int documentId, Contractor contractor)
        {
            IQueryable<ProductLine> products = null;
            if (contractor.ContractorTypeId == (int)EntityEnum.ContractorTypeEnum.Factory)
            {
                products = from o in datacontextModel.ProductLines
                           where o.DocumentId == documentId && o.SupplierId == contractor.ContractorId
                           select o;
            }
            else
            {
                products = from o in datacontextModel.ProductLines
                           where o.DocumentId == documentId
                           select o;
            }

            return products;
        }
コード例 #7
0
ファイル: MyCompanyController.cs プロジェクト: sidby/sklad
        private IQueryable<Document> GetContractorDocuments(SkladDataContext datacontextModel,
            Contractor contractor, DateTime? periodFrom, DateTime? periodTo, bool refundsShipmentOnly = true)
        {
            IQueryable<Document> documentSet;
            if (contractor.ContractorTypeId == (int)EntityEnum.ContractorTypeEnum.Factory)
            {

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

                    x.SupplierId == contractor.ContractorId)
                    .GroupBy(x => x.DocumentId).Select(k => k.Key).ToArray();

                if (periodTo == null)
                    periodTo = DateTime.MaxValue;

                if (!refundsShipmentOnly)
                    documentSet = datacontextModel.Documents.Where(x => documentIds.Contains(x.DocumentId) && x.CreatedOf >= periodFrom && x.CreatedOf <= periodTo);
                else
                    documentSet = datacontextModel.Documents.Where(x => documentIds.Contains(x.DocumentId) && x.CreatedOf >= periodFrom && x.CreatedOf <= periodTo
                        && (x.DocumentTypeId == (int)EntityEnum.DocumentTypeEnum.Refunds || x.DocumentTypeId == (int)EntityEnum.DocumentTypeEnum.Shipment));

            }
            else
            {   if(!refundsShipmentOnly)
                    documentSet = datacontextModel.Documents.Where(x => x.ContractorId == contractor.ContractorId);
                else
                    documentSet = datacontextModel.Documents.Where(x => x.ContractorId == contractor.ContractorId
                         && (x.DocumentTypeId == (int)EntityEnum.DocumentTypeEnum.Refunds || x.DocumentTypeId == (int)EntityEnum.DocumentTypeEnum.Shipment));
            }
            return documentSet;
        }