示例#1
0
        //Create Categories in database
        private async Task<Models.Sklad.Dir.DirNomenCategory> CategoriesCreate(string DirNomenName)
        {
            Models.Sklad.Dir.DirNomenCategory dirNomenCategory = new Models.Sklad.Dir.DirNomenCategory();
            PartionnyAccount.Controllers.Sklad.Dir.DirNomens.DirNomenCategoriesController dirNomenCategoriesController = new Dir.DirNomens.DirNomenCategoriesController();

            var queryCat = await
            (
                from x in db.DirNomenCategories
                where x.DirNomenCategoryName.ToLower() == DirNomenName.ToLower()
                select x
            ).ToListAsync();

            //Есть такой Товар - выходим.
            if (queryCat.Count() > 0)
            {
                dirNomenCategory.DirNomenCategoryID = queryCat[0].DirNomenCategoryID;
                dirNomenCategory.DirNomenCategoryName = queryCat[0].DirNomenCategoryName;
            }
            else
            {
                dirNomenCategory.DirNomenCategoryName = DirNomenName;
                dirNomenCategory = await Task.Run(() => dirNomenCategoriesController.mPutPostDirNomenCategories(db, dirNomenCategory, EntityState.Added));
            }

            return dirNomenCategory;
        }
示例#2
0
        private async Task<bool> GroupCreate(int DirNomenID, string GroupList, string DirNomenName)
        {
            //Ищим товар в БД
            // Если есть - пропускаем
            // Если нет, то:
            //  вносим все группы "GroupList"
            //  вносим товар в последнюю

            //Controllers.Sklad.Dir.DirNomens.DirNomensController dirNomensController = new Controllers.Sklad.Dir.DirNomens.DirNomensController();


            SQLiteParameter parDirNomenID = null, parSub = null, parDel = null, parDirNomenName = null, parDirNomenNameFull = null, parDirNomenTypeID = null, parDirNomenCategoryID = null;


            #region Ищим товар в БД

            var iCount = await
                (
                    from x in db.DirNomens
                    where x.DirNomenID == DirNomenID
                    select x
                ).CountAsync();

            //Есть такой Товар - выходим.
            if (iCount > 0) return false;

            #endregion


            #region Группа товара

            //Нет товара - вносим группы, если их нет
            //Парсим группу: "APPLE/ iPhone 4S/  Распродажа/  Распродажа Swarovski /"
            int? Sub = null; //Последняя подчинённая
            string[] GroupArray = GroupList.Split('/');
            for (int i = 0; i < GroupArray.Length; i++)
            {
                i777 = i;
                //Удаляем спереди пробелы
                string GroupName = GroupArray[i];

                if (GroupName.Length == 0) break;

                if (GroupName[0].ToString() == " ") GroupName = GroupName.Remove(0, 1);
                if (GroupName[0].ToString() == " ") GroupName = GroupName.Remove(0, 1);
                if (GroupName[0].ToString() == " ") GroupName = GroupName.Remove(0, 1);
                if (GroupName[0].ToString() == " ") GroupName = GroupName.Remove(0, 1);

                if (GroupName.Length == 0) break;

                //1. Первая записть - Корневая группа (Sub == 0)
                var query = await
                    (
                        from x in db.DirNomens
                        where x.DirNomenName.ToLower() == GroupName.ToLower() && x.Sub == Sub
                        select x
                    ).ToListAsync();

                if (query.Count() != 0)
                {
                    //Есть запись в БД - получаем "Sub" для следующих групп
                    Sub = Convert.ToInt32(query[0].DirNomenID);
                }
                else
                {
                    //Нет записи в БД - создаём новую группу и получаем Sub
                    Models.Sklad.Dir.DirNomen dirNomenGroup = new Models.Sklad.Dir.DirNomen();
                    /*
                    dirNomenGroup.DirNomenID = iMaxGroupID; iMaxGroupID++; // null;
                    if (Sub > 0) dirNomenGroup.Sub = Sub;
                    dirNomenGroup.Del = false;
                    dirNomenGroup.DirNomenName = GroupName;
                    dirNomenGroup.DirNomenNameFull = GroupName;
                    dirNomenGroup.DirNomenTypeID = 1;

                    dirNomenGroup = await Task.Run(() => dirNomensController.mPutPostDirNomen(db, dirNomenGroup, EntityState.Added));
                    */

                    parDirNomenID = new SQLiteParameter("@DirNomenID", System.Data.DbType.Int32) { Value = iMaxGroupID }; 
                    if (Sub > 0) parSub = new SQLiteParameter("@Sub", System.Data.DbType.Int32) { Value = Sub };
                    else parSub = new SQLiteParameter("@Sub", System.Data.DbType.Int32) { Value = null };
                    parDel = new SQLiteParameter("@Del", System.Data.DbType.Boolean) { Value = false };
                    parDirNomenName = new SQLiteParameter("@DirNomenName", System.Data.DbType.String) { Value = GroupName };
                    parDirNomenNameFull = new SQLiteParameter("@DirNomenNameFull", System.Data.DbType.String) { Value = GroupName };
                    parDirNomenTypeID = new SQLiteParameter("@DirNomenTypeID", System.Data.DbType.Int32) { Value = 1 };
                    db.Database.ExecuteSqlCommand("INSERT INTO DirNomens (DirNomenID, Sub, Del, DirNomenName, DirNomenNameFull, DirNomenTypeID)values(@DirNomenID, @Sub, @Del, @DirNomenName, @DirNomenNameFull, @DirNomenTypeID);", parDirNomenID, parSub, parDel, parDirNomenName, parDirNomenNameFull, parDirNomenTypeID);

                    Sub = Convert.ToInt32(iMaxGroupID); //Sub = Convert.ToInt32(dirNomenGroup.DirNomenID);
                    iMaxGroupID++;
                }
            }

            #endregion


            #region  Создаём категорию товара

            //Create Categories in database
            Models.Sklad.Dir.DirNomenCategory dirNomenCategory = await Task.Run(() => CategoriesCreate(DirNomenName));

            #endregion


            #region Создаём Товар
            
            /*
            Models.Sklad.Dir.DirNomen dirNomen = new Models.Sklad.Dir.DirNomen();
            //dirNomen.DirNomenID = null;
            dirNomen.DirNomenID = DirNomenID;
            //dirNomen.DirNomenArticle = DirNomenID.ToString();
            if (Sub > 0) dirNomen.Sub = Sub;
            dirNomen.Del = false;
            dirNomen.DirNomenName = DirNomenName;
            dirNomen.DirNomenNameFull = DirNomenName;
            dirNomen.DirNomenTypeID = 1;
            dirNomen.DirNomenCategoryID = dirNomenCategory.DirNomenCategoryID;
            //dirNomen.IsGoods = true;

            dirNomen = await Task.Run(() => dirNomensController.mPutPostDirNomen(db, dirNomen, EntityState.Added));
            */
            
            //Запись в БД
            parDirNomenID = new SQLiteParameter("@DirNomenID", System.Data.DbType.Int32) { Value = DirNomenID };
            parSub = new SQLiteParameter("@Sub", System.Data.DbType.Int32) { Value = Sub };
            parDel = new SQLiteParameter("@Del", System.Data.DbType.Boolean) { Value = false };
            parDirNomenName = new SQLiteParameter("@DirNomenName", System.Data.DbType.String) { Value = DirNomenName };
            parDirNomenNameFull = new SQLiteParameter("@DirNomenNameFull", System.Data.DbType.String) { Value = DirNomenName };
            parDirNomenTypeID = new SQLiteParameter("@DirNomenTypeID", System.Data.DbType.Int32) { Value = 1 };
            parDirNomenCategoryID = new SQLiteParameter("@DirNomenCategoryID", System.Data.DbType.String) { Value = dirNomenCategory.DirNomenCategoryID };
            db.Database.ExecuteSqlCommand("INSERT INTO DirNomens (DirNomenID, Sub, Del, DirNomenName, DirNomenNameFull, DirNomenTypeID, DirNomenCategoryID)values(@DirNomenID, @Sub, @Del, @DirNomenName, @DirNomenNameFull, @DirNomenTypeID, @DirNomenCategoryID);", parDirNomenID, parSub, parDel, parDirNomenName, parDirNomenNameFull, parDirNomenTypeID, parDirNomenCategoryID);

            #endregion

            //Это не нужно!
            //Sub = Convert.ToInt32(dirNomen.DirNomenID);

            return true;
        }
示例#3
0
        //db, dbRead, sysSetting, docSecondHandRazbor2Tab, EntityState.Added, field
        internal async Task <DocSecondHandRazbor2Tab> mPutPostDocSecondHandRazbor2Tab(
            DbConnectionSklad db,
            DbConnectionSklad dbRead,
            Models.Sklad.Sys.SysSetting sysSetting,
            DocSecondHandRazbor2Tab docSecondHandRazbor2Tab,
            EntityState entityState,          //EntityState.Added, Modified

            Classes.Account.Login.Field field //Дополнительные данные о сотруднике
            )
        {
            //Алгоритм
            //1. DirNomens (ищим: находим (ничего), не находим (новый)) и заполняем DocSecondHandRazbor2Tabs.DirNomenID
            //2. DocSecondHandRazbor2Tabs (сохраняем)
            //3. RemParties (создаём партию)


            #region 1. DirNomens
            //Иищим: находим (ничего), не находим (новый)
            //и заполняем DocSecondHandRazbor2Tabs.DirNomenID

            #region  Категория товара

            if (docSecondHandRazbor2Tab.DirNomenCategoryID == null)
            {
                var queryDirNomenCategoryID = await
                                              (
                    from x in db.DirNomenCategories
                    where x.DirNomenCategoryName == docSecondHandRazbor2Tab.DirNomenCategoryName
                    select x
                                              ).ToListAsync();
                if (queryDirNomenCategoryID.Count() > 0)
                {
                    docSecondHandRazbor2Tab.DirNomenCategoryID   = queryDirNomenCategoryID[0].DirNomenCategoryID;
                    docSecondHandRazbor2Tab.DirNomenCategoryName = queryDirNomenCategoryID[0].DirNomenCategoryName;
                }
                else
                {
                    Models.Sklad.Dir.DirNomenCategory dirNomenCategory = new Models.Sklad.Dir.DirNomenCategory();
                    dirNomenCategory.DirNomenCategoryName = docSecondHandRazbor2Tab.DirNomenCategoryName;

                    db.Entry(dirNomenCategory).State = EntityState.Added;
                    await db.SaveChangesAsync();

                    docSecondHandRazbor2Tab.DirNomenCategoryID   = dirNomenCategory.DirNomenCategoryID;
                    docSecondHandRazbor2Tab.DirNomenCategoryName = dirNomenCategory.DirNomenCategoryName;
                }
            }
            else
            {
                Models.Sklad.Dir.DirNomenCategory dirNomenCategory = await db.DirNomenCategories.FindAsync(docSecondHandRazbor2Tab.DirNomenCategoryID);

                docSecondHandRazbor2Tab.DirNomenCategoryName = dirNomenCategory.DirNomenCategoryName;
            }

            #endregion


            var query = await
                        (
                from x in db.DirNomens
                where x.Sub == docSecondHandRazbor2Tab.DirNomen2ID && x.DirNomenCategoryID == docSecondHandRazbor2Tab.DirNomenCategoryID
                select x
                        ).ToListAsync();
            if (query.Count() > 0)
            {
                docSecondHandRazbor2Tab.DirNomenID = query[0].DirNomenID;
            }
            else
            {
                Models.Sklad.Dir.DirNomen dirNomen = new Models.Sklad.Dir.DirNomen();
                dirNomen.Sub                = docSecondHandRazbor2Tab.DirNomen2ID;
                dirNomen.DirNomenTypeID     = 1;
                dirNomen.DirNomenName       = docSecondHandRazbor2Tab.DirNomenCategoryName;
                dirNomen.DirNomenCategoryID = docSecondHandRazbor2Tab.DirNomenCategoryID;
                dirNomen.DirNomenNameFull   = docSecondHandRazbor2Tab.DirNomenCategoryName;

                db.Entry(dirNomen).State = EntityState.Added;
                await db.SaveChangesAsync();

                docSecondHandRazbor2Tab.DirNomenID = dirNomen.DirNomenID;
            }

            #endregion


            #region 2. DocSecondHandRazbor2Tabs

            db.Entry(docSecondHandRazbor2Tab).State = entityState;
            await db.SaveChangesAsync();

            #endregion


            #region 3. RemParties

            Models.Sklad.Doc.DocSecondHandPurch docSecondHandPurch = await db.DocSecondHandPurches.FindAsync(docSecondHandRazbor2Tab.DocSecondHandPurchID);


            Models.Sklad.Rem.RemParty remParty = new Models.Sklad.Rem.RemParty();
            remParty.RemPartyID    = null;
            remParty.DirNomenID    = Convert.ToInt32(docSecondHandRazbor2Tab.DirNomenID);
            remParty.Quantity      = docSecondHandRazbor2Tab.Quantity;
            remParty.Remnant       = docSecondHandRazbor2Tab.Quantity;
            remParty.DirCurrencyID = docSecondHandRazbor2Tab.DirCurrencyID;
            //remParty.DirCurrencyMultiplicity = docSecondHandRazbor2Tab.DirCurrencyMultiplicity;
            //remParty.DirCurrencyRate = docSecondHandRazbor2Tab.DirCurrencyRate;
            remParty.DirVatValue         = 0;                                                         // docPurch.DirVatValue;
            remParty.DirWarehouseID      = docSecondHandPurch.DirWarehouseID;                         // docPurch.DirWarehouseID;
            remParty.DirWarehouseIDDebit = docSecondHandPurch.DirWarehouseID;                         // docPurch.DirWarehouseID;
            remParty.DirWarehouseIDPurch = Convert.ToInt32(docSecondHandPurch.DirWarehouseIDPurches); // docPurch.DirWarehouseID;
            remParty.DirContractorIDOrg  = docSecondHandPurch.doc.DirContractorIDOrg;

            //!!! Важно !!!
            //if (docSecondHandRazbor2Tab.DirContractorID != null) remParty.DirContractorID = Convert.ToInt32(docSecondHandRazbor2Tab.DirContractorID);
            //else remParty.DirContractorID = docSecondHandPurch.DirContractorID;
            remParty.DirContractorID = docSecondHandPurch.doc.DirContractorIDOrg;
            //!!! Важно !!!

            //Дата Приёмки товара
            remParty.DocDatePurches = docSecondHandPurch.doc.DocDate;

            remParty.DirCharColourID   = docSecondHandRazbor2Tab.DirCharColourID;
            remParty.DirCharMaterialID = docSecondHandRazbor2Tab.DirCharMaterialID;
            remParty.DirCharNameID     = docSecondHandRazbor2Tab.DirCharNameID;
            remParty.DirCharSeasonID   = docSecondHandRazbor2Tab.DirCharSeasonID;
            remParty.DirCharSexID      = docSecondHandRazbor2Tab.DirCharSexID;
            remParty.DirCharSizeID     = docSecondHandRazbor2Tab.DirCharSizeID;
            remParty.DirCharStyleID    = docSecondHandRazbor2Tab.DirCharStyleID;
            remParty.DirCharTextureID  = docSecondHandRazbor2Tab.DirCharTextureID;

            remParty.SerialNumber = docSecondHandRazbor2Tab.SerialNumber;
            remParty.Barcode      = docSecondHandRazbor2Tab.Barcode;

            remParty.DocID         = Convert.ToInt32(docSecondHandPurch.DocID);
            remParty.PriceCurrency = docSecondHandRazbor2Tab.PriceCurrency;
            remParty.PriceVAT      = docSecondHandRazbor2Tab.PriceVAT;
            remParty.FieldID       = Convert.ToInt32(docSecondHandRazbor2Tab.DocSecondHandRazbor2TabID);

            remParty.PriceRetailVAT         = docSecondHandRazbor2Tab.PriceRetailVAT;
            remParty.PriceRetailCurrency    = docSecondHandRazbor2Tab.PriceRetailCurrency;
            remParty.PriceWholesaleVAT      = docSecondHandRazbor2Tab.PriceWholesaleVAT;
            remParty.PriceWholesaleCurrency = docSecondHandRazbor2Tab.PriceWholesaleCurrency;
            remParty.PriceIMVAT             = docSecondHandRazbor2Tab.PriceIMVAT;
            remParty.PriceIMCurrency        = docSecondHandRazbor2Tab.PriceIMCurrency;

            //DirNomenMinimumBalance
            remParty.DirNomenMinimumBalance = sysSetting.DirNomenMinimumBalance;

            remParty.DirEmployeeID = docSecondHandPurch.doc.DirEmployeeID;
            remParty.DocDate       = docSecondHandPurch.doc.DocDate;


            db.Entry(remParty).State = EntityState.Added;
            await db.SaveChangesAsync();


            #endregion


            #region 3. Лог: Пишем в Лог о смене статуса и мастера, если такое было

            logService.DocSecondHandPurchID   = docSecondHandRazbor2Tab.DocSecondHandPurchID;
            logService.DirSecondHandLogTypeID = 6; //Смена статуса
            logService.DirEmployeeID          = field.DirEmployeeID;
            //logService.DirSecondHandStatusID = DirSecondHandStatusID;
            logService.Msg = "Разборка: добавили запчасть: " + docSecondHandRazbor2Tab.dirNomen.DirNomenName;

            await logServicesController.mPutPostLogSecondHands(db, logService, EntityState.Added);

            #endregion


            return(docSecondHandRazbor2Tab);
        }