Example #1
0
        public static NormaContent rebuildNormaContent(NormaContent inNormaContent)
        {
            NormaContent normaContent = new NormaContent(inNormaContent.Id, inNormaContent.Quantity, inNormaContent.UsePeriod);

            normaContent.NormaId  = inNormaContent.NormaId;
            normaContent.IsActive = inNormaContent.IsActive;
//            if (inNormaContent.QuantityTON != 0)
            normaContent.QuantityTON = inNormaContent.QuantityTON;
//            else
//                normaContent.QuantityTON = inNormaContent.Quantity;
            NomGroup nomGroup = rebuildNomGroup(inNormaContent.NomGroup);

            normaContent.NomGroup = nomGroup;
            normaContent.InShop   = inNormaContent.InShop;
            List <NormaNomGroup> normaNomGroups = new List <NormaNomGroup>();

            foreach (var item in inNormaContent.NormaNomGroups)
            {
                NormaNomGroup normaNomGroup = rebuildNormaNomGroup(item);
                normaNomGroups.Add(normaNomGroup);
            }
            normaContent.NormaNomGroups = normaNomGroups;
            string normaContentInfo = "";

            foreach (var item in normaContent.NormaNomGroups)
            {
                if (item.IsBase == false)
                {
                    normaContentInfo = normaContentInfo + item.NomGroup.Name + "; ";
                }
            }
            normaContent.NormaContentInfo = normaContentInfo;
            return(normaContent);
        }
Example #2
0
        public ActionResult Copy(string Id)
        {
            Norma norma    = normaRepository.Get(int.Parse(Id));
            Norma newNorma = new Norma();

            newNorma.Organization = norma.Organization;
            newNorma.Name         = norma.Name + " (Копия)";
            newNorma.IsActive     = norma.IsActive;
            newNorma.NormaComment = norma.NormaComment;
            normaRepository.SaveOrUpdate(newNorma);

            Dictionary <string, object> queryParams = new Dictionary <string, object>();

            queryParams.Add("NormaId", int.Parse(Id));
            queryParams.Add("IsActive", true);
            Dictionary <string, object> orderParams = new Dictionary <string, object>();

            orderParams.Add("Id", ASC);
            IEnumerable <NormaContent> normaContents = normaContentRepository.GetByCriteria(queryParams, orderParams);

            foreach (var item in normaContents)
            {
                NormaContent nc = new NormaContent();
                nc.Quantity    = item.Quantity;
                nc.QuantityTON = item.QuantityTON;
                nc.UsePeriod   = item.UsePeriod;
                nc.IsActive    = item.IsActive;
                nc.NormaId     = newNorma.Id;
                nc.NomGroup    = item.NomGroup;
                nc.InShop      = item.InShop;
                normaContentRepository.SaveOrUpdate(nc);
                foreach (var nng in item.NormaNomGroups)
                {
                    NomGroup     nomGroup = new NomGroup(nng.NomGroup.Id, nng.NomGroup.Name);
                    NomBodyPart  nb       = new NomBodyPart(nng.NomGroup.NomBodyPart.Id, nng.NomGroup.NomBodyPart.Name);
                    Organization o        = rebuildOrganization(nng.NomGroup.Organization);
                    nomGroup.Organization = o;
                    nomGroup.NomBodyPart  = nb;
                    NormaNomGroup ng = new NormaNomGroup();
                    ng.NomGroup     = nomGroup;
                    ng.IsBase       = nng.IsBase;
                    ng.NormaContent = nc;

                    normaNomGroupRepository.SaveOrUpdate(ng);
                }
            }
            ;
            return(View(viewName));
//            return _SelectionClientSide_Normas();
        }
Example #3
0
        public static NomGroup rebuildNomGroup(NomGroup inNomGroup, List <string> excludeProperty)
        {
            NomGroup nomGroup = new NomGroup(inNomGroup.Id, inNomGroup.Name);

            nomGroup.IsWinter     = inNomGroup.IsWinter;
            nomGroup.ExternalCode = inNomGroup.ExternalCode;
            nomGroup.IsActive     = inNomGroup.IsActive;
            if (inNomGroup.Organization != null)
            {
                if (!isExclude(excludeProperty, "Organization"))
                {
                    nomGroup.Organization = rebuildOrganizationSimple(inNomGroup.Organization, rebuildExcludeProperty(excludeProperty, "Organization"));
                }
            }
            if (inNomGroup.Organization != null)
            {
                if (!isExclude(excludeProperty, "NomBodyPart"))
                {
                    nomGroup.NomBodyPart = rebuildNomBodyPart(inNomGroup.NomBodyPart);
                }
            }
            nomGroup.NameOT = inNomGroup.NameOT;
            return(nomGroup);
        }
Example #4
0
 public static NomGroup rebuildNomGroup(NomGroup inNomGroup)
 {
     return(rebuildNomGroup(inNomGroup, null));
 }
Example #5
0
        public ActionResult Save(int selectType, int PriceLoadList, IEnumerable <HttpPostedFileBase> attachments)
        {
            HttpResponseBase response = ControllerContext.HttpContext.Response;

            response.ContentType = "text/html";
            response.Write("<html><body>");
            if (attachments == null)
            {
                response.Write("Файл для загрузки не выбран!");
            }
            else
            {
                int          idOrg       = int.Parse(getCurrentEnterpriseId());
                Organization currentOrg  = organizationRepository.Get(idOrg);
                PeriodPrice  periodPrice = periodPriceRepository.Get(PriceLoadList);
                if (selectType == 1)
                {
                    nomGroupPriceRepository.TruncNomGroupPrice(idOrg, PriceLoadList);
                }
                foreach (var file in attachments)
                {
                    // Some browsers send file names with full path. This needs to be stripped.
                    var isError  = false;
                    var fileName = Path.GetFileName(file.FileName);
                    response.Write("Обрабатывается файл <b>" + fileName + "</b><br/>");
                    response.Flush();
                    var physicalFilePath = Path.Combine(Server.MapPath("~/TempFiles"), fileName);
                    try
                    {
                        if (System.IO.File.Exists(physicalFilePath))
                        {
                            System.IO.File.Delete(physicalFilePath);
                        }
                        try
                        {
                            file.SaveAs(physicalFilePath);
                        }
                        catch (Exception e)
                        {
                            response.Write("Ошибка при охранении файла на сервере:<br/>");
                            response.Write(e.Message);
                            response.Flush();
                            isError = true;
                        }
                        System.Data.DataTable table = null;
                        string workSheetNames       = "";
                        if (!isError)
                        {
                            try
                            {
                                ExcelReader excelReader = new ExcelReader(physicalFilePath, true);
                                if (excelReader.workSheetNames.Length > 0)
                                {
                                    workSheetNames = excelReader.workSheetNames[0];
                                    table          = excelReader.GetWorksheet(workSheetNames);
                                }
                                else
                                {
                                    response.Write("В файле не найден рабочий лист!<br/>");
                                    response.Flush();
                                    isError = true;
                                }
                            }
                            catch (Exception e)
                            {
                                response.Write("Ошибка при открытии файла:<br/>");
                                response.Write(e.Message);
                                response.Flush();
                                isError = true;
                            }
                        }
                        if (table != null)
                        {
                            response.Write("Загрузка данных производится из листа '" + workSheetNames.Trim(new[] { '$' }) + "'<br/>");
                            response.Flush();
                            if (!table.Columns.Contains("Цена"))
                            {
                                response.Write("Файл содержит не коррекные данные ('Цена').<br/>");
                                response.Flush();
                                isError = true;
                            }
                            if (!table.Columns.Contains("Код группы"))
                            {
                                response.Write("Файл содержит не коррекные данные ('Код группы').<br/>");
                                response.Flush();
                                isError = true;
                            }

                            int colPrice        = table.Columns.IndexOf("Цена");
                            int colExternalCode = table.Columns.IndexOf("Код группы");

                            if (!isError)
                            {
                                DataRow[] result = table.Select();
                                Dictionary <string, object> queryParams = new Dictionary <string, object>();
                                foreach (DataRow row in result) // Loop over the rows.
                                {
                                    if (row[colExternalCode] != System.DBNull.Value)
                                    {
                                        string rowExternalCode = Convert.ToString(row[colExternalCode]);
                                        try
                                        {
                                            string rowPriceString = Convert.ToString(row[colPrice]);
                                            double rowPrice       = Convert.ToDouble(rowPriceString);
                                            queryParams.Clear();
                                            queryParams.Add("Organization", currentOrg);
                                            queryParams.Add("ExternalCode", rowExternalCode);
                                            NomGroup ng = nomGroupRepository.FindOne(queryParams);
                                            if (ng == null)
                                            {
                                                response.Write("В справочнике не найдена группа номенклатур с кодом " + rowExternalCode + ".<br/>");
                                                response.Flush();
                                            }
                                            else
                                            {
                                                NomGroupPrice nPrice = null;
                                                queryParams.Clear();
                                                queryParams.Add("OrganizationId", currentOrg.Id);
                                                queryParams.Add("NomGroup", ng);
                                                queryParams.Add("PeriodPrice", periodPrice);
                                                nPrice = nomGroupPriceRepository.FindOne(queryParams);
                                                if (nPrice == null)
                                                {
                                                    nPrice                = new NomGroupPrice();
                                                    nPrice.NomGroup       = ng;
                                                    nPrice.OrganizationId = currentOrg.Id;
                                                    nPrice.PeriodPrice    = periodPrice;
                                                    nPrice.ExternalCode   = ng.ExternalCode;
                                                }

                                                nPrice.Price = rowPrice;
                                                nomGroupPriceRepository.DbContext.BeginTransaction();
                                                try
                                                {
                                                    nomGroupPriceRepository.SaveOrUpdate(nPrice);
                                                    nomGroupPriceRepository.DbContext.CommitTransaction();
                                                }
                                                catch (Exception e)
                                                {
                                                    nomGroupPriceRepository.DbContext.RollbackTransaction();
                                                    response.Write("Ошибка при сохранении данных в БД:<br/>");
                                                    response.Write(e.Message);
                                                    response.Write("<br/>");
                                                    if (e.InnerException != null)
                                                    {
                                                        response.Write(e.InnerException.Message);
                                                        response.Write("<br/>");
                                                    }
                                                    response.Flush();
                                                }
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            response.Write("Ошибка определения цены для номклатуры " + rowExternalCode + "<br/>");
                                            response.Flush();
                                        }
                                    }
                                }
                                response.Flush();
                            }
                            response.Flush();
                        }
                        if (!isError)
                        {
                            response.Write("Файл успешно обработан!");
                        }
                    }
                    finally
                    {
                        System.IO.File.Delete(physicalFilePath);
                    }
                }
            }
            Response.Write("</html></body>");
            Response.Flush();
            return(null);;
        }
Example #6
0
        public List <COMING_SAP> GetInvoice(Organization currentOrganization, StorageName currentStorage, ICriteriaRepository <Nomenclature> nomenRepository, ICriteriaRepository <NomGroup> nomGroupRepository, int DocTypeId, string docNumber, int docYear, string docDate, out string Message)
        {
            String            INCOMING_RFC = ConfigurationManager.AppSettings["SAP_ERP_" + currentOrganization.Id];
            RfcDestination    destination  = RfcDestinationManager.GetDestination(INCOMING_RFC);
            IRfcFunction      function     = null;
            List <COMING_SAP> list         = new List <COMING_SAP>();

//            string docDate = "01.01." + docYear;
            docDate = "01.01." + docYear;

            if (currentStorage == null)
            {
                currentStorage = new StorageName();
            }
            try
            {
                function = destination.Repository.CreateFunction("BAPI_GOODSMVT_GETDETAIL");

                function.SetValue("MATERIALDOCUMENT", docNumber);
                function.SetValue("MATDOCUMENTYEAR", docYear);
                function.Invoke(destination);
            }
            catch (RfcBaseException e)
            {
                Message = e.StackTrace;
                //                Console.WriteLine(e.ToString());
            }
            Dictionary <string, Nomenclature> MaterialName          = new Dictionary <string, Nomenclature>();
            Dictionary <string, string>       NomenclatureGroupName = new Dictionary <string, string>();

            Message = "OK";
            IRfcStructure tableHeader = function.GetStructure("GOODSMVT_HEADER");

            if (tableHeader.Count > 0)
            {
                if (tableHeader.GetString("DOC_DATE") != "0000-00-00")
                {
                    docDate = tableHeader.GetString("DOC_DATE");
                    try
                    {
                        docDate = DateTime.ParseExact(docDate, "yyyy-MM-dd", new System.Globalization.CultureInfo("ru-RU", true)).ToString(DataGlobals.DATE_FORMAT_FULL_YEAR);
                    }
                    catch
                    {
                    }
                }
            }
            IRfcTable table = function.GetTable("GOODSMVT_ITEMS");

            if (table.RowCount == 0)
            {
                IRfcTable retTable = function.GetTable("RETURN");
                retTable.CurrentIndex = 0;
                Message = retTable.GetString("MESSAGE");
            }
            else
            {
                for (int i = 0; i < table.RowCount; i++)
                {
                    table.CurrentIndex = i;
                    if ((table.GetString("PLANT") == "" + currentStorage.Plant) && (table.GetString("STGE_LOC") == "" + currentStorage.Externalcode))
                    {
                        //if (getKnownMove(table.GetString("MOVE_TYPE"), currentStorage) != MoveType.Unknown)
                        //{
                        COMING_SAP incomingSap = new COMING_SAP(i + 1);
                        incomingSap.DocTypeId = DocTypeId;
                        incomingSap.DocNumber = docNumber;
                        //incomingSap.DocDate = "01.01." + docYear;
                        incomingSap.DocDate    = docDate;
                        incomingSap.MaterialId = table.GetString("MATERIAL").TrimStart('0');
                        Nomenclature defValue = null;
                        if (MaterialName.TryGetValue(incomingSap.MaterialId, out defValue))
                        {
                            incomingSap.MATERIAL     = defValue.Name;
                            incomingSap.ExternalCode = defValue.ExternalCode;
                            if (defValue.Growth != null)
                            {
                                incomingSap.GrowthId   = defValue.Growth.Id;
                                incomingSap.GrowthName = defValue.Growth.SizeNumber;
                            }
                            if (defValue.NomBodyPartSize != null)
                            {
                                incomingSap.SizeId   = defValue.NomBodyPartSize.Id;
                                incomingSap.SizeName = defValue.NomBodyPartSize.SizeNumber;
                            }
                            if (defValue.NomGroup != null)
                            {
                                incomingSap.NomGroupId   = defValue.NomGroup.Id;
                                incomingSap.NomGroupName = defValue.NomGroup.Name;
                                incomingSap.IsWinter     = defValue.NomGroup.IsWinter;
                            }
                            if (defValue.Sex != null)
                            {
                                incomingSap.SexId   = defValue.Sex.Id;
                                incomingSap.SexName = defValue.Sex.Name;
                            }
                            if (defValue.Unit != null)
                            {
                                incomingSap.UnitId   = defValue.Unit.Id;
                                incomingSap.UnitName = defValue.Unit.Name;
                            }
                            if (defValue.NomBodyPart != null)
                            {
                                incomingSap.NomBodyPartId   = defValue.NomBodyPart.Id;
                                incomingSap.NomBodyPartName = defValue.NomBodyPart.Name;
                            }
                        }
                        else
                        {
                            Dictionary <string, object> queryParams = new Dictionary <string, object>();
                            queryParams.Add("Organization", currentOrganization);
                            queryParams.Add("ExternalCode", incomingSap.MaterialId.TrimStart('0'));
                            queryParams.Add("IsActive", true);
                            //                                Nomenclature currentNomenclature = nomenRepository.FindOne(queryParams);
                            IList <Nomenclature> currentNomenclatures = nomenRepository.GetByLikeCriteria(queryParams);
                            Nomenclature         currentNomenclature  = null;
                            if (currentNomenclatures.Count > 0)
                            {
                                currentNomenclature = currentNomenclatures[0];
                            }
                            if (currentNomenclature != null)
                            {
                                // TODO: Требуется обновить группу номенклатуры из SAP?
                                defValue                 = currentNomenclature;
                                incomingSap.MATERIAL     = defValue.Name;
                                incomingSap.ExternalCode = defValue.ExternalCode;
                                if (defValue.NomGroup != null)
                                {
                                    incomingSap.NomGroupId   = defValue.NomGroup.Id;
                                    incomingSap.NomGroupName = defValue.NomGroup.Name;
                                    incomingSap.IsWinter     = defValue.NomGroup.IsWinter;
                                }
                                if (defValue.Sex != null)
                                {
                                    incomingSap.SexId   = defValue.Sex.Id;
                                    incomingSap.SexName = defValue.Sex.Name;
                                }
                                if (defValue.Unit != null)
                                {
                                    incomingSap.UnitId   = defValue.Unit.Id;
                                    incomingSap.UnitName = defValue.Unit.Name;
                                }
                                if (defValue.NomBodyPart != null)
                                {
                                    incomingSap.NomBodyPartId   = defValue.NomBodyPart.Id;
                                    incomingSap.NomBodyPartName = defValue.NomBodyPart.Name;
                                }
                            }
                            else
                            {
                                //Группу из сапа пока не запрашиваю!!!!

                                /*                                defValue = getMaterialName(destination, incomingSap.MaterialId);
                                 *                              if (NomenclatureGroupName.TryGetValue(incomingSap.NomrnclatureGroupId, out defStringValue))
                                 *                              {
                                 *                                  incomingSap.NomrnclatureGroupName = defStringValue;
                                 *                              }
                                 *                              else
                                 *                              {
                                 *                                  defStringValue = getNomenclatureGroupName(destination, incomingSap.NomrnclatureGroupId);
                                 *                                  incomingSap.NomrnclatureGroupName = defStringValue;
                                 *                                  NomenclatureGroupName.Add(incomingSap.NomrnclatureGroupId, defStringValue);
                                 *                              }*/
                                if (Message == "OK")
                                {
                                    Message = "";
                                }
                                defValue = new Nomenclature(int.Parse(incomingSap.MaterialId));
                                String[] strArray = getMaterialName(destination, table.GetString("MATERIAL"));
                                defValue.Name         = strArray[0];
                                defValue.ExternalCode = strArray[1].TrimStart('0');
                                Message = Message + "Номенклатура: [" + incomingSap.MaterialId + "]" + defValue.Name + "не найдена.\n";
                                incomingSap.MATERIAL     = defValue.Name;
                                incomingSap.ExternalCode = incomingSap.MaterialId;
                                queryParams.Clear();
                                queryParams.Add("Organization", currentOrganization);
                                queryParams.Add("ExternalCode", strArray[1].TrimStart('0'));
                                NomGroup nGroup = nomGroupRepository.FindOne(queryParams);
                                if (nGroup != null)
                                {
                                    incomingSap.NomGroupId      = nGroup.Id;
                                    incomingSap.NomGroupName    = nGroup.Name;
                                    incomingSap.IsWinter        = nGroup.IsWinter;
                                    incomingSap.NomBodyPartId   = nGroup.NomBodyPart.Id;
                                    incomingSap.NomBodyPartName = nGroup.NomBodyPart.Name;
                                }
                                incomingSap.SAPNomGroupId   = strArray[1].TrimStart('0');
                                incomingSap.SAPNomGroupName = getNomenclatureGroupName(destination, strArray[1]);
                                defValue.NomGroup           = nGroup;
                            }
                            if (defValue != null)
                            {
                                MaterialName.Add(incomingSap.MaterialId, defValue);
                            }
                        }

                        incomingSap.QUANTITY = (int)Math.Truncate(table.GetDouble("ENTRY_QNT"));
                        incomingSap.UOM      = table.GetString("ENTRY_UOM");
                        incomingSap.LC       = table.GetString("AMOUNT_LC");
                        incomingSap.SV       = table.GetString("AMOUNT_SV");
                        incomingSap.MoveType = table.GetString("MOVE_TYPE");
                        //NomenclatureInfo nInfo = getMaterialDetail(destination, incomingSap.MaterialId);
                        list.Add(incomingSap);
                        //}
                        //else {
                        //    Message = table.GetString("MOVE_TYPE") + " вид движения не поддерживается!";
                        //}
                    }
                }
            }
            return(list);
        }