Example #1
0
        //Create Purchase documents and Remnants of goods in stock
        private async Task<DocPurch> DocsCreate(ArrayList alWrite)
        {
            if (alWrite.Count == 0) return null;


            db.Configuration.AutoDetectChangesEnabled = false;

            //Во всех записях есть данные для Doc, DocPurch и DocPurchTab
            Field1 field10 = (Field1)alWrite[0];


            #region Таблица Doc *** *** ***

            Models.Sklad.Doc.DocPurch docPurch = new Models.Sklad.Doc.DocPurch();
            docPurch.DocID = null;
            docPurch.Base = "Создано на основании импорта из файла Excel";
            docPurch.Del = false;
            docPurch.DirEmployeeID = field.DirEmployeeID;
            docPurch.Discount = 0;
            docPurch.DocDate = DateTime.Now.AddDays(-30); //Convert.ToDateTime(field10.DocDate);
            docPurch.DocIDBase = null;
            docPurch.Held = true;
            docPurch.IsImport = true;
            docPurch.ListObjectID = 1;

            #endregion


            #region Таблица DocPurch *** *** ***

            docPurch.DocPurchID = null;
            docPurch.NumberInt = "";
            docPurch.NumberTT = "";
            docPurch.NumberTax = "";
            docPurch.DirContractorIDOrg = DirContractorIDOrg;
            docPurch.DirContractorID = DirContractorID;
            docPurch.DirWarehouseID = field10.DirWarehouseID;
            docPurch.DirVatValue = 0;
            docPurch.DirPaymentTypeID = 1;

            #endregion


            #region Таблица DocPurchTab *** *** ***

            //Создаём коллекцию спецификации
            Models.Sklad.Doc.DocPurchTab[] docPurchTabCollection = new Models.Sklad.Doc.DocPurchTab[alWrite.Count];
            for (int i = 0; i < alWrite.Count; i++)
            {
                Field1 field1 = (Field1)alWrite[i];

                Models.Sklad.Doc.DocPurchTab docPurchTab = new Models.Sklad.Doc.DocPurchTab();
                docPurchTab.DocPurchID = 0;
                docPurchTab.DocPurchTabID = null;

                docPurchTab.DirNomenID = ReturnDirNomenID(Convert.ToInt32(field1.DirNomenID));
                docPurchTab.DirCurrencyID = 1;
                docPurchTab.DirCurrencyMultiplicity = 1;
                docPurchTab.DirCurrencyRate = 1;
                //docPurchTab.DirVatValue = 0;

                if (field1.DirCharColourID > 0) docPurchTab.DirCharColourID = field1.DirCharColourID;
                if (field1.DirCharTextureID > 0) docPurchTab.DirCharTextureID = field1.DirCharTextureID;
                if (field1.DirCharSizeID > 0) docPurchTab.DirCharSizeID = field1.DirCharSizeID;

                docPurchTab.Quantity = field1.Quantity; //field1.Quantity;

                docPurchTab.PriceVAT = field1.PriceVAT;
                docPurchTab.PriceCurrency = field1.PriceVAT;

                docPurchTab.PriceRetailVAT = field1.PriceRetailVAT;
                docPurchTab.PriceRetailCurrency = field1.PriceRetailCurrency;

                docPurchTab.PriceWholesaleVAT = field1.PriceWholesaleVAT;
                docPurchTab.PriceWholesaleCurrency = field1.PriceWholesaleCurrency;

                docPurchTab.PriceIMVAT = field1.PriceIMVAT;
                docPurchTab.PriceIMCurrency = field1.PriceIMCurrency;

                docPurchTabCollection[i] = docPurchTab;
            }

            #endregion


            #region Save

            Doc.DocPurches.DocPurchesController docPurchesController = new Doc.DocPurches.DocPurchesController();
            docPurch = await Task.Run(() => docPurchesController.mPutPostDocPurch(db, db, "held", sysSetting, docPurch, EntityState.Added, docPurchTabCollection, field)); //await Task.Run(() => docPurchesController.mPutPostDocPurch(db, dbRead, "held", sysSetting, docPurch, EntityState.Added, docPurchTabCollection, field));

            #endregion


            return docPurch;
        }
Example #2
0
        public async Task <IHttpActionResult> DeleteDocPurchTab(int id, HttpRequestMessage request)
        {
            try
            {
                #region Проверяем Логин и Пароль + Изменяем строку соединения + Права + Разные Функции

                //Получаем Куку
                System.Web.HttpCookie authCookie = System.Web.HttpContext.Current.Request.Cookies["CookieIPOL"];

                // Проверяем Логин и Пароль
                Classes.Account.Login.Field field = await Task.Run(() => login.Return(authCookie, true));

                if (!field.Access)
                {
                    return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg10)));
                }

                //Изменяем строку соединения
                db     = new DbConnectionSklad(connectionString.Return(field.DirCustomersID, null, true));
                dbRead = new DbConnectionSklad(connectionString.Return(field.DirCustomersID, null, true));

                //Права (1 - Write, 2 - Read, 3 - No Access)
                int iRight = await Task.Run(() => accessRight.Access(connectionString.Return(field.DirCustomersID, null, true), field.DirEmployeeID, "RightDocPurches"));

                if (iRight != 1)
                {
                    return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57(0))));
                }

                //Разные Функции
                function.NumberDecimalSeparator();

                //Получам настройки
                sysSetting = await db.SysSettings.FindAsync(1);

                #endregion

                #region Параметры

                //save, save_close, held, held_cancel
                //var paramList = request.GetQueryNameValuePairs();
                //docPurchTab.DocPurchID = Convert.ToInt32(paramList.FirstOrDefault(kv => string.Compare(kv.Key, "DocPurchID", true) == 0).Value);

                #endregion

                #region Проверки

                if (!ModelState.IsValid)
                {
                    return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg91)));                     //return BadRequest(ModelState);
                }
                //Если документ "docPurchTab.DocPurchID" проведён, то выдать Эксепшн
                Models.Sklad.Doc.DocPurchTab docPurchTab = await db.DocPurchTabs.FindAsync(id);

                //Models.Sklad.Doc.Doc doc = await db.Docs.FindAsync(docPurch.DocID);
                if (Convert.ToBoolean(docPurchTab.docPurch.doc.Held))
                {
                    return(Ok(returnServer.Return(false, Classes.Language.Sklad.Language.msg57_3)));
                }

                //Подстановки - некоторые поля надо заполнить, если они не заполены (Юридические реквизиты)
                //docPurchTab.Substitute();

                #endregion


                #region Сохранение

                //using (TransactionScope ts = new TransactionScope())
                using (System.Data.Entity.DbContextTransaction ts = db.Database.BeginTransaction())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;

                    try
                    {
                        //db.DocPurchTabs.Remove(docPurchTab);
                        //await db.SaveChangesAsync();

                        db.Entry(docPurchTab).State = EntityState.Deleted;
                        await db.SaveChangesAsync();

                        ts.Commit(); //.Complete();
                    }
                    catch (Exception ex)
                    {
                        try { ts.Rollback(); ts.Dispose(); } catch { }
                        try { db.Database.Connection.Close(); db.Database.Connection.Dispose(); } catch { }

                        return(Ok(returnServer.Return(false, exceptionEntry.Return(ex))));
                    }
                }


                #region 6. JourDisp *** *** *** *** *** *** *** *** *** *

                Models.Sklad.Sys.SysJourDisp sysJourDisp = new Models.Sklad.Sys.SysJourDisp();
                sysJourDisp.DirDispOperationID = 5; //Удаление записи
                sysJourDisp.DirEmployeeID      = field.DirEmployeeID;
                sysJourDisp.ListObjectID       = ListObjectID;
                sysJourDisp.TableFieldID       = docPurchTab.DocPurchID;
                sysJourDisp.Description        = "";
                try { sysJourDispsController.mPutPostSysJourDisps(db, sysJourDisp, EntityState.Added); } catch (Exception ex) { }

                #endregion


                dynamic collectionWrapper = new
                {
                    ID  = id,
                    Msg = Classes.Language.Sklad.Language.msg19
                };
                return(Ok(returnServer.Return(true, collectionWrapper))); //return Ok(returnServer.Return(true, ""));

                #endregion
            }
            catch (Exception ex)
            {
                return(Ok(returnServer.Return(false, exceptionEntry.Return(ex))));
            }
        }