Example #1
0
        public void Nouns()
        {
            int speechPartNountID            = 1;
            CyrNounCollection nounCollection = new CyrNounCollection();
            CyrillerEntities  mainDB         = new CyrillerEntities();
            int         count = mainDB.Words.Where(x => x.SpeechPartID == speechPartNountID).Count();
            int         step  = 1000;
            List <Task> tasks = new List <Task>();

            mainDB.Dispose();

            for (int i = 0; i < count; i += step)
            {
                int skip = i;

                tasks.Add(Task.Run(() =>
                {
                    CyrillerEntities db     = new CyrillerEntities();
                    IQueryable <Word> words = db.Words.Where(x => x.SpeechPartID == speechPartNountID).OrderBy(x => x.ID).Skip(skip).Take(step);

                    foreach (Word word in words)
                    {
                        CyrNoun noun = nounCollection.Get(word.Name, GetConditionsEnum.Strict, (GendersEnum?)word.GenderID, (AnimatesEnum?)word.AnimateID, (WordTypesEnum?)word.TypeID);

                        Assert.NotNull(noun);
                        Assert.Equal(word.GenderID ?? 0, (int?)noun.Gender ?? 0);
                        Assert.Equal(word.AnimateID ?? 0, (int?)noun.Animate ?? 0);
                        Assert.Equal(word.TypeID ?? 0, (int?)noun.WordType ?? 0);

                        CyrResult result = noun.Decline();

                        Assert.NotNull(result);

                        for (int caseID = 1; caseID < 7; caseID++)
                        {
                            WordCase[] wordCases = word.WordCases.Where(x => x.CaseID == caseID && x.NumberID == 1).ToArray();

                            if (!wordCases.Any())
                            {
                                Assert.True(caseID == 1 || string.IsNullOrEmpty(result[caseID]), $"{word.ID}|{caseID} - {word.Name} - {result[caseID]}");
                            }
                            else
                            {
                                Assert.True(wordCases.Any(x => string.Compare(x.Name, result[caseID], true) == 0), $"{word.ID}|{caseID} - {word.Name} - {result[caseID]}");
                            }
                        }
                    }

                    db.Dispose();
                }));
            }

            Task.WaitAll(tasks.ToArray());
        }
Example #2
0
        static void WriteToConsole(CyrNoun noun, string foundWord = null)
        {
            Console.WriteLine($"{noun.Name}");

            if (!string.IsNullOrWhiteSpace(foundWord) && !string.Equals(noun.Name, foundWord, StringComparison.InvariantCulture))
            {
                Console.Write(" - слово в словаре: ");
                Console.WriteLine(foundWord);
            }

            switch (noun.Gender)
            {
            case GendersEnum.Feminine:
                Console.WriteLine(" - женский род");
                break;

            case GendersEnum.Masculine:
                Console.WriteLine(" - мужской род");
                break;

            case GendersEnum.Neuter:
                Console.WriteLine(" - нейтральный род");
                break;
            }

            if (noun.IsAnimated)
            {
                Console.WriteLine(" - одушевленный предмет");
            }
            else
            {
                Console.WriteLine(" - неодушевленный предмет");
            }

            Console.Write(" - Единственное число: ");
            Console.WriteLine(string.Join(", ", noun.Decline().ToArray()));

            Console.Write(" - Множественное число: ");
            Console.WriteLine(string.Join(", ", noun.DeclinePlural().ToArray()));

            Console.WriteLine();
        }
Example #3
0
        public ActionResult CreateContract(Guid callID)
        {
            var callData    = db.Calls.ToList();
            var itemsData   = db.Items.ToList();
            var custData    = db.Customers.ToList();
            var repData     = db.Representatives.ToList();
            var callDetails = db.CallDetails.ToList();
            //var progdata = db.Programs.ToList();

            var callData2 = (from c in db.CallDetails
                             join item in itemsData on c.ItemID equals item.ItemID
                             join calcdet in db.CalcDetails.ToList() on item.CalcDetailsID equals calcdet.CalcID
                             where (c.CallID == callID)
                             select new ContractViewModel.Itm {
                itemname = item.ItemName, Qty = c.ItemQty.ToString(), itemsubtype = item.ItemSubtype.ItemSubtype1, additionals = item.Additional, calcDate = calcdet.CalcDate.ToString(), calcNum = calcdet.CalcNum
            }).ToList();


            ContractViewModel contract = new ContractViewModel();

            CultureInfo ci = new CultureInfo("RU-ru");

            contract = (from cd in callData
                        join cust in custData on cd.CustomerID equals cust.CustomerID
                        join rep in repData on cust.RepresentativeID equals rep.RepresentativeID
                        join calldet in callDetails on cd.CallID equals calldet.CallID
                        join item in itemsData on calldet.ItemID equals item.ItemID

                        where (cd.CallID == (Guid)callID)
                        select new ContractViewModel {
                CallID = cd.CallID,
                callDate = cd.CallDate.ToString("dd MMMM yyyy г.", ci),
                sampleActDate = cd.SampleActDate.ToString("dd MMMM yyyy г.", ci),
                callNumber = cd.DocNumber.ToString(),
                expAffNum = cd.AffidavitNum.ToString(),
                expAffDate = cd.AffidavitDate.ToString("dd MMMM yyyy г.", ci),
                contractDate = cd.ContractDate,
                repdoc = rep.RepDoc.ToString(),
                repFName = rep.FirstName.ToString(),
                repMName = rep.MidName.ToString(),
                repFamName = rep.FamilyName.ToString(),
                repPosition = rep.Position.ToString(),
                repPhone = rep.PhoneNumber.ToString(),
                custName = cust.Name.ToString(),
                custAddress = cust.Address.ToString(),
                custTaxID = cust.TaxID.ToString(),
                custBIC = cust.BIC.ToString(),
                custPhoneNumber = cust.PhoneNumber.ToString(),
                custOKPO = cust.OKPO.ToString(),
                custAccount = cust.Account.ToString(),
                custBankBranch = cust.BankBranch.ToString(),
                custBranchAddress = cust.BranchAddress.ToString(),
                custBankCode = cust.BankCode.ToString(),
                custMPhoneNumber = cust.MPhoneNumber.ToString()
            }

                        ).FirstOrDefault();

            contract.itmList = callData2;

            ////////////////////////////////////////////////////////////////////////////////////////////////////////

            //                              ВВОД ДАННЫХ В ШАБЛОН ДОГОВОРА                                        //

            ///////////////////////////////////////////////////////////////////////////////////////////////////////


            List <string> expertData = callexp.Split(' ').Reverse().ToList();

            string expName = expertData[0] + expertData[1] + expertData[2];

            int nameIndex = callexp.IndexOf(expName);

            string expertPosition = callexp.Remove(nameIndex, expName.Length);

            string firstWordInPosition = callexp.Split(' ').First();

            int firstWordIndex = expertPosition.IndexOf(firstWordInPosition);

            string expPositionTail = expertPosition.Remove(firstWordIndex, firstWordInPosition.Length);

            CyrNounCollection      nouns = new CyrNounCollection();
            CyrAdjectiveCollection adj   = new CyrAdjectiveCollection();
            CyrPhrase phrase             = new CyrPhrase(nouns, adj);
            CyrResult expname            = phrase.Decline(expName, GetConditionsEnum.Strict);

            expName = expname.Genitive;

            CyrNoun   strict        = nouns.Get(firstWordInPosition, GetConditionsEnum.Strict);
            CyrResult expPosition   = strict.Decline();
            string    firstWordDecl = expPosition.Genitive;

            expertPosition = string.Concat(firstWordDecl, expPositionTail);

            firstWordInPosition = contract.repPosition.Split(' ').First();

            firstWordIndex = contract.repPosition.IndexOf(firstWordInPosition);

            string repPositionTail = contract.repPosition.Remove(firstWordIndex, firstWordInPosition.Length);

            CyrResult repname = phrase.Decline((contract.repFamName + contract.repFName + contract.repMName), GetConditionsEnum.Strict);
            string    repName = repname.Genitive;

            strict = nouns.Get(firstWordInPosition, GetConditionsEnum.Strict);
            CyrResult repPosition = strict.Decline();

            firstWordDecl = repPosition.Genitive;
            string representativePosition = string.Concat(firstWordDecl, expPositionTail);


            try
            {
                Document document = new Document();
                document.LoadFromFile("~/Content/FileTemplates/ContractTemplateCorporate.docx");
                BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
                bookmarkNavigator.MoveToBookmark("ContractNum");
                bookmarkNavigator.ReplaceBookmarkContent(contract.callNumber, true);

                bookmarkNavigator.MoveToBookmark("ContractDay");
                if (contract.contractDate.HasValue)
                {
                    bookmarkNavigator.ReplaceBookmarkContent((contract.contractDate?.ToString("dd", new CultureInfo("ru-RU"))), true);

                    bookmarkNavigator.MoveToBookmark("ContractMonth");
                    bookmarkNavigator.ReplaceBookmarkContent(contract.contractDate?.ToString(" MMMM ", new CultureInfo("ru-RU")), true);

                    bookmarkNavigator.MoveToBookmark("ContractYear");
                    bookmarkNavigator.ReplaceBookmarkContent(contract.contractDate?.ToString(" yyyy г.", new CultureInfo("ru-RU")), true);
                }

                else
                {
                    bookmarkNavigator.ReplaceBookmarkContent((DateTime.Today.ToString("dd", new CultureInfo("ru-RU"))), true);

                    bookmarkNavigator.MoveToBookmark("ContractMonth");
                    bookmarkNavigator.ReplaceBookmarkContent(DateTime.Today.ToString(" MMMM ", new CultureInfo("ru-RU")), true);

                    bookmarkNavigator.MoveToBookmark("ContractYear");
                    bookmarkNavigator.ReplaceBookmarkContent(DateTime.Today.ToString(" yyyy г.", new CultureInfo("ru-RU")), true);
                }

                bookmarkNavigator.MoveToBookmark("ContractExpertPosition");
                bookmarkNavigator.ReplaceBookmarkContent(expertPosition, true);

                bookmarkNavigator.MoveToBookmark("ContractExpertFullName");
                bookmarkNavigator.ReplaceBookmarkContent(expName, true);

                bookmarkNavigator.MoveToBookmark("AffidavitNum");
                bookmarkNavigator.ReplaceBookmarkContent(contract.expAffNum, true);

                bookmarkNavigator.MoveToBookmark("AffidavitDate");
                bookmarkNavigator.ReplaceBookmarkContent(contract.expAffDate, true);

                bookmarkNavigator.MoveToBookmark("CustomerName");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custName, true);

                bookmarkNavigator.MoveToBookmark("CustomerDoc");
                bookmarkNavigator.ReplaceBookmarkContent(" ", true);

                bookmarkNavigator.MoveToBookmark("RepresentativePosition");
                bookmarkNavigator.ReplaceBookmarkContent(representativePosition, true);

                bookmarkNavigator.MoveToBookmark("RepresentativeName");
                bookmarkNavigator.ReplaceBookmarkContent(repName, true);

                bookmarkNavigator.MoveToBookmark("CustomerCompanyDoc");
                bookmarkNavigator.ReplaceBookmarkContent(contract.repdoc, true);

                foreach (ContractViewModel.Itm i in contract.itmList)
                {
                    CyrResult it_name = phrase.Decline(i.itemsubtype, GetConditionsEnum.Strict);
                    i.itemsubtype = it_name.Genitive;

                    bookmarkNavigator.MoveToBookmark("ItemName");
                    bookmarkNavigator.ReplaceBookmarkContent(i.itemsubtype + i.itemname, true);

                    string progname = (from prog in db.Programs.ToList()
                                       join t in db.ItemTypes.ToList() on prog.ItemTypeID equals t.ItemTypeID
                                       join st in db.ItemSubtypes.ToList() on t.ItemTypeID equals st.ItemTypeID
                                       join item in db.Items.ToList() on st.ItemSubtypeID equals item.ItemSubtypeID
                                       where item.ItemName == i.itemname
                                       select prog.ProgramNameShort).FirstOrDefault();


                    bookmarkNavigator.MoveToBookmark("ProgramShortName");
                    bookmarkNavigator.ReplaceBookmarkContent(progname, true);

                    bookmarkNavigator.MoveToBookmark("ItemsNum");
                    bookmarkNavigator.ReplaceBookmarkContent(i.Qty, true);


                    string [] stringarr       = i.additionals.Split(' ');
                    CyrResult addCyr          = phrase.Decline(stringarr[0], GetConditionsEnum.Strict);
                    string    additionals     = addCyr.Genitive;
                    int       index           = i.additionals.IndexOf(additionals);
                    string    additionalsTail = i.additionals.Remove(index, stringarr[0].Length);

                    bookmarkNavigator.MoveToBookmark("Additionals");
                    bookmarkNavigator.ReplaceBookmarkContent(additionals + additionalsTail, true);

                    bookmarkNavigator.MoveToBookmark("CalculationOrderDate");
                    bookmarkNavigator.ReplaceBookmarkContent(i.calcDate, true);

                    bookmarkNavigator.MoveToBookmark("CalculationOrderNum");
                    bookmarkNavigator.ReplaceBookmarkContent(i.calcNum, true);
                }

                decimal TotalSum = 0;
                var     costs    = from callitem in callDetails
                                   where (callitem.CallID == callID)
                                   select callitem.ItemTestCost;
                TotalSum = costs.Sum(c => Convert.ToDecimal(c));

                bookmarkNavigator.MoveToBookmark("TotalSum");
                bookmarkNavigator.ReplaceBookmarkContent(TotalSum.ToString(), true);

                bookmarkNavigator.MoveToBookmark("TestingDurationCalDays");
                bookmarkNavigator.ReplaceBookmarkContent("30", true);

                bookmarkNavigator.MoveToBookmark("ExpertFIO");
                bookmarkNavigator.ReplaceBookmarkContent(expName, true);

                bookmarkNavigator.MoveToBookmark("RepresentativeFIO");
                bookmarkNavigator.ReplaceBookmarkContent(repName, true);

                bookmarkNavigator.MoveToBookmark("CustomerName2");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custName, true);

                bookmarkNavigator.MoveToBookmark("TaxID");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custTaxID, true);

                bookmarkNavigator.MoveToBookmark("OKPO");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custOKPO, true);

                bookmarkNavigator.MoveToBookmark("CustomerAddress");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custAddress, true);

                bookmarkNavigator.MoveToBookmark("CustomerPhoneNum");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custPhoneNumber, true);

                bookmarkNavigator.MoveToBookmark("CustomerMphoneNum");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custMPhoneNumber, true);

                bookmarkNavigator.MoveToBookmark("BankAccount");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custAccount, true);

                bookmarkNavigator.MoveToBookmark("BankBranch");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custBankBranch, true);

                bookmarkNavigator.MoveToBookmark("BankAddress");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custBranchAddress, true);

                bookmarkNavigator.MoveToBookmark("BankCode");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custBankCode, true);

                bookmarkNavigator.MoveToBookmark("BIC");
                bookmarkNavigator.ReplaceBookmarkContent(contract.custBIC, true);

                //Save doc file.

                if (document != null)
                {
                    string path = Server.MapPath(@"~\Area\Manager\Files\Contracts\");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    document.SaveToFile(path + @"docx\" + contract.CallID.ToString() + ".docx", Spire.Doc.FileFormat.Docx);
                    document.SaveToFile(path + @"pdf\" + contract.CallID.ToString() + ".pdf", Spire.Doc.FileFormat.PDF);
                    ViewBag.pdf = (path + @"pdf\" + contract.CallID.ToString() + ".pdf");
                }
            }

            catch (Exception e)
            {
                return(new HttpNotFoundResult(e.ToString()));
            }



            return(View());
        }
Example #4
0
        public void Nouns()
        {
            int speechPartNountID            = 1;
            CyrNounCollection nounCollection = new CyrNounCollection();
            CyrillerEntities  mainDB         = new CyrillerEntities();
            int         count = mainDB.Words.Where(x => x.SpeechPartID == speechPartNountID).Count();
            int         step  = 1000;
            List <Task> tasks = new List <Task>();

            mainDB.Dispose();

            for (int i = 0; i < count; i += step)
            {
                int skip = i;

                tasks.Add(Task.Run(() =>
                {
                    CyrillerEntities db     = new CyrillerEntities();
                    IQueryable <Word> words = db.Words.Where(x => x.SpeechPartID == speechPartNountID).OrderBy(x => x.ID).Skip(skip).Take(step);

                    foreach (Word iterator in words)
                    {
                        CyrNoun noun = nounCollection.Get(iterator.Name, (GendersEnum)(iterator.GenderID ?? 0), CasesEnum.Nominative, NumbersEnum.Singular);

                        Assert.NotNull(noun);

                        // There might be multiple the same words in the database, one animated, another one not.
                        int animateID = (int)noun.Animate;
                        int genderID  = (int)noun.Gender;
                        Word word     = db.Words.FirstOrDefault(x =>
                                                                x.Name == noun.Name &&
                                                                x.AnimateID == animateID &&
                                                                (x.GenderID ?? 0) == genderID
                                                                );

                        Assert.NotNull(word);
                        Assert.True((word.GenderID ?? 0) == ((int?)noun.Gender ?? 0), $"{word.ID}|{word.Name} - wrong gender [{noun.Gender}], expected [{word.Gender?.Name}].");
                        Assert.True((word.AnimateID ?? 0) == ((int?)noun.Animate ?? 0), $"{word.ID}|{word.Name} - wrong animate [{noun.Animate}], expected [{word.Animate?.Name}].");
                        Assert.True((word.TypeID ?? 0) == ((int?)noun.WordType ?? 0), $"{word.ID}|{word.Name} - wrong type [{noun.WordType}], expected [{word.WordType?.Name}].");

                        CyrResult result = noun.Decline();

                        Assert.NotNull(result);

                        for (int caseID = 1; caseID < 7; caseID++)
                        {
                            WordCase[] wordCases = word.WordCases.Where(x => x.CaseID == caseID && x.NumberID == 1).ToArray();
                            string errorMessage  = $"{word.ID}|{caseID} - wrong case [{result[caseID]}], expected [{word.Name}].";

                            if (!wordCases.Any())
                            {
                                Assert.True(caseID == 1 || string.IsNullOrEmpty(result[caseID]), errorMessage);
                            }
                            else
                            {
                                Assert.True(wordCases.Any(x => string.Compare(x.Name, result[caseID], true) == 0), errorMessage);
                            }
                        }
                    }

                    db.Dispose();
                }));
            }

            Task.WaitAll(tasks.ToArray());
        }