Exemplo n.º 1
0
        private void DefaultParametrs()
        {
            DocDetailsVis = Visibility.Collapsed;
            IncludeVis    = Visibility.Collapsed;
            ExcludeVis    = Visibility.Collapsed;

            DateStart = DateTime.Now.AddDays(-60);
            DateEnd   = DateTime.Now;

            BrokersList = DataBaseClient.ReadBrokers().Where(b => b.id != 3).OrderByDescending(b => b.id).ToList();

            foreach (var item in BrokersList)
            {
                item.name = item.name.Replace("Товарищество с ограниченной ответственностью", "ТОО");
            }

            SelectedBroker    = BrokersList[0];
            SelectedDefBroker = BrokersList[0];
            DocTypesList      = DataBaseClient.ReadDocumentTypes(31, 42, 21);

            DocTypesList.Insert(9, DocTypesList.FirstOrDefault(d => d.id == 21));
            DocTypesList.RemoveAt(0);

            SelectedDocType = DocTypesList[0];
            DocQuantity     = 1;

            UpdateCompaniesList();
        }
Exemplo n.º 2
0
        private void ActionsWithDoc(int mode)
        {
            switch (mode)
            {
            case 1:     // Create
                if (SelectedCompany != null)
                {
                    // Set default params
                    SelectedOtherDoc = null;
                    DocCompanyName   = SelectedCompany.name;
                    SelectedBroker   = BrokersList.FirstOrDefault(bl => bl.id == SelectedDefBroker.id);
                    DocCreateDate    = DateTime.Now;
                    SelectedDocType  = DocTypesList[0];
                    DocNumber        = "";
                    DocInPost        = false;
                    DocQuantity      = 1;

                    // Show detials form
                    IncludeVis    = Visibility.Visible;
                    ExcludeVis    = Visibility.Collapsed;
                    DocDetailsVis = Visibility.Visible;
                }
                else
                {
                    MessagesService.Show("Оповещение", "Не выбрана компания");
                }
                break;

            case 2:     // Edit
                // Fill form
                DocCompanyName  = SelectedOtherDoc.company.name;
                SelectedBroker  = BrokersList.FirstOrDefault(b => b.id == SelectedOtherDoc.brokerid);
                DocCreateDate   = SelectedOtherDoc.createdate;
                SelectedDocType = DocTypesList.FirstOrDefault(d => d.id == SelectedOtherDoc.documenttypeid);
                DocNumber       = SelectedOtherDoc.number;
                DocInPost       = SelectedOtherDoc.inpost;
                DocQuantity     = SelectedOtherDoc.quantity;

                if (DocInPost)
                {
                    IncludeVis = Visibility.Collapsed;
                    ExcludeVis = Visibility.Visible;
                }
                else
                {
                    IncludeVis = Visibility.Visible;
                    ExcludeVis = Visibility.Collapsed;
                }

                DocDetailsVis = Visibility.Visible;
                break;

            case 3:     // Delete
                if (SelectedOtherDoc != null)
                {
                    try {
                        DataBaseClient.DeleteOtherDoc(SelectedOtherDoc.id);
                    } catch { MessagesService.Show("Оповещение", "Ошибка при удалении записи из базы"); }
                }
                else
                {
                    MessagesService.Show("Оповещение", "Не выбран документ");
                }
                break;

            case 4:     // Include
                // Save otherDoc if need
                if (SelectedOtherDoc == null)
                {
                    SaveDoc();
                }

                // Search opened registral
                var listServ       = DataBaseClient.ReadListServ(SelectedOtherDoc.brokerid, 12);
                int listServId     = 0;
                var listServNumber = DataBaseClient.ReadListServ();

                if (listServ == null)
                {
                    // Create list serv with status opened
                    ListServEF listServItem = new ListServEF()
                    {
                        brokerid   = SelectedOtherDoc.brokerid,
                        createdate = DateTime.Now,
                        number     = listServNumber.Count > 0 ? listServNumber.Max(l => l.number) + 1 : 1,
                        statusid   = 12
                    };

                    listServId = DataBaseClient.CreateListServ(listServItem);
                }
                else
                {
                    listServId = listServ.id;
                }

                // Search company in envelop
                var envelop   = DataBaseClient.ReadEnvelop(listServId, SelectedOtherDoc.companyid);
                int envelopId = 0;

                if (envelop == null)
                {
                    // Create envelop
                    EnvelopEF envelopItem = new EnvelopEF()
                    {
                        listservid = listServId,
                        companyid  = SelectedOtherDoc.companyid,
                    };

                    envelopId = DataBaseClient.CreateEnvelop(envelopItem);
                }
                else
                {
                    envelopId = envelop.id;
                }

                // Create envelop content
                EnvelopContentEF envelopContent = new EnvelopContentEF()
                {
                    listservid = listServId,
                    envelopid  = envelopId,
                    otherdocid = SelectedOtherDoc.id
                };

                DataBaseClient.CreateEnvelopContent(envelopContent);

                // Change status inpost
                SelectedOtherDoc.inpost         = true;
                SelectedOtherDoc.listservnumber = DataBaseClient.ReadListServ(listServId).number;

                DataBaseClient.UpdateOtherDoc(SelectedOtherDoc);

                // Update view
                try {
                    OtherDocsList    = new ObservableCollection <OtherDocsEF>(DataBaseClient.ReadOtherDocs(SelectedCompany.id, DateStart, DateEnd));
                    SelectedOtherDoc = null;
                    DocDetailsVis    = Visibility.Collapsed;
                } catch { }
                break;

            case 5:     // Exclude
                int selOthDoc = SelectedOtherDoc.id;

                var listServStatus = DataBaseClient.ReadEnvelopContentList();

                if (listServStatus != null)
                {
                    if (listServStatus.FirstOrDefault(l => l.otherdocid == selOthDoc).listserv.statusid != 14)
                    {
                        if (!DataBaseClient.DeleteEnvelopContent(selOthDoc))
                        {
                            MessagesService.Show("Оповещение", "Произошла ошибка при исключении документа из реестра.");
                        }
                        else
                        {
                            try {
                                OtherDocsList    = new ObservableCollection <OtherDocsEF>(DataBaseClient.ReadOtherDocs(SelectedCompany.id, DateStart, DateEnd));
                                SelectedOtherDoc = OtherDocsList.FirstOrDefault(o => o.id == selOthDoc);
                                DocDetailsVis    = Visibility.Collapsed;
                            } catch { }
                        }
                    }
                    else
                    {
                        MessagesService.Show("Оповещение", "Конверт в статусе отправлен.");
                    }
                }
                break;
            }
        }