public static void GenerateOrder(Order order)
        {
            archiveManager = new ArchiveManager();

            orderInfo = order;

            var docReq = new DocumentRequisite()
            {
                fileName = "Заявка №" + order.Auction.Number.Replace("/", "_") + ".docx",
                date     = order.Auction.Date,
                market   = MarketPlaceEnum.UTB,
                number   = order.Auction.Number,
                type     = DocumentTypeEnum.Order,
                section  = DocumentSectionEnum.Auction
            };

            orderFileName = archiveManager.GetTemplate(docReq, DocumentTemplateEnum.Order);

            if (!string.IsNullOrEmpty(orderFileName))
            {
                orderFileName = FillTemplateFile();

                if (orderFileName != null)
                {
                    docReq.fileName.Replace(".docx", ".pdf");
                    archiveManager.SaveFile(docReq, order.Auction.FilesListId);
                }
            }
        }
Ejemplo n.º 2
0
        public static void CreateReport(string template, Report report, int type)
        {
            archiveManager = new ArchiveManager(dataManager);
            var service = new WordService(template, false);

            service = type == 2 ? InsertIntoSupplierReport(report, service) : InsertIntoClientReport(report, service);
            var fileListId = DataBaseClient.GetFileListAuctionByLot(report.Code);

            if (fileListId != null)
            {
                DocumentRequisite docReq = new DocumentRequisite()
                {
                    date     = fileListId.date,
                    fileName = template.Substring(template.LastIndexOf("\\") + 1),
                    market   = AltaBO.specifics.MarketPlaceEnum.ETS,
                    number   = fileListId.number,
                    section  = AltaBO.specifics.DocumentSectionEnum.Auction,
                    type     = type == 2 ? AltaBO.specifics.DocumentTypeEnum.SupplierReport : AltaBO.specifics.DocumentTypeEnum.CustomerReport
                };

                archiveManager.SaveFile(docReq, (int)fileListId.fileslistid);
                docReq.fileName = docReq.fileName.Replace(".docx", ".pdf");
                archiveManager.SaveFile(docReq, (int)fileListId.fileslistid);
            }

            service.SaveAsPDF(template);
            service.CloseDocument(true);
            service.CloseWord(true);
        }
        public Stream GetDocument(DocumentRequisite documentRequisite)
        {
            var path   = GetPath(documentRequisite);
            var stream = GetDocument(path);

            return(stream);
        }
        public static void CreateApplicants(Order orderInfo, List <SupplierOrder> notAllowedSuppliers, DocumentRequisite docReqInfo, string fileNameInfo, bool forCustomerInfo = false)
        {
            order       = orderInfo;
            notAllowed  = new List <SupplierOrder>(notAllowedSuppliers);
            docReq      = docReqInfo;
            fileName    = fileNameInfo;
            forCustomer = forCustomerInfo;

            FillTemplate(order.Auction.SiteId == 4 ? 2 : 1);
        }
Ejemplo n.º 5
0
        private void AttachContract()
        {
            AppJournal.Write("Company", "Attach contract", true);

            if (SelectedContract != null && SelectedContract.id > 0)
            {
                try
                {
                    sourceFileName = Service.GetFile("Выберите файл договора", "(*.*) | *.*").FullName;
                }
                catch (Exception) { }

                if (!string.IsNullOrEmpty(sourceFileName))
                {
                    newFileName  = FolderExplorer.GetCompanyPath(Company.bin);
                    newFileName += "Договор " + SelectedContract.number.Replace("/", "_").Replace("\\", "_") + " с " + ServiceFunctions.CompanyRenamer(Company.name) + sourceFileName.Substring(sourceFileName.LastIndexOf("."));

                    if (Service.CopyFile(sourceFileName, newFileName, true))
                    {
                        try
                        {
                            DocumentRequisite docReq = new DocumentRequisite()
                            {
                                date     = DateTime.Now,
                                fileName = newFileName.Substring(newFileName.LastIndexOf("\\") + 1),
                                number   = Company.bin,
                                section  = AltaBO.specifics.DocumentSectionEnum.Company,
                                type     = AltaBO.specifics.DocumentTypeEnum.Contract
                            };

                            DataBaseClient.UpdateContractFile(SelectedContract.id, archiveManager.SaveFile(docReq));
                            MessagesService.Show("АРХИВ", "Файл скопирован в архив.");
                            UpdateContractList();
                        }
                        catch (Exception ex)
                        {
                            MessagesService.Show("АРХИВ", "При занесении файла в базу произошла ошибка");
                            AppJournal.Write("Company", "Put contract into db error :" + ex.ToString(), true);
                        }
                    }
                    else
                    {
                        MessagesService.Show("ОШИБКА", "Проверьте доступ к архиву.");
                    }
                }
            }
            else
            {
                MessagesService.Show("Работа с договором", "Не выбран договор");
            }
        }
        public string GetPath(DocumentRequisite documentRequisite)
        {
            string path = "";

            switch (documentRequisite.section)
            {
            case DocumentSectionEnum.Company:
                path = archiveRootPath + @"Companies/";
                break;

            case DocumentSectionEnum.Order:
                path = archiveRootPath + @"Orders/";
                break;

            case DocumentSectionEnum.Auction:
                path = archiveRootPath + @"Auctions/";
                break;

            case DocumentSectionEnum.Template:
                path = archiveRootPath + @"Templates/";
                break;
            }

            if (documentRequisite.section != DocumentSectionEnum.Company)
            {
                switch (documentRequisite.market)
                {
                case MarketPlaceEnum.UTB:
                    path += @"UTB/";
                    break;

                case MarketPlaceEnum.ETS:
                    path += @"ETS/";
                    break;

                case MarketPlaceEnum.KazETS:
                    path += @"KazETS/";
                    break;

                case MarketPlaceEnum.Caspy:
                    path += @"Caspy/";
                    break;
                }
            }

            path += (documentRequisite.section == DocumentSectionEnum.Company || documentRequisite.section == DocumentSectionEnum.Template) ? "" : (documentRequisite.date.ToShortDateString() + @"/");
            path += documentRequisite.section == DocumentSectionEnum.Template ? "" : String.Format(@"{0}/", documentRequisite.number.Replace("/", "_"));
            path += documentRequisite.fileName;

            return(path);
        }
        public static void UploadDocument(DocumentType documentType, string fileName, Auction auction)
        {
            DocumentRequisite documentRequisite = new DocumentRequisite()
            {
                fileName    = fileName.Substring(fileName.LastIndexOf("\\") + 1),
                date        = auction.Date,
                extension   = fileName.Substring(fileName.LastIndexOf(".") + 1),
                filesListId = auction.FilesListId,
                market      = (MarketPlaceEnum)auction.SiteId,
                number      = auction.Number,
                section     = DocumentSectionEnum.Auction,
                type        = (DocumentTypeEnum)documentType.id
            };

            var result = archiveManager.PutDocument(fileName, documentRequisite, auction.FilesListId);
        }
Ejemplo n.º 8
0
        public static void CreateReports(Order orderInfo)
        {
            order = orderInfo;

            reportFileNames = ArchiveTransport.PutUTBReports(orderInfo);

            FillTemplate();

            // Put file to base
            var fileListId = DataBaseClient.ReadAuction(order.Auction.Id);

            if (fileListId != null)
            {
                DocumentRequisite docReq = new DocumentRequisite()
                {
                    date     = order.Auction.Date,
                    fileName = reportFileNames[0].Substring(reportFileNames[0].LastIndexOf("\\")),
                    market   = AltaBO.specifics.MarketPlaceEnum.UTB,
                    number   = order.Auction.Number,
                    section  = AltaBO.specifics.DocumentSectionEnum.Auction,
                    type     = AltaBO.specifics.DocumentTypeEnum.CustomerReport
                };

                // Customer file
                // Check for exist
                if (DataBaseClient.ReadDocument((int)fileListId.fileslistid, (int)AltaBO.specifics.DocumentTypeEnum.CustomerReport) == null)
                {
                    archiveManager.SaveFile(docReq, (int)fileListId.fileslistid);

                    docReq.fileName = reportFileNames[1].Substring(reportFileNames[1].LastIndexOf("\\"));
                }

                // Supplier file
                // Check for exist
                if (DataBaseClient.ReadDocument((int)fileListId.fileslistid, (int)AltaBO.specifics.DocumentTypeEnum.SupplierReport) == null)
                {
                    docReq.type = AltaBO.specifics.DocumentTypeEnum.SupplierReport;

                    archiveManager.SaveFile(docReq, (int)fileListId.fileslistid);
                }
            }
            //
        }
        public int PutDocument(Stream stream, DocumentRequisite documentRequisite, int?filesListId = null)
        {
            if (dataManager == null)
            {
                return(-1);
            }

            var path = GetPath(documentRequisite);

            if (!FTPService.CreateDirectory(Path.GetDirectoryName(path)))
            {
                return(-2);
            }
            if (!FTPService.Upload(stream, path))
            {
                return(-3);
            }

            return(dataManager.PutDocument(documentRequisite, filesListId));
        }
Ejemplo n.º 10
0
        public string[] CopyOriginalOrder(DocumentRequisite documentRequisite, string orderFileName, string treatyFileName = null, string orderOriginalFileName = null, string[] schemesFileNames = null)
        {
            var dateFolder   = ipPath + archiveRootPath + "\\Auctions\\" + documentRequisite.market + "\\" + documentRequisite.date.ToShortDateString();
            var oldEndFolder = dateFolder.Replace("/", "\\") + "\\" + (documentRequisite.number.Substring(documentRequisite.number.Length - 4)).Replace("/", "_");
            var endFolder    = dateFolder.Replace("/", "\\") + "\\" + documentRequisite.number.Replace("/", "_");

            endFolder = Directory.Exists(oldEndFolder) ? oldEndFolder : endFolder;

            string[] fileNames = new string[3 + (schemesFileNames == null ? 0 : schemesFileNames.Length)];

            fileNames[0] = endFolder + "\\" + orderFileName.Substring(orderFileName.LastIndexOf("\\"));
            File.Copy(orderFileName, fileNames[0], true);

            if (treatyFileName != null)
            {
                fileNames[1] = endFolder + "\\" + treatyFileName.Substring(treatyFileName.LastIndexOf("\\"));
                File.Copy(treatyFileName, fileNames[1], true);
            }

            if (orderOriginalFileName != null)
            {
                fileNames[2] = endFolder + "\\" + orderOriginalFileName.Substring(orderOriginalFileName.LastIndexOf("\\"));
                File.Copy(orderOriginalFileName, fileNames[2], true);
            }

            int fCount = 3;

            if (schemesFileNames != null && !string.IsNullOrEmpty(schemesFileNames[0]))
            {
                foreach (var item in schemesFileNames)
                {
                    fileNames[fCount] = endFolder + "\\" + item.Substring(item.LastIndexOf("\\"));

                    File.Copy(item, fileNames[fCount], true);

                    fCount++;
                }
            }

            return(fileNames);
        }
Ejemplo n.º 11
0
 public void SaveFile(DocumentRequisite documentRequisite, int filesListId)
 {
     dataManager.PutDocument(documentRequisite, filesListId);
 }
Ejemplo n.º 12
0
 public int SaveFile(DocumentRequisite documentRequisite)
 {
     return(dataManager.PutSimpleDocument(documentRequisite));
 }
Ejemplo n.º 13
0
        public string GetTemplate(DocumentRequisite documentRequisite, DocumentTemplateEnum documentTemplate)
        {
            string extension = ".docx";

            switch (documentRequisite.market)
            {
            case MarketPlaceEnum.UTB:
                if (documentTemplate == DocumentTemplateEnum.Order)
                {
                    extension = ".xlsx";
                }
                break;

            case MarketPlaceEnum.ETS:
                if (documentRequisite.type == DocumentTypeEnum.TechSpecs || documentTemplate == DocumentTemplateEnum.Procuratory)
                {
                    extension = ".xlsx";
                }
                break;

            case MarketPlaceEnum.KazETS:
                if (documentTemplate == DocumentTemplateEnum.SupplierOrderKorund || documentTemplate == DocumentTemplateEnum.SupplierOrderAkAltyn ||
                    documentTemplate == DocumentTemplateEnum.TechSpec || documentTemplate == DocumentTemplateEnum.CoverLetter ||
                    documentTemplate == DocumentTemplateEnum.CoverLetterAkAltyn || documentTemplate == DocumentTemplateEnum.CoverLetterKorund)
                {
                    extension = ".xlsx";
                }
                break;

            case MarketPlaceEnum.Caspy:
                if (documentTemplate == DocumentTemplateEnum.Order)
                {
                    extension = ".xlsx";
                }
                break;
            }

            if (documentRequisite.type == DocumentTypeEnum.CompanyProfile)
            {
                extension = ".xlsx";
            }

            var templateFileName = ipPath + archiveRootPath.Replace("/", "") + "\\Templates\\" + documentRequisite.market + "\\" + documentTemplate + extension;
            var dateFolder       = ipPath + archiveRootPath.Replace("/", "") + "\\Auctions\\" + documentRequisite.market + "\\" + documentRequisite.date.ToShortDateString();
            var endFolder        = dateFolder + "\\" + documentRequisite.number.Replace("/", "_");
            var oldEndFolder     = dateFolder + "\\" + (documentRequisite.market == MarketPlaceEnum.ETS ? documentRequisite.number.Length > 4 ? documentRequisite.number.Substring(documentRequisite.number.Length - 4) : documentRequisite.number : documentRequisite.number).Replace("/", "_");

            if (!Directory.Exists(dateFolder))
            {
                Directory.CreateDirectory(dateFolder);
            }
            if (Directory.Exists(oldEndFolder))
            {
                endFolder = oldEndFolder;
            }
            if (!Directory.Exists(endFolder))
            {
                Directory.CreateDirectory(endFolder);
            }

            try {
                File.Copy(templateFileName, endFolder + "\\" + documentRequisite.fileName, true);
                return(endFolder + "\\" + documentRequisite.fileName);
            } catch (Exception ex) {
                AppJournal.Write("Template copy", "Err: " + ex.ToString(), true);
                return(null);
            }
        }
Ejemplo n.º 14
0
        public static string LoadTemplateToLocalStorage(this ArchiveManager archiveManager, DocumentRequisite requisite)
        {
            var localPath = GenerateFilePath(requisite);

            return(archiveManager.GetDocument(requisite, localPath) ? localPath : null);
        }
Ejemplo n.º 15
0
        public bool GetDocument(DocumentRequisite documentRequisite, string saveAs)
        {
            var path = GetPath(documentRequisite);

            return(GetDocument(path, saveAs));
        }
Ejemplo n.º 16
0
 public int PutDocument(FileStream fileStream, DocumentRequisite documentRequisite, int?filesListId = null)
 {
     return(PutDocument((Stream)fileStream, documentRequisite, filesListId));
 }
 public DocumentRequisite AddDocumentReuisite(DocumentRequisite documentRequisite)
 {
     return(DataManager.AddDocumentRequisite(documentRequisite));
 }
Ejemplo n.º 18
0
        private void CreateBackMoneyTransfer()
        {
            // Log service
            AppJournal.Write("BackMoneyTransfer", "Create back money transfer documents", true);

            // Check for selected transaction
            if (SelectedClearingCount != null && SelectedClearingCount.statusid != 10)
            {
                // Get templates & copy to auction directory
                var fromCount = DataBaseClient.ReadSuppliersJournals(SelectedClearingCount.tosupplierid, SelectedClearingCount.brokerid);
                var toCount   = DataBaseClient.ReadSuppliersJournals(SelectedClearingCount.fromsupplierid, SelectedClearingCount.brokerid);

                DocumentRequisite docMoneyTransferReq = new DocumentRequisite()
                {
                    fileName = "Заявление на возврат из КЦ №" + SelectedClearingCount.lot.auction.number.Replace("/", "_") + " (c " + fromCount[0].code + " на " + toCount[0].code + ").docx",
                    market   = MarketPlaceEnum.ETS,
                    date     = SelectedClearingCount.lot.auction.date,
                    number   = SelectedClearingCount.lot.auction.number
                };

                var moneyTransferTemplateFile = archiveManager.GetTemplate(docMoneyTransferReq, DocumentTemplateEnum.MoneyTransfer);

                // Fill order with needed data
                Order order = new Order();
                order.Auction = new Auction();
                order.Auction.SupplierOrders = new System.Collections.ObjectModel.ObservableCollection <SupplierOrder>();

                order.Auction.SupplierOrders.Add(new SupplierOrder()
                {
                    BrokerName = SelectedClearingCount.broker.name,
                    BrokerCode = fromCount[0].code,
                    Code       = toCount[0].code
                });

                order.Auction.Lots = new System.Collections.ObjectModel.ObservableCollection <Lot>();

                order.Auction.Lots.Add(new Lot()
                {
                    Number = SelectedClearingCount.lot.number
                });

                // Formate money transfer document & open folder with new document
                if (MoneyTransferService.CreateDocument(order, moneyTransferTemplateFile, SelectedClearingCount.transaction))
                {
                    FolderExplorer.OpenAuctionFolder(MarketPlaceEnum.ETS, SelectedClearingCount.lot.auction.date.ToShortDateString(), SelectedClearingCount.lot.auction.number);

                    // Put records in base
                    ClearingCountingEF clearingCounting = new ClearingCountingEF()
                    {
                        brokerid       = SelectedClearingCount.brokerid,
                        fromsupplierid = fromCount[0].supplierid,
                        tosupplierid   = toCount[0].supplierid,
                        lotid          = SelectedClearingCount.lotid,
                        transaction    = SelectedClearingCount.transaction,
                        createdate     = DateTime.Now,
                        statusid       = 10
                    };

                    if (DataBaseClient.CreateClearingCounting(clearingCounting) == 0)
                    {
                        MessagesService.Show("Заявление об изменении денежных средств", "Произошла ошибка при занесении данных в базу");
                        AppJournal.Write("MoneyTransfer", "Fault when create record in base", true);
                    }
                    else
                    {
                        DataBaseClient.UpdateClearingCountStatus(toCount[0].supplierid, fromCount[0].supplierid, SelectedClearingCount.lotid);
                    }

                    Apply(0);
                }
                else
                {
                    MessagesService.Show("Заявление об изменении денежных средств", "Произошла ошибка при формировании заявления");
                }
            }
            else
            {
                MessagesService.Show("Заявление о возврате денежных средств", "Не выбрана транзакция или статус ОПЛАЧЕНО.");
                AppJournal.Write("BackMoneyTransfer", "Fault because not selected transaction or status payed.", true);
            }
        }
Ejemplo n.º 19
0
 public static string GenerateFilePath(this DocumentRequisite requisite)
 {
     return(GenerateFilePath(requisite.fileName));
 }
Ejemplo n.º 20
0
        private void FormateContract()
        {
            // Prepare data
            // Get contract data
            var cContract = dataManager.ReadContracts(companyId, SelectedBroker != null ? SelectedBroker.id : 0);

            if (cContract == null || cContract.Count < 1)
            {
                MessagesService.Show("Формирование договора", "Нет данных договора");
                return;
            }

            Contract caspyContract = cContract.FirstOrDefault(c => c.number.ToLower() == Contract.number);

            // Get company data
            var cCompany = dataManager.GetCompany(companyId);

            if (cCompany == null)
            {
                MessagesService.Show("Формирование договора", "Нет данных компании");
                return;
            }

            Company caspyCompany = cCompany;

            caspyCompany.bank = Contract.bank != null ? Contract.bank.name : "";
            caspyCompany.bik  = Contract.bank != null ? Contract.bank.company.bik : "";

            // Get company broker data
            var cBroker = dataManager.GetCompany(SelectedBroker.companyId);

            if (cBroker == null)
            {
                MessagesService.Show("Формирование договора", "Нет данных компании брокера");
                return;
            }

            Company caspyBroker = cBroker;

            var bContracts = dataManager.ReadContracts(companyId, SelectedBroker.id);

            if (bContracts == null || bContracts.Count < 1)
            {
                MessagesService.Show("Формирование договора", "Нет данных договора брокера");
                return;
            }

            var bContract = DataBaseClient.ReadContract(bContracts[0].id);

            if (bContract == null)
            {
                MessagesService.Show("Формирование договора", "Нет данных договора брокера");
                return;
            }

            caspyBroker.bank = bContract.bank != null ? bContract.bank.name : "";
            caspyBroker.bik  = bContract.bank != null ? bContract.bank.company.bik : "";

            // Copy templates to end folder
            DocumentRequisite docContractReq = new DocumentRequisite()
            {
                date     = DateTime.Now,
                fileName = "Договор " + Contract.number + ".docx",
                number   = Contract.company.bin,
                section  = DocumentSectionEnum.Company,
                type     = DocumentTypeEnum.Contract,
                market   = MarketPlaceEnum.Caspy
            };

            var contractFileName = archiveManager.GetTemplate(docContractReq, DocumentTemplateEnum.Contract);

            if (string.IsNullOrEmpty(contractFileName))
            {
                MessagesService.Show("Формирование договора", "Ошибка копирования шаблона договора");
                return;
            }

            string newFileName = FolderExplorer.GetCompanyPath(Contract.company.bin);

            newFileName += docContractReq.fileName;

            if (Service.CopyFile(contractFileName, newFileName, true))
            {
                Service.DeleteFile(contractFileName);
            }
            else
            {
                MessagesService.Show("Формирование договора", "Ошибка копирования шаблона договора");
                return;
            }

            if (string.IsNullOrEmpty(newFileName))
            {
                MessagesService.Show("Формирование договора", "Ошибка копирования шаблона договора");
                return;
            }

            // Fill contract template with prepared data
            if (!ContractService.FillKaspiContract(newFileName, caspyContract, caspyCompany, caspyBroker))
            {
                MessagesService.Show("Формирование договора", "Произошла ошибка при формировании документа");
                return;
            }

            DataBaseClient.UpdateContractFile(Contract.id, archiveManager.SaveFile(docContractReq));
        }
Ejemplo n.º 21
0
 public int PutDocument(Stream stream, DocumentRequisite documentRequisite)
 {
     return(PutDocument(stream, documentRequisite, documentRequisite.filesListId));
 }
        public int DonwloadFile()
        {
            var files       = HttpContext.Current.Request.Files;
            var form        = HttpContext.Current.Request.Form;
            var currentDate = DateTime.Now;

            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType));
            }

            if (files.Count == 0 || form.Count == 0)
            {
                var errorResponce = new HttpResponseMessage(HttpStatusCode.BadRequest);
                errorResponce.Headers.Add("X-Error-Description", "No files specified or data of the form specified.");
                throw new HttpResponseException(errorResponce);
            }

            var file = HttpContext.Current.Request.Files["file"];

            if (file == null)
            {
                var errorResponce = new HttpResponseMessage(HttpStatusCode.BadRequest);
                errorResponce.Headers.Add("X-Error-Description", "Not found file in request body.");
                throw new HttpResponseException(errorResponce);
            }
            ;

            JavaScriptSerializer jss    = new JavaScriptSerializer();
            DocumentRequisite    docReq = jss.Deserialize <DocumentRequisite>(form.Get("documentRequisite"));

            if (docReq == null)
            {
                var errorResponce = new HttpResponseMessage(HttpStatusCode.BadRequest);
                errorResponce.Headers.Add("X-Error-Description", "Error in form data");
                throw new HttpResponseException(errorResponce);
            }
            ;

            docReq.fileName = file.FileName;
            docReq.date     = currentDate;

            if (form.Get("fileListId") != null)
            {
                docReq.filesListId = int.Parse(form.Get("fileListId"));
            }

            var archive = new ArchiveManager(DataManager);

            int fileId = archive.PutDocument(file.InputStream, docReq);

            if (fileId > 0)
            {
                return(fileId);
            }
            else
            {
                var errorResponce = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                errorResponce.Headers.Add("X-Error-Description", "An error occurred while saving the file");
                throw new HttpResponseException(errorResponce);
            }
        }