示例#1
0
        public string DeleteCotract(string s1)
        {
            try
            {
                using (DB_DocumentsEntities dbModel = new DB_DocumentsEntities())
                {
                    string СontractNumber = Request["СontractNumber"];
                    string ProviderTitle  = Request["ProviderTitle"];


                    var resultTable = dbModel.Contracts.Where(x => x.Providers.Any(pr => pr.TitleProvider == ProviderTitle) && x.ContractNumber == СontractNumber).FirstOrDefault();


                    int Id1 = resultTable.IdContract;

                    dbModel.Contracts.Remove(dbModel.Contracts.FirstOrDefault(con => con.IdContract == Id1));

                    dbModel.SaveChanges();



                    return(JsonConvert.SerializeObject("{status: '200'}"));
                }//using
            }
            catch (Exception ex)
            {
                return($"{{status: '500', message: '{ex.Message}'}}");

                /*501 Not Implemented («не реализовано»);
                 * 500 Internal Server Error («внутренняя ошибка сервера»)
                 */
            }
        }// DeleteCotract
示例#2
0
        public string CreateCotract(string s1)
        {
            try
            {
                using (DB_DocumentsEntities dbModel = new DB_DocumentsEntities())
                {
                    string dateFromResult;
                    string dateEndResult;

                    string Year1  = Request["Year1"];
                    string Month1 = Request["Month1"];
                    string Day1   = Request["Day1"];

                    string Year2  = Request["Year2"];
                    string Month2 = Request["Month2"];
                    string Day2   = Request["Day2"];

                    int IdProvider = int.Parse(Request["firm"]);


                    dateFromResult = Year1 + "-" + Month1 + "-" + Day1;
                    dateEndResult  = Year2 + "-" + Month2 + "-" + Day2;

                    Contracts contract = new Contracts()
                    {
                        ContractNumber = Request["СontractNumber"],
                        DateFrom       = DateTime.Parse(dateFromResult),
                        DateEnd        = DateTime.Parse(dateEndResult),
                        DeliveryConditionsIncoterms = Request["Incoterms"]
                    };

                    int providerID = int.Parse(Request["firm"]);

                    Providers pr = dbModel.Providers.FirstOrDefault(p => p.IdProvider == providerID);


                    contract.Providers.Add(pr);


                    dbModel.Contracts.Add(contract);

                    dbModel.SaveChanges();


                    return(JsonConvert.SerializeObject("{status: '200'}"));
                }//using
            }
            catch (Exception ex)
            {
                return($"{{status: '500', message: '{ex.Message}'}}");

                /*501 Not Implemented («не реализовано»);
                 * 500 Internal Server Error («внутренняя ошибка сервера»)
                 */
            }
        }//CreateCotract
示例#3
0
        public ActionResult Edit(int id, Firms firm)
        {
            try {
                using (DB_DocumentsEntities dbModel = new DB_DocumentsEntities())
                {
                    dbModel.Entry(firm).State = EntityState.Modified;
                    dbModel.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }// Edit
示例#4
0
        public string Create(string s1, string s2)
        {
            try
            {
                byte t1 = byte.Parse(Request["AddressType1"]);

                Addresses addresses1 = new Addresses()
                {
                    Country      = Request["Country1"],
                    City         = Request["City1"],
                    Street       = Request["Street1"],
                    HouseNumber  = Request["HouseNumber1"],
                    OfficeNumber = int.Parse(Request["OfficeNumber1"]),
                    addressTypes = dbModel.addressTypes.First(t => t.addressTypeId == t1)
                };

                byte t2 = byte.Parse(Request["AddressType2"]);

                Addresses addresses2 = new Addresses()
                {
                    Country      = Request["Country2"],
                    City         = Request["City2"],
                    Street       = Request["Street2"],
                    HouseNumber  = Request["HouseNumber2"],
                    OfficeNumber = int.Parse(Request["OfficeNumber2"]),
                    addressTypes = dbModel.addressTypes.First(t => t.addressTypeId == t2)
                };

                Directors director = new Directors()
                {
                    Surname    = Request["Surname"],
                    Name       = Request["Name"],
                    SecondName = Request["SecondName"]
                };



                var result1 = dbModel.Addresses.Add(addresses1);
                var result2 = dbModel.Addresses.Add(addresses2);
                var result3 = dbModel.Directors.Add(director);


                dbModel.SaveChanges();


                var Id1 = result1.IdAddress;
                var Id2 = result2.IdAddress;
                var Id3 = result3.IdDirector;


                Firms f = new Firms()
                {
                    TitleFirm = Request["FirmTitle"],

                    IdAddressActual = Id1,

                    IdAddressLegal = Id2,

                    IdDirector = Id3
                };

                dbModel.Firms.Add(f);

                dbModel.SaveChanges();

                var r = new { status = 200 };

                return(JsonConvert.SerializeObject(r));

                //return JsonConvert.SerializeObject("{status: '200'}");
            }
            catch (Exception ex)
            {
                var r = new { status = 500 };

                return(JsonConvert.SerializeObject(r));

                /*501 Not Implemented («не реализовано»);
                 * 500 Internal Server Error («внутренняя ошибка сервера»)
                 */
            }
        }// string Create(Firms firm)
示例#5
0
        public string CreateProvider(string s1, string s2)
        {
            try
            {
                byte t1 = byte.Parse(Request["AddressType1"]);

                Addresses addresses1 = new Addresses()
                {
                    Country      = Request["Country1"],
                    City         = Request["City1"],
                    Street       = Request["Street1"],
                    HouseNumber  = Request["HouseNumber1"],
                    OfficeNumber = int.Parse(Request["OfficeNumber1"]),
                    addressTypes = dbModel.addressTypes.First(t => t.addressTypeId == t1)
                };

                byte t2 = byte.Parse(Request["AddressType2"]);

                Addresses addresses2 = new Addresses()
                {
                    Country      = Request["Country2"],
                    City         = Request["City2"],
                    Street       = Request["Street2"],
                    HouseNumber  = Request["HouseNumber2"],
                    OfficeNumber = int.Parse(Request["OfficeNumber2"]),
                    addressTypes = dbModel.addressTypes.First(t => t.addressTypeId == t2)
                };


                byte t3 = byte.Parse(Request["AddressType3"]);

                Addresses addresses3 = new Addresses()
                {
                    Country      = Request["Country3"],
                    City         = Request["City3"],
                    Street       = Request["Street3"],
                    HouseNumber  = Request["HouseNumber3"],
                    OfficeNumber = int.Parse(Request["OfficeNumber3"]),
                    addressTypes = dbModel.addressTypes.First(t => t.addressTypeId == t3)
                };


                Directors director = new Directors()
                {
                    Surname    = Request["Surname"],
                    Name       = Request["Name"],
                    SecondName = Request["SecondName"]
                };


                var result1 = dbModel.Addresses.Add(addresses1);
                var result2 = dbModel.Addresses.Add(addresses2);
                var result3 = dbModel.Directors.Add(director);
                var result4 = dbModel.Addresses.Add(addresses3);


                dbModel.SaveChanges();


                var Id1 = result1.IdAddress;
                var Id2 = result2.IdAddress;
                var Id3 = result3.IdDirector;
                var Id4 = result4.IdAddress;

                Providers pr = new Providers()
                {
                    TitleProvider = Request["FirmTitle"],

                    IdAddressProviderActual = Id1,

                    IdAddressProviderLegal = Id2,

                    IdDirector = Id3,

                    IdAddressStore = Id4
                };


                int firmID = int.Parse(Request["firm"]);

                Firms firm = dbModel.Firms.FirstOrDefault(f => f.IdFirm == firmID);

                pr.Firms.Add(firm);

                dbModel.Providers.Add(pr);
                dbModel.SaveChanges();


                var r = new { status = 200 };

                return(JsonConvert.SerializeObject(r));

                //return JsonConvert.SerializeObject("{status: '200'}");
            }
            catch (Exception ex)
            {
                var r = new { status = 500 };

                return(JsonConvert.SerializeObject(r));

                /*501 Not Implemented («не реализовано»);
                 * 500 Internal Server Error («внутренняя ошибка сервера»)
                 */
            }
        }//CreateProvider
示例#6
0
        public JsonResult CreateDocument(SecondClassDocument SCD)
        {
            try
            {
                var Doc = SCD;


                string dateDocument;
                dateDocument = Doc.Year + "-" + Doc.Month + "-" + Doc.Day;


                Documents document = new Documents()
                {
                    DocumentNumber = Doc.numberDocument,
                    Date           = DateTime.Parse(dateDocument),
                    NDS            = Doc.NDS
                };

                Contracts contract = dbModel.Contracts.FirstOrDefault(c => c.IdContract == Doc.contractID);

                document.Contracts.Add(contract);

                var DocumentNew = dbModel.Documents.Add(document);

                dbModel.SaveChanges();

                var DocumentNewID = DocumentNew.IdDocument;      /// Id нового документа для таблицы наименований


                // 5 полей ввода  Doc.ArrayDocTitle.Count() 10/5=2;

                int CountArray = Doc.ArrayDocTitle.Count();

                int max = (CountArray / 5);

                int t = 0;

                for (int i = 1; i < max; i++)
                {
                    DocumentTitle docTitle = new DocumentTitle()
                    {
                        Title            = Doc.ArrayDocTitle[t],
                        UnitMeasurements = Doc.ArrayDocTitle[t + 1],
                        Amount           = double.Parse(Doc.ArrayDocTitle[t + 2]),
                        PriceWithoutNDS  = double.Parse(Doc.ArrayDocTitle[t + 3]),
                        SumWithoutNDS    = double.Parse(Doc.ArrayDocTitle[t + 4])
                    };

                    Documents doc = dbModel.Documents.FirstOrDefault(d => d.IdDocument == DocumentNewID);
                    docTitle.Documents.Add(doc);

                    dbModel.DocumentTitle.Add(docTitle);

                    t = t + 5;
                }   // for


                dbModel.SaveChanges();


                return(Json("{status: '200'}"));
            }
            catch (Exception ex)
            {
                return(Json($"{{status: '500', message: '{ex.Message} {ex.StackTrace}'}}"));

                /*501 Not Implemented («не реализовано»);
                 * 500 Internal Server Error («внутренняя ошибка сервера»)
                 */
            }
        }//CreateDocumen