Пример #1
0
        public static RemaindExternal rebuildRemaindExternal(RemaindExternal inRemaind, List <string> excludeProperty)
        {
            RemaindExternal r = null;

            if (inRemaind != null)
            {
                r = new RemaindExternal(inRemaind.Id);
                if (!isExclude(excludeProperty, "RemaindDate"))
                {
                    r.RemaindDate = inRemaind.RemaindDate;
                }
                if (!isExclude(excludeProperty, "Storage"))
                {
                    r.Storage = rebuildStorage(inRemaind.Storage, rebuildExcludeProperty(excludeProperty, "Storage"));
                }
                if (!isExclude(excludeProperty, "StorageName"))
                {
                    r.StorageName = rebuildStorageName(inRemaind.StorageName, rebuildExcludeProperty(excludeProperty, "StorageName"));
                }

                if (!isExclude(excludeProperty, "Nomenclature"))
                {
                    r.Nomenclature = rebuildNomenclature(inRemaind.Nomenclature, rebuildExcludeProperty(excludeProperty, "Nomenclature"));
                }

                if (!isExclude(excludeProperty, "Growth"))
                {
                    r.Growth = rebuildNomBodyPartSize(inRemaind.Growth, rebuildExcludeProperty(excludeProperty, "Growth"));
                }

                if (!isExclude(excludeProperty, "NomBodyPartSize"))
                {
                    r.NomBodyPartSize = rebuildNomBodyPartSize(inRemaind.NomBodyPartSize, rebuildExcludeProperty(excludeProperty, "NomBodyPartSize"));
                }
                r.Wear        = inRemaind.Wear;
                r.Quantity    = inRemaind.Quantity;
                r.QuantityIn  = inRemaind.QuantityIn;
                r.QuantityOut = inRemaind.QuantityOut;
            }
            return(r);
        }
Пример #2
0
 public static RemaindExternal rebuildRemaindExternal(RemaindExternal inRemain)
 {
     return(rebuildRemaindExternal(inRemain, null));
 }
Пример #3
0
        public ActionResult Save(string date, int StorageList, IEnumerable <HttpPostedFileBase> attachments)
        {
            int messCount = 0;

            if (attachments == null)
            {
                Session.Add("messRow" + messCount.ToString(), "Файл для загрузки не выбран");
                messCount++;
            }
            else
            {
                remaindExternalRepository.DbContext.BeginTransaction();
                // The Name of the Upload component is "attachments"
                IFormatProvider culture     = new System.Globalization.CultureInfo("ru-RU", true);
                string          format      = "dd.MM.yyyy";
                DateTime        paramDate   = DateTime.ParseExact(date, format, culture);
                StorageName     storageName = storageNameRepository.Get(StorageList);
                remaindExternalRepository.TruncRemainExternal(StorageList, date);
                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);
                    Session.Add("messRow" + messCount.ToString(), "Обрабатывается файл " + fileName);
                    messCount++;
                    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)
                        {
                            Session.Add("messRow" + messCount.ToString(), "Ошибка при охранении файла на сервере:");
                            messCount++;
                            Session.Add("messRow" + messCount.ToString(), e.Message);
                            messCount++;
                            isError = true;
                        }
                        System.Data.DataTable table = null;
                        if (!isError)
                        {
                            try
                            {
                                ExcelReader excelReader = new ExcelReader(physicalFilePath);
                                table = excelReader.GetWorksheet(excelReader.workSheetNames[0]);
                            }
                            catch (Exception e)
                            {
                                Session.Add("messRow" + messCount.ToString(), "Ошибка при открытии файла:");
                                messCount++;
                                Session.Add("messRow" + messCount.ToString(), e.Message);
                                messCount++;
                                isError = true;
                            }
                        }
                        if (table != null)
                        {
                            try
                            {
                                DataRow[] result = table.Select("F2 = '*' and F3=" + storageName.Plant + " and F4 in (" + storageName.StorageNumber + ")");
                                Dictionary <string, object> queryParams = new Dictionary <string, object>();
                                foreach (DataRow row in result) // Loop over the rows.
                                {
                                    if (row[4] != System.DBNull.Value)
                                    {
                                        queryParams.Clear();
                                        queryParams.Add("Organization", storageName.Organization);
                                        queryParams.Add("ExternalCode", (string)row[4]);
                                        Nomenclature    nomenclature = nomenclatureRepository.FindOne(queryParams);
                                        RemaindExternal remExt       = new RemaindExternal();
                                        remExt.ActualDate   = DateTime.Now;
                                        remExt.RemaindDate  = paramDate;
                                        remExt.StorageName  = storageName;
                                        remExt.Nomenclature = nomenclature;
                                        remExt.Wear         = 100;
                                        String wear = (string)row[4];
                                        if ((wear.ToUpper(System.Globalization.CultureInfo.CurrentCulture) == "БУ") ||
                                            (wear.ToUpper(System.Globalization.CultureInfo.CurrentCulture) == "Б/У"))
                                        {
                                            remExt.Wear = 50;
                                        }
                                        remExt.ExternalCode = (string)row[4];
                                        int cnt = 0;
                                        if (row[11] != System.DBNull.Value)
                                        {
                                            int.TryParse((string)row[11], out cnt);
                                        }
                                        remExt.QuantityIn = cnt;
                                        cnt = 0;
                                        if (row[12] != System.DBNull.Value)
                                        {
                                            int.TryParse((string)row[12], out cnt);
                                        }
                                        remExt.QuantityOut = cnt;
                                        cnt = 0;
                                        if (row[13] != System.DBNull.Value)
                                        {
                                            int.TryParse((string)row[13], out cnt);
                                        }
                                        remExt.Quantity = cnt;
                                        remaindExternalRepository.SaveOrUpdate(remExt);
                                    }
                                }
                                Session.Add("messRow" + messCount.ToString(), "Обработано " + result.Length + " записей.");
                                messCount++;
                            }
                            catch (Exception e)
                            {
                                Session.Add("messRow" + messCount.ToString(), "Ошибка сохранении данных в БД:");
                                messCount++;
                                Session.Add("messRow" + messCount.ToString(), e.Message);
                                messCount++;
                                isError = true;
                            }
                        }
                        if (!isError)
                        {
                            remaindExternalRepository.DbContext.CommitTransaction();
                            Session.Add("messRow" + messCount.ToString(), "Файл успешно обработан");
                            messCount++;
                        }
                        else
                        {
                            remaindExternalRepository.DbContext.RollbackTransaction();
                        }
                    }
                    finally
                    {
                        System.IO.File.Delete(physicalFilePath);
                    }
                }
            }
            Session.Add("row_count", messCount.ToString());
            return(RedirectToAction("Index"));
        }