예제 #1
0
파일: Form1.cs 프로젝트: Alp4ka/Storage
 /// <summary>
 /// Нажатие на кнопку добавить.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void addButton_Click(object sender, EventArgs e)
 {
     try
     {
         var selectedNode = storageTree.SelectedNode;
         if (selectedNode != null)
         {
             var pcv = new ProductCardView();
             pcv.ShowDialog();
             Product pr = pcv.Result;
             if (pr == null)
             {
                 return;
             }
             var array = pr.GetArray();
             var row   = new ProductRow();
             row.Product = pr;
             row.CreateCells(dataGrid);
             for (int j = 0; j < array.Length; ++j)
             {
                 row.Cells[j].Value = array[j];
             }
             dataGrid.Rows.Add(row);
             Storage.Products.Add(pr);
             ((StorageNode)selectedNode).Cathegory.Products.Add(pr);
             SuperSmartCsvManager.WriteToCsv((StorageNode)selectedNode);
         }
     }
     catch
     {
     }
 }
예제 #2
0
 private static DeliveryProductMailerModel GetProductModel(ProductRow p, ModificationKind rowKind)
 {
     return(new DeliveryProductMailerModel()
     {
         Name = p.Name,
         Quantity = p.Quantity,
         Reference = p.Reference,
         Conditioning = p.GetConditioning(),
         RowKind = rowKind,
         Vat = p.Vat,
         ProductTotalVatPrice = p.TotalProductVatPrice,
         ProductTotalWholeSalePrice = p.TotalProductWholeSalePrice,
         ProductTotalOnSalePrice = p.TotalProductOnSalePrice,
         ProductWholeSalePrice = p.UnitWholeSalePrice,
         HasReturnable = p.HasReturnable,
         ReturnableName = p.ReturnableName,
         ReturnableQuantity = p.Quantity,
         ReturnableVat = p.ReturnableVat,
         ReturnableWholeSalePrice = p.ReturnableWholeSalePrice,
         ReturnableTotalVatPrice = p.TotalReturnableVatPrice,
         ReturnableTotalOnSalePrice = p.TotalReturnableOnSalePrice,
         ReturnableTotalWholeSalePrice = p.TotalReturnableWholeSalePrice,
         TotalVatPrice = p.TotalVatPrice,
         TotalOnSalePrice = p.TotalOnSalePrice,
         TotalWholeSalePrice = p.TotalWholeSalePrice
     });
 }
예제 #3
0
        private static void RenderActionCell(ProductRow row, float width)
        {
            var completed = row.CurrentVersion.IsCompleted &&
                            !row.CurrentVersion.HasErrors &&
                            row.AllBuilds.IsCompleted &&
                            !row.AllBuilds.HasErrors;

            var oldEnabled = GUI.enabled;

            GUI.enabled = oldEnabled && row.AllBuilds.IsCompleted && !row.AllBuilds.HasErrors && row.AllBuilds.GetResult() != null && row.SelectedVersion != null;
            if (completed)
            {
                var actions = new List <string>();
                for (var i = 0; i < Actions.Length; i++)
                {
                    if ((row.ActionMask & (1 << i)) != 0)
                    {
                        actions.Add(Actions[i]);
                    }
                }
                if (actions.Count == 0)
                {
                    actions.Add(ACTION_SKIP);
                }
                var actionIndex = EditorGUILayout.Popup(actions.IndexOf(row.Action), actions.ToArray(), GUILayout.Width(width));
                if (actionIndex < 0)
                {
                    actionIndex = 0;
                }
                row.Action = actions[actionIndex];
            }
            GUI.enabled = oldEnabled;
        }
예제 #4
0
 private Action <string, float> GetProgressReportFor(ProductRow row, int number, int total)
 {
     return((msg, progress) =>
     {
         this.updateStatus = string.Format("{0} [{1}/{2}]: {3} ({4:F2}%)", row.Name, number, total, msg, progress * 100);
         this.Repaint();
     });
 }
            public ProductRow AddProductRow(string PorductName, int Weight)
            {
                ProductRow rowProductRow = ((ProductRow)(this.NewRow()));

                rowProductRow.ItemArray = new object[] {
                    null,
                    PorductName,
                    Weight
                };
                this.Rows.Add(rowProductRow);
                return(rowProductRow);
            }
            public ProductRow AddProductRow(string PorductName, int Weight)
            {
                ProductRow rowProductRow = ((ProductRow)(this.NewRow()));

                object[] columnValuesArray = new object[] {
                    PorductName,
                    null,
                    Weight
                };
                rowProductRow.ItemArray = columnValuesArray;
                this.Rows.Add(rowProductRow);
                return(rowProductRow);
            }
예제 #7
0
 private static DeliveryReturnableMailerModel GetReturnableModel(ProductRow product, ModificationKind rowKind)
 {
     return(new DeliveryReturnableMailerModel()
     {
         Name = product.ReturnableName,
         Quantity = product.Quantity,
         RowKind = rowKind,
         Vat = product.ReturnableVat ?? 0,
         TotalVatPrice = product.TotalReturnableVatPrice ?? 0,
         TotalWholeSalePrice = product.TotalReturnableWholeSalePrice ?? 0,
         TotalOnSalePrice = product.TotalReturnableOnSalePrice ?? 0,
         WholeSalePrice = product.ReturnableWholeSalePrice ?? 0
     });
 }
예제 #8
0
        public SaveResponse Create(IUnitOfWork uow, SaveRequest <MyRow> request)
        {
            var regist = MyRow.Fields;
            var mater  = ProductRow.Fields;
            var objeto = request.Entity;

            var product = uow.Connection.TryFirst <ProductRow>(q => q
                                                               .Select(mater.ProductID, mater.UnitsInStock, mater.UnitPrice)
                                                               .Where(mater.ProductID == Convert.ToString(objeto.ProductId)));

            if (product == null)
            {
                product = new ProductRow
                {
                }
            }
            ;
            else
            {
                product.TrackWithChecks = false;
            }


            if (product.UnitsInStock == objeto.CantidadAMuestrear)
            {
                objeto.CantidadContada = 0;
            }
            else
            {
                objeto.CantidadContada     = (product.UnitsInStock - objeto.CantidadAMuestrear);
                objeto.DesviacionEconomica = (objeto.CantidadContada * product.UnitPrice);
            }



            /* var objetoo = request.Entity;
             *
             *
             * if (objetoo.CantidadAMuestrear < objetoo.CantidadContada)
             * {
             *   throw new ValidationError("La cantidad contada no puede ser");
             * }
             * else
             * {
             *
             * }*/
            return(new MySaveHandler().Process(uow, request, SaveRequestType.Create));
        }
예제 #9
0
        private static void RenderCurrentVersionCell(ProductRow row, float width)
        {
            var promise = row.CurrentVersion;

            if (promise.IsCompleted == false)
            {
                GUILayout.Label(Resources.UI_UNITYPLUGIN_WINDOW_UPDATE_CHECKING_MESSAGE, GUILayout.Width(width));
            }
            else if (promise.HasErrors)
            {
                GUILayout.Label(Resources.UI_UNITYPLUGIN_WINDOW_UPDATE_ERROR_MESSAGE, GUILayout.Width(width));
            }
            else
            {
                GUILayout.Label(Convert.ToString(promise.GetResult()), GUILayout.Width(width));
            }
        }
예제 #10
0
 private static void RenderSelectedVersionCell(ProductRow row, float width)
 {
     if (row.SelectedVersion != null)
     {
         if ((row.Action == ACTION_DOWNLOAD || row.Action == ACTION_UPDATE) && row.AllVersions != null)
         {
             var versionNames    = Array.ConvertAll(row.AllVersions, v => v.ToString());
             var selectedVersion = Array.IndexOf(row.AllVersions, row.SelectedVersion);
             if (selectedVersion < 0)
             {
                 selectedVersion = 0;
             }
             selectedVersion = EditorGUILayout.Popup(selectedVersion, versionNames, GUILayout.Width(width));
             if (selectedVersion < 0)
             {
                 selectedVersion = 0;
             }
             row.SelectedVersion = row.AllVersions[selectedVersion];
         }
         else if (row.Action == ACTION_REPAIR)
         {
             GUILayout.Label(string.Empty, GUILayout.Width(width));
         }
         else if (row.Action == ACTION_SKIP && row.AllVersions != null)
         {
             GUILayout.Label(Convert.ToString(row.AllVersions.FirstOrDefault()), GUILayout.Width(width));
         }
         else
         {
             GUILayout.Label(row.SelectedVersion.ToString(), GUILayout.Width(width));
         }
     }
     else if (row.AllBuilds.IsCompleted == false)
     {
         GUILayout.Label(Resources.UI_UNITYPLUGIN_WINDOW_UPDATE_CHECKING_MESSAGE, GUILayout.Width(width));
     }
     else if (row.AllBuilds.IsCompleted && row.AllBuilds.HasErrors)
     {
         GUILayout.Label(Resources.UI_UNITYPLUGIN_WINDOW_UPDATE_ERROR_MESSAGE, GUILayout.Width(width));
     }
     else
     {
         GUILayout.Label(Convert.ToString(row.SelectedVersion), GUILayout.Width(width));
     }
 }
예제 #11
0
        public ProductRow AddProductRow(string ProductName, int SupplierID, int CategoryID, string QuantityPerUnit, decimal UnitPrice, short UnitsInStock, short UnitsOnOrder, short ReorderLevel, bool Discontinued)
        {
            ProductRow rowProductRow = ((ProductRow)(this.NewRow()));

            rowProductRow.ItemArray = new object[] {
                null,
                ProductName,
                SupplierID,
                CategoryID,
                QuantityPerUnit,
                UnitPrice,
                UnitsInStock,
                UnitsOnOrder,
                ReorderLevel,
                Discontinued
            };
            this.Rows.Add(rowProductRow);
            return(rowProductRow);
        }
예제 #12
0
        private static IEnumerable DownloadAsync(ProductRow row, Action <string, float> progressCallback = null)
        {
            var downloadVersion = default(Version);

            if (row.Action == ACTION_DOWNLOAD || row.Action == ACTION_UPDATE)
            {
                downloadVersion = row.SelectedVersion;
            }
            else if (row.Action == ACTION_REPAIR)
            {
                downloadVersion = row.CurrentVersion.GetResult();
            }

            if (downloadVersion == null)
            {
                yield break;
            }

            var downloadPath    = Path.GetTempFileName();
            var downloadSuccess = false;

            try
            {
                var downloadAsync = UpdateServerCli.DownloadBuild(row.Id, downloadVersion, downloadPath, progressCallback);
                yield return(downloadAsync);

                downloadSuccess = true;
                yield return(downloadPath);
            }
            finally
            {
                if (downloadSuccess == false && File.Exists(downloadPath))
                {
                    try
                    {
                        File.Delete(downloadPath);
                    }
                    catch { /* ignore delete error */ }
                }
            }
        }
예제 #13
0
        public SaveResponse Create(IUnitOfWork uow, SaveRequest <MyRow> request)
        {
            var regist = RegistrosRow.Fields;
            var mater  = ProductRow.Fields;
            var objeto = request.Entity;

            var product = uow.Connection.TryFirst <ProductRow>(q => q
                                                               .Select(mater.ProductID, mater.UnitsInStock)
                                                               .Where(mater.ProductID == Convert.ToString(objeto.ProductId)));

            if (product == null)
            {
                product = new ProductRow
                {
                }
            }
            ;
            else
            {
                product.TrackWithChecks = false;
            }


            if ((int)objeto.Movimiento == (int)TipoMovimiento.Entrada)
            {
                product.UnitsInStock = Convert.ToDecimal(product.UnitsInStock + objeto.Cantidad);
            }
            else
            {
                product.UnitsInStock = Convert.ToDecimal(product.UnitsInStock - objeto.Cantidad);
            }



            new ProductRepository().Update(uow, new SaveRequest <ProductRow> {
                Entity = product, EntityId = product.ProductID
            });

            return(new MySaveHandler().Process(uow, request, SaveRequestType.Create));
        }
예제 #14
0
파일: Form1.cs 프로젝트: Alp4ka/Storage
        /// <summary>
        /// Дабл клик по тривью.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void storageTree_DoubleClick(object sender, EventArgs e)
        {
            var selectedNode = storageTree.SelectedNode;

            if (selectedNode != null)
            {
                dataGrid.Rows.Clear();
                var products = ((StorageNode)selectedNode).Cathegory.Products;

                for (int i = 0; i < products.Count(); ++i)
                {
                    var row   = new ProductRow();
                    var array = products[i].GetArray();
                    row.CreateCells(dataGrid);
                    for (int j = 0; j < array.Length; ++j)
                    {
                        row.Cells[j].Value = array[j];
                    }
                    row.Product = products[i];
                    dataGrid.Rows.Add(row);
                }
            }
        }
예제 #15
0
 public void AddProductRow(ProductRow row)
 {
     this.Rows.Add(row);
 }
예제 #16
0
 public OrdersRow AddOrdersRow(int TradePupletRef, ProductRow parentProductRowByProduct_Orders, System.DateTime DateOrder, decimal Quantity, decimal Price, decimal Reserved, decimal QuantityNow, bool isClose, string Note, string AuthorCreate, string AuthorLastModif, System.DateTime DateCreate, System.DateTime DateLastModif, byte[] RowVersion) {
     OrdersRow rowOrdersRow = ((OrdersRow)(this.NewRow()));
     rowOrdersRow.ItemArray = new object[] {
             null,
             TradePupletRef,
             parentProductRowByProduct_Orders[0],
             DateOrder,
             Quantity,
             Price,
             Reserved,
             QuantityNow,
             isClose,
             Note,
             AuthorCreate,
             AuthorLastModif,
             DateCreate,
             DateLastModif,
             RowVersion};
     this.Rows.Add(rowOrdersRow);
     return rowOrdersRow;
 }
예제 #17
0
 public RemainsRow AddRemainsRow(
             ProductRow parentProductRowByProduct_Remains, 
             string Series, 
             System.DateTime UseByDate, 
             decimal PricePurchase, 
             decimal Quantity, 
             System.DateTime DateLastModif, 
             string AuthorLastModif, 
             string ManufacturerName, 
             int ManufacturerRef, 
             string CountryName, 
             System.DateTime DocDate, 
             decimal QuantityRemains, 
             int MainStockRef, 
             int ReceiptDetailRef, 
             string ProductName, 
             decimal SumRemains) {
     RemainsRow rowRemainsRow = ((RemainsRow)(this.NewRow()));
     rowRemainsRow.ItemArray = new object[] {
             parentProductRowByProduct_Remains[0],
             Series,
             UseByDate,
             PricePurchase,
             Quantity,
             DateLastModif,
             AuthorLastModif,
             ManufacturerName,
             ManufacturerRef,
             CountryName,
             DocDate,
             QuantityRemains,
             MainStockRef,
             ReceiptDetailRef,
             ProductName,
             SumRemains};
     this.Rows.Add(rowRemainsRow);
     return rowRemainsRow;
 }
예제 #18
0
 public ReceiptDetailRow AddReceiptDetailRow(
             ReceiptMasterRow parentReceiptMasterRowByFK_ReceiptDetail_ReceiptMaster, 
             ProductRow parentProductRowByProduct_ReceiptDetail, 
             string Series, 
             System.DateTime UseByDate, 
             decimal Quantity, 
             decimal PricePurchase, 
             decimal PurchSum, 
             decimal PurchNDS, 
             decimal SalesNDS, 
             decimal SalesPrice, 
             decimal SalesSum, 
             string Note, 
             string AuthorCreate, 
             string AuthorLastModif, 
             System.DateTime DateLastModif, 
             System.DateTime DateCreate, 
             byte[] RowVersion, 
             int ManufacturerRef, 
             decimal Extra, 
             int DocumentTypeRef, 
             string ProductName, 
             string ManufacturerName, 
             string CountryName) {
     ReceiptDetailRow rowReceiptDetailRow = ((ReceiptDetailRow)(this.NewRow()));
     rowReceiptDetailRow.ItemArray = new object[] {
             null,
             parentReceiptMasterRowByFK_ReceiptDetail_ReceiptMaster[0],
             parentProductRowByProduct_ReceiptDetail[0],
             Series,
             UseByDate,
             Quantity,
             PricePurchase,
             PurchSum,
             PurchNDS,
             SalesNDS,
             SalesPrice,
             SalesSum,
             Note,
             AuthorCreate,
             AuthorLastModif,
             DateLastModif,
             DateCreate,
             RowVersion,
             ManufacturerRef,
             Extra,
             DocumentTypeRef,
             ProductName,
             ManufacturerName,
             CountryName};
     this.Rows.Add(rowReceiptDetailRow);
     return rowReceiptDetailRow;
 }
예제 #19
0
 public ReceiptDetailRow AddReceiptDetailRow(
             ReceiptMasterRow parentReceiptMasterRowByReceiptMaster_ReceiptDetail, 
             ProductRow parentProductRowByProduct_ReceiptDetail, 
             string Series, 
             System.DateTime UseByDate, 
             decimal Quantity, 
             decimal PricePurchase, 
             decimal PurchSum, 
             decimal PurchNDS, 
             decimal SalesNDS, 
             decimal SalesPrice, 
             decimal SalesSum, 
             int InvoiceDetailRef, 
             string AuthorCreate, 
             string AuthorLastModif, 
             System.DateTime DateCreate, 
             byte[] RowVersion, 
             string Note, 
             System.DateTime DateLastModif, 
             decimal CalcPurchSum, 
             int OrganisationRef, 
             string ProductName, 
             string ManufacturerName, 
             string DocumentTypeRef, 
             ManufacturerRow parentManufacturerRowByFK_Manufacturer_ReceiptDetail) {
     ReceiptDetailRow rowReceiptDetailRow = ((ReceiptDetailRow)(this.NewRow()));
     rowReceiptDetailRow.ItemArray = new object[] {
             null,
             parentReceiptMasterRowByReceiptMaster_ReceiptDetail[0],
             parentProductRowByProduct_ReceiptDetail[0],
             Series,
             UseByDate,
             Quantity,
             PricePurchase,
             PurchSum,
             PurchNDS,
             SalesNDS,
             SalesPrice,
             SalesSum,
             InvoiceDetailRef,
             AuthorCreate,
             AuthorLastModif,
             DateCreate,
             RowVersion,
             Note,
             DateLastModif,
             CalcPurchSum,
             OrganisationRef,
             ProductName,
             ManufacturerName,
             DocumentTypeRef,
             parentManufacturerRowByFK_Manufacturer_ReceiptDetail[0]};
     this.Rows.Add(rowReceiptDetailRow);
     return rowReceiptDetailRow;
 }
예제 #20
0
        public void products()
        {
            if (!BaseConnection.openConnection())
            {
                return;
            }


            string query = "select Products.Name, Units.Name, Invoice_Products.Amount, Tax_rates.Name, Tax_rates.Value, Invoice_Products.Price " +
                           "from Invoice_Products inner join Invoices on Invoice_Products.Id_invoice = Invoices.Id " +
                           "inner join Products on Invoice_Products.Id_product = Products.Id " +
                           "inner join Units on Units.Id = Products.Id_unit inner join Tax_rates on Tax_rates.Id = Invoice_Products.Id_tax " +
                           "where Invoices.Id = " + _idInvoice;


            decimal           sum          = 0;
            List <ProductRow> productsList = new List <ProductRow>();
            SqlDataReader     reader       = BaseConnection.execReader(query);

            while (reader.Read())
            {
                ProductRow productRow = new ProductRow();
                productRow.name         = reader.GetString(0);
                productRow.unit         = reader.GetString(1);
                productRow.amount       = reader.GetInt32(2);
                productRow.taxRate      = reader.GetString(3);
                productRow.taxRateValue = reader.GetDecimal(4);
                productRow.price        = reader.GetDecimal(5);
                productsList.Add(productRow);
            }


            BaseConnection.closeConnection();


            _writer.AddAttribute(HtmlTextWriterAttribute.Class, "table");
            _writer.RenderBeginTag(HtmlTextWriterTag.Table);             // open table
            {
                _writer.AddAttribute(HtmlTextWriterAttribute.Class, "thead-dark");
                _writer.RenderBeginTag(HtmlTextWriterTag.Thead);                 // open thead
                {
                    _writer.RenderBeginTag(HtmlTextWriterTag.Tr);                //open tr
                    {
                        _writer.AddAttribute(HtmlTextWriterAttribute.Scope, "col");
                        _writer.RenderBeginTag(HtmlTextWriterTag.Th);                           //Product
                        _writer.Write("Produkt");
                        _writer.RenderEndTag();

                        _writer.AddAttribute(HtmlTextWriterAttribute.Scope, "col");
                        _writer.RenderBeginTag(HtmlTextWriterTag.Th);                           //Unit
                        _writer.Write("Jedn.");
                        _writer.RenderEndTag();

                        _writer.AddAttribute(HtmlTextWriterAttribute.Scope, "col");
                        _writer.RenderBeginTag(HtmlTextWriterTag.Th);                           //Amount
                        _writer.Write("Ilość");
                        _writer.RenderEndTag();

                        _writer.AddAttribute(HtmlTextWriterAttribute.Scope, "col");
                        _writer.RenderBeginTag(HtmlTextWriterTag.Th);                           //Vat
                        _writer.Write("Stawka");
                        _writer.RenderEndTag();

                        _writer.AddAttribute(HtmlTextWriterAttribute.Scope, "col");
                        _writer.RenderBeginTag(HtmlTextWriterTag.Th);                           //Price netto
                        _writer.Write("Cena netto");
                        _writer.RenderEndTag();

                        _writer.AddAttribute(HtmlTextWriterAttribute.Scope, "col");
                        _writer.RenderBeginTag(HtmlTextWriterTag.Th);                           //Price brutto
                        _writer.Write("Cena brutto");
                        _writer.RenderEndTag();
                    }
                    _writer.RenderEndTag();                      // close tr
                }
                _writer.RenderEndTag();                          //close thead

                _writer.RenderBeginTag(HtmlTextWriterTag.Tbody); // open tbody
                {
                    foreach (var ele in productsList)
                    {
                        _writer.RenderBeginTag(HtmlTextWriterTag.Tr);                         //open tr
                        {
                            _writer.RenderBeginTag(HtmlTextWriterTag.Td);                     // Product
                            _writer.Write(ele.name);
                            _writer.RenderEndTag();

                            _writer.RenderBeginTag(HtmlTextWriterTag.Td);                               // Unit
                            _writer.Write(ele.unit);
                            _writer.RenderEndTag();

                            _writer.RenderBeginTag(HtmlTextWriterTag.Td);                               // Amount
                            _writer.Write(ele.amount);
                            _writer.RenderEndTag();

                            _writer.RenderBeginTag(HtmlTextWriterTag.Td);                               // VAT
                            _writer.Write(ele.taxRate);
                            _writer.RenderEndTag();

                            _writer.RenderBeginTag(HtmlTextWriterTag.Td);                               // Price netto
                            _writer.Write(ele.price.ToString("0.##"));
                            _writer.RenderEndTag();

                            decimal brutto = Math.Round(ele.price * (ele.taxRateValue + 1), 2);
                            sum += (brutto * ele.amount);
                            _writer.RenderBeginTag(HtmlTextWriterTag.Td);                               // Price brutto
                            _writer.Write(brutto);
                            _writer.RenderEndTag();
                        }
                        _writer.RenderEndTag();                         // close tr
                    }
                }
                _writer.RenderEndTag();         //close tbody
            }
            _writer.RenderEndTag();             //close table

            _writer.AddAttribute(HtmlTextWriterAttribute.Class, "text-right w-100 font-weight-bold bg-light");
            _writer.RenderBeginTag(HtmlTextWriterTag.H3); //open h3
            _writer.Write("Razem do zapłaty (brutto): " + sum + " zł");
            _writer.RenderEndTag();                       //close h3
        }
예제 #21
0
        public ExcelImportResponse ExcelImport(IUnitOfWork uow, ExcelImportRequest request)
        {
            request.CheckNotNull();
            Check.NotNullOrWhiteSpace(request.FileName, "filename");

            UploadHelper.CheckFileNameSecurity(request.FileName);

            if (!request.FileName.StartsWith("temporary/"))
                throw new ArgumentOutOfRangeException("filename");

            ExcelPackage ep = new ExcelPackage();
            using (var fs = new FileStream(UploadHelper.DbFilePath(request.FileName), FileMode.Open, FileAccess.Read))
                ep.Load(fs);

            var p = ProductRow.Fields;
            var s = SupplierRow.Fields;
            var c = CategoryRow.Fields;

            var response = new ExcelImportResponse();
            response.ErrorList = new List<string>();

            var worksheet = ep.Workbook.Worksheets[1];
            for (var row = 2; row <= worksheet.Dimension.End.Row; row++)
            {
                try
                {
                    var productName = Convert.ToString(worksheet.Cells[row, 1].Value ?? "");
                    if (productName.IsTrimmedEmpty())
                        continue;

                    var product = uow.Connection.TryFirst<ProductRow>(q => q
                        .Select(p.ProductID)
                        .Where(p.ProductName == productName));

                    if (product == null)
                        product = new ProductRow
                        {
                            ProductName = productName
                        };
                    else
                    {
                        // avoid assignment errors
                        product.TrackWithChecks = false;
                    }

                    var supplierName = Convert.ToString(worksheet.Cells[row, 2].Value ?? "");
                    if (!string.IsNullOrWhiteSpace(supplierName))
                    {
                        var supplier = uow.Connection.TryFirst<SupplierRow>(q => q
                            .Select(s.SupplierID)
                            .Where(s.CompanyName == supplierName));

                        if (supplier == null)
                        {
                            response.ErrorList.Add("Error On Row " + row + ": Supplier with name '" +
                                supplierName + "' is not found!");
                            continue;
                        }

                        product.SupplierID = supplier.SupplierID.Value;
                    }
                    else
                        product.SupplierID = null;

                    var categoryName = Convert.ToString(worksheet.Cells[row, 3].Value ?? "");
                    if (!string.IsNullOrWhiteSpace(categoryName))
                    {
                        var category = uow.Connection.TryFirst<CategoryRow>(q => q
                            .Select(c.CategoryID)
                            .Where(c.CategoryName == categoryName));

                        if (category == null)
                        {
                            response.ErrorList.Add("Error On Row " + row + ": Category with name '" +
                                categoryName + "' is not found!");
                            continue;
                        }

                        product.CategoryID = category.CategoryID.Value;
                    }
                    else
                        product.CategoryID = null;

                    product.QuantityPerUnit = Convert.ToString(worksheet.Cells[row, 4].Value ?? "");
                    product.UnitPrice = Convert.ToDecimal(worksheet.Cells[row, 5].Value ?? 0);
                    product.UnitsInStock = Convert.ToInt16(worksheet.Cells[row, 6].Value ?? 0);
                    product.UnitsOnOrder = Convert.ToInt16(worksheet.Cells[row, 7].Value ?? 0);
                    product.ReorderLevel = Convert.ToInt16(worksheet.Cells[row, 8].Value ?? 0);

                    if (product.ProductID == null)
                    {
                        new ProductRepository().Create(uow, new SaveWithLocalizationRequest<MyRow>
                        {
                            Entity = product
                        });

                        response.Inserted = response.Inserted + 1;
                    }
                    else
                    {
                        new ProductRepository().Update(uow, new SaveWithLocalizationRequest<MyRow>
                        {
                            Entity = product,
                            EntityId = product.ProductID.Value
                        });

                        response.Updated = response.Updated + 1;
                    }
                }
                catch (Exception ex)
                {
                    response.ErrorList.Add("Exception on Row " + row + ": " + ex.Message);
                }
            }

            return response;
        }
예제 #22
0
        private static void ChooseAction(ProductRow row)
        {
            var currentVersion = row.CurrentVersion.GetResult();
            var builds         = row.AllBuilds.HasErrors ? default(BuildInfo[]) : row.AllBuilds.GetResult();

            if (builds == null || builds.Length == 0)
            {
                return;
            }

            var versions = Array.ConvertAll(builds, b => b.Version);

            Array.Sort(versions);
            Array.Reverse(versions);

            row.AllVersions = versions;
            var lastVersion = versions.FirstOrDefault();

            if (string.IsNullOrEmpty(row.Location) || lastVersion == null)
            {
                // no local artifacts
                row.SelectedVersion = null;
                row.Action          = ACTION_SKIP;
                row.ActionMask      = (1 << Array.IndexOf(Actions, ACTION_SKIP));
                return;
            }

            var expectedBuild = builds.FirstOrDefault(b => b.Version == row.ExpectedVersion);
            var currentBuild  = builds.FirstOrDefault(b => b.Version == currentVersion);

            if (expectedBuild == null && currentVersion != null && currentVersion > lastVersion)
            {
                // current installed build is the last one
                row.SelectedVersion = currentVersion;
                row.Action          = ACTION_SKIP;
                row.ActionMask      = (1 << Array.IndexOf(Actions, ACTION_SKIP));
            }
            else if (File.Exists(row.Location) == false || (expectedBuild != null && currentBuild != expectedBuild))
            {
                // missing file or invalid version is installed
                row.SelectedVersion = expectedBuild != null ? expectedBuild.Version : currentVersion ?? lastVersion;
                row.Action          = ACTION_DOWNLOAD;
                row.ActionMask      = (1 << Array.IndexOf(Actions, ACTION_DOWNLOAD)) | (1 << Array.IndexOf(Actions, ACTION_SKIP));
            }
            else if (currentBuild == null && currentVersion != null)
            {
                // current installed build is not found
                row.SelectedVersion = lastVersion;
                row.Action          = ACTION_DOWNLOAD;
                row.ActionMask      = (1 << Array.IndexOf(Actions, ACTION_DOWNLOAD)) | (1 << Array.IndexOf(Actions, ACTION_SKIP));
            }
            else
            {
                var actualHash = FileAndPathUtils.ComputeHash(row.Location, currentBuild.HashAlgorithm);
                if (string.Equals(currentBuild.Hash, actualHash, StringComparison.OrdinalIgnoreCase) == false)
                {
                    if (Settings.Current.Verbose)
                    {
                        Debug.LogWarning(string.Format("File's '{0}' {1} hash '{2}' differs from expected '{3}'. File should be repaired.", row.Location, currentBuild.HashAlgorithm, actualHash, currentBuild.Hash));
                    }

                    // corrupted file
                    row.SelectedVersion = lastVersion;
                    row.Action          = ACTION_REPAIR;
                    row.ActionMask      = (1 << Array.IndexOf(Actions, ACTION_REPAIR)) | (1 << Array.IndexOf(Actions, ACTION_UPDATE)) | (1 << Array.IndexOf(Actions, ACTION_SKIP));
                }
                else if (currentVersion < lastVersion)
                {
                    // outdated version
                    row.SelectedVersion = lastVersion;
                    row.Action          = ACTION_UPDATE;
                    row.ActionMask      = (1 << Array.IndexOf(Actions, ACTION_UPDATE)) | (1 << Array.IndexOf(Actions, ACTION_SKIP));
                }
                else
                {
                    // actual version
                    row.SelectedVersion = currentVersion ?? lastVersion;
                    row.Action          = ACTION_SKIP;
                    row.ActionMask      = (1 << Array.IndexOf(Actions, ACTION_SKIP));
                }
            }
        }
예제 #23
0
 private static void RenderProductCell(ProductRow row, float width)
 {
     GUILayout.Label(row.Name, GUILayout.Width(width));
 }
예제 #24
0
 public PricesPurchaseRow AddPricesPurchaseRow(OrganizationRow parentOrganizationRowByOrganization_PricesPurchase, ProductRow parentProductRowByProduct_PricesPurchase, decimal PricePurchase, System.DateTime Date, string OrganizationName) {
     PricesPurchaseRow rowPricesPurchaseRow = ((PricesPurchaseRow)(this.NewRow()));
     rowPricesPurchaseRow.ItemArray = new object[] {
             parentOrganizationRowByOrganization_PricesPurchase[0],
             parentProductRowByProduct_PricesPurchase[0],
             PricePurchase,
             Date,
             OrganizationName};
     this.Rows.Add(rowPricesPurchaseRow);
     return rowPricesPurchaseRow;
 }
예제 #25
0
        public ExcelImportResponse ExcelImport(IUnitOfWork uow, ExcelImportRequest request)
        {
            request.CheckNotNull();
            Check.NotNullOrWhiteSpace(request.FileName, "filename");

            UploadHelper.CheckFileNameSecurity(request.FileName);

            if (!request.FileName.StartsWith("temporary/"))
            {
                throw new ArgumentOutOfRangeException("filename");
            }

            ExcelPackage ep = new ExcelPackage();

            using (var fs = new FileStream(UploadHelper.DbFilePath(request.FileName), FileMode.Open, FileAccess.Read))
                ep.Load(fs);

            var p  = ProductRow.Fields;
            var c  = CategoryRow.Fields;
            var m  = MeasureRow.Fields;
            var cp = CounterpartyRow.Fields;

            var response = new ExcelImportResponse();

            response.ErrorList = new List <string>();

            var worksheet = ep.Workbook.Worksheets[1];

            for (var row = 2; row <= worksheet.Dimension.End.Row; row++)
            {
                try
                {
                    var productName = Convert.ToString(worksheet.Cells[row, 4].Value ?? "");
                    if (productName.IsTrimmedEmpty())
                    {
                        continue;
                    }

                    var product = uow.Connection.TryFirst <ProductRow>(q => q
                                                                       .Select(p.ProductID)
                                                                       .Where(p.ProductName == productName));

                    if (product == null)
                    {
                        product = new ProductRow
                        {
                            ProductName = productName
                        }
                    }
                    ;
                    else
                    {
                        product.TrackWithChecks = false;
                    }

                    #region Category

                    var categoryName = Convert.ToString(worksheet.Cells[row, 6].Value ?? "");
                    if (!string.IsNullOrWhiteSpace(categoryName))
                    {
                        var category = uow.Connection.TryFirst <CategoryRow>(q => q
                                                                             .Select(c.CategoryID)
                                                                             .Where(c.CategoryName == categoryName));

                        if (category == null)
                        {
                            response.ErrorList.Add("Error On Row" + row + ": Category with name '" +
                                                   categoryName + "' is not found!");
                            continue;
                        }

                        product.CategoryID = category.CategoryID.Value;
                    }
                    else
                    {
                        product.CategoryID = null;
                    }

                    #endregion Category

                    #region Measure

                    var measureName = Convert.ToString(worksheet.Cells[row, 7].Value ?? "");
                    if (!string.IsNullOrWhiteSpace(measureName))
                    {
                        var measure = uow.Connection.TryFirst <MeasureRow>(q => q
                                                                           .Select(m.MeasureID)
                                                                           .Where(m.MeasureName == measureName));

                        if (measure == null)
                        {
                            response.ErrorList.Add("Error On Row" + row + ": Measure with name '" +
                                                   measureName + "' is not found!");
                            continue;
                        }

                        product.MeasureID = measure.MeasureID.Value;
                    }
                    else
                    {
                        product.MeasureID = null;
                    }

                    #endregion Measure

                    #region Counterparty

                    //var counterpartyName = Convert.ToString(worksheet.Cells[row, 13].Value ?? 0);
                    //if (!string.IsNullOrWhiteSpace(counterpartyName))
                    //{
                    //    var counterparty = uow.Connection.TryFirst<CounterpartyRow>(q => q
                    //        .Select(cp.CounterpartyID)
                    //        .Where(cp.CompanyName == counterpartyName));

                    //    if(counterparty == null)
                    //    {
                    //        response.ErrorList.Add("Error On Row" + row + ": Counterparty with name '" +
                    //            counterpartyName + "' is not found!");
                    //        continue;
                    //    }

                    //    product.CounterpartyID = counterparty.CounterpartyID.ToString();
                    //}
                    //else
                    //{
                    //    product.CounterpartyID = null;
                    //}

                    #endregion Counterparty

                    product.ProductCode    = Convert.ToString(worksheet.Cells[row, 1].Value ?? "");
                    product.ProductBarcode = Convert.ToString(worksheet.Cells[row, 2].Value ?? "");
                    product.ProductLabel   = Convert.ToString(worksheet.Cells[row, 3].Value ?? "");
                    product.Discontinued   = Convert.ToBoolean(worksheet.Cells[row, 5].Value ?? "");

                    product.QuantityPerUnit = Convert.ToString(worksheet.Cells[row, 8].Value ?? "");
                    product.UnitPrice       = Convert.ToDecimal(worksheet.Cells[row, 9].Value ?? 0);
                    product.UnitsInStock    = Convert.ToInt16(worksheet.Cells[row, 10].Value ?? 0);
                    product.UnitsOnOrder    = Convert.ToInt16(worksheet.Cells[row, 11].Value ?? 0);

                    product.CounterpartyID = Convert.ToString(worksheet.Cells[row, 13].Value ?? 0);

                    if (product.ProductID == null)
                    {
                        new ProductRepository().Create(uow, new SaveWithLocalizationRequest <MyRow>
                        {
                            Entity = product
                        });

                        response.Inserted = response.Inserted + 1;
                    }
                    else
                    {
                        new ProductRepository().Update(uow, new SaveWithLocalizationRequest <MyRow>
                        {
                            Entity   = product,
                            EntityId = product.ProductID.Value
                        });

                        response.Updated = response.Updated + 1;
                    }
                }
                catch (Exception ex)
                {
                    response.ErrorList.Add("Exception on Row " + row + ": " + ex.Message);
                }
            }

            return(response);
        }
예제 #26
0
 public void RemoveProductRow(ProductRow row)
 {
     this.Rows.Remove(row);
 }
예제 #27
0
 public ProductRowChangeEventArgs(ProductRow row, DataRowAction action)
 {
     _eventRow = row;
     _eventAction = action;
 }
예제 #28
0
 public void AddProductRow(ProductRow row)
 {
     this.Rows.Add(row);
 }
예제 #29
0
 public ProductRowStorage(ProductRow product)
 {
     TotalPrice = product.GetTotalPrice();
     UnitPrice  = product.GetUnitPrice();
     QtyValue   = product.QtyBox.GetQtyValue();
 }
예제 #30
0
 public void RemoveProductRow(ProductRow row)
 {
     this.Rows.Remove(row);
 }
        public ExcelImportResponse ExcelImport(IUnitOfWork uow, ExcelImportRequest request)
        {
            request.CheckNotNull();
            Check.NotNullOrWhiteSpace(request.FileName, "filename");

            UploadHelper.CheckFileNameSecurity(request.FileName);

            if (!request.FileName.StartsWith("temporary/"))
            {
                throw new ArgumentOutOfRangeException("filename");
            }

            ExcelPackage ep = new ExcelPackage();

            using (var fs = new FileStream(UploadHelper.DbFilePath(request.FileName), FileMode.Open, FileAccess.Read))
                ep.Load(fs);

            var p = ProductRow.Fields;
            var s = SupplierRow.Fields;
            var c = CategoryRow.Fields;

            var response = new ExcelImportResponse();

            response.ErrorList = new List <string>();

            var worksheet = ep.Workbook.Worksheets[1];

            for (var row = 2; row <= worksheet.Dimension.End.Row; row++)
            {
                try
                {
                    var productName = Convert.ToString(worksheet.Cells[row, 1].Value ?? "");
                    if (productName.IsTrimmedEmpty())
                    {
                        continue;
                    }

                    var product = uow.Connection.TryFirst <ProductRow>(q => q
                                                                       .Select(p.ProductID)
                                                                       .Where(p.ProductName == productName));

                    if (product == null)
                    {
                        product = new ProductRow
                        {
                            ProductName = productName
                        }
                    }
                    ;
                    else
                    {
                        // avoid assignment errors
                        product.TrackWithChecks = false;
                    }

                    var supplierName = Convert.ToString(worksheet.Cells[row, 2].Value ?? "");
                    if (!string.IsNullOrWhiteSpace(supplierName))
                    {
                        var supplier = uow.Connection.TryFirst <SupplierRow>(q => q
                                                                             .Select(s.SupplierID)
                                                                             .Where(s.CompanyName == supplierName));

                        if (supplier == null)
                        {
                            response.ErrorList.Add("Error On Row " + row + ": Supplier with name '" +
                                                   supplierName + "' is not found!");
                            continue;
                        }

                        product.SupplierID = supplier.SupplierID.Value;
                    }
                    else
                    {
                        product.SupplierID = null;
                    }

                    var categoryName = Convert.ToString(worksheet.Cells[row, 3].Value ?? "");
                    if (!string.IsNullOrWhiteSpace(categoryName))
                    {
                        var category = uow.Connection.TryFirst <CategoryRow>(q => q
                                                                             .Select(c.CategoryID)
                                                                             .Where(c.CategoryName == categoryName));

                        if (category == null)
                        {
                            response.ErrorList.Add("Error On Row " + row + ": Category with name '" +
                                                   categoryName + "' is not found!");
                            continue;
                        }

                        product.CategoryID = category.CategoryID.Value;
                    }
                    else
                    {
                        product.CategoryID = null;
                    }

                    product.QuantityPerUnit = Convert.ToString(worksheet.Cells[row, 4].Value ?? "");
                    product.UnitPrice       = Convert.ToDecimal(worksheet.Cells[row, 5].Value ?? 0);
                    product.UnitsInStock    = Convert.ToInt16(worksheet.Cells[row, 6].Value ?? 0);
                    product.UnitsOnOrder    = Convert.ToInt16(worksheet.Cells[row, 7].Value ?? 0);
                    product.ReorderLevel    = Convert.ToInt16(worksheet.Cells[row, 8].Value ?? 0);

                    if (product.ProductID == null)
                    {
                        new ProductRepository().Create(uow, new SaveRequest <MyRow>
                        {
                            Entity = product
                        });

                        response.Inserted = response.Inserted + 1;
                    }
                    else
                    {
                        new ProductRepository().Update(uow, new SaveRequest <MyRow>
                        {
                            Entity   = product,
                            EntityId = product.ProductID.Value
                        });

                        response.Updated = response.Updated + 1;
                    }
                }
                catch (Exception ex)
                {
                    response.ErrorList.Add("Exception on Row " + row + ": " + ex.Message);
                }
            }

            return(response);
        }
예제 #32
0
        } // End of the AddAccount method

        /// <summary>
        /// Add an article if it does not exist
        /// </summary>
        public async Task<ArticleRoot> AddArticle(ProductRow row)
        {
            // Create a reference to an article root
            FortnoxResponse<ArticleRoot> fr = new FortnoxResponse<ArticleRoot>();

            // Make sure that the product code only consists of alphanumeric characters
            row.product_code = string.IsNullOrEmpty(row.product_code) == false ? CommonTools.ConvertToAlphanumeric(row.product_code) : null;

            // Find the article
            if (string.IsNullOrEmpty(row.gtin) == false)
            {
                // Try to get articles on EAN
                FortnoxResponse<ArticlesRoot> fr_page = await this.nox_client.Get<ArticlesRoot>($"articles?ean={row.gtin}");

                // Log errors
                if (string.IsNullOrEmpty(fr_page.error) == false)
                {
                    this.logger.LogError(fr_page.error);
                }

                // Make sure that at least one article was found
                if (fr_page.model != null && fr_page.model.Articles != null && fr_page.model.Articles.Count > 0)
                {
                    // Get an article
                    fr = await this.nox_client.Get<ArticleRoot>($"articles/{fr_page.model.Articles[0].ArticleNumber}");

                    // Log errors
                    if (string.IsNullOrEmpty(fr.error) == false)
                    {
                        this.logger.LogError(fr.error);
                    }
                }
            }
            if(fr.model == null && string.IsNullOrEmpty(row.manufacturer_code) == false)
            {
                // Try to get articles on manufacturer code
                FortnoxResponse<ArticlesRoot> fr_page = await this.nox_client.Get<ArticlesRoot>($"articles?manufacturerarticlenumber={row.manufacturer_code}");

                // Log errors
                if (string.IsNullOrEmpty(fr_page.error) == false)
                {
                    this.logger.LogError(fr_page.error);
                }

                // Make sure that at least one article was found
                if (fr_page.model != null && fr_page.model.Articles != null && fr_page.model.Articles.Count > 0)
                {
                    // Get an article
                    fr = await this.nox_client.Get<ArticleRoot>($"articles/{fr_page.model.Articles[0].ArticleNumber}");

                    // Log errors
                    if (string.IsNullOrEmpty(fr.error) == false)
                    {
                        this.logger.LogError(fr.error);
                    }
                }
            }
            if(fr.model == null && string.IsNullOrEmpty(row.product_code) == false)
            {
                // Get an article
                fr = await this.nox_client.Get<ArticleRoot>($"articles/{row.product_code}");

                // Log errors
                if (string.IsNullOrEmpty(fr.error) == false)
                {
                    this.logger.LogError(fr.error);
                }
            }

            // Add the article if it does not exist
            if (fr.model == null)
            {
                // Create a new article
                fr.model = new ArticleRoot
                {
                    Article = new Article
                    {
                        ArticleNumber = string.IsNullOrEmpty(row.product_code) == false ? row.product_code : null,
                        ConstructionAccount = this.default_values.SalesAccountSEREVERSEDVAT,
                        Description = row.product_name,
                        EAN = string.IsNullOrEmpty(row.gtin) == false ? row.gtin : null,
                        EUAccount = this.default_values.SalesAccountEUREVERSEDVAT,
                        EUVATAccount = this.default_values.SalesAccountEUVAT,
                        ExportAccount = this.default_values.SalesAccountEXPORT,
                        ManufacturerArticleNumber = string.IsNullOrEmpty(row.manufacturer_code) == false ? row.manufacturer_code : null,
                        PurchaseAccount = this.default_values.PurchaseAccount,
                        SalesAccount = CommonTools.GetArticleSalesAccount(row.vat_rate, this.default_values),
                        Unit = string.IsNullOrEmpty(row.unit_code) == false ? row.unit_code : null
                    }
                };

                // Add an article
                fr = await this.nox_client.Add<ArticleRoot>(fr.model, "articles");

                // Log errors
                if (string.IsNullOrEmpty(fr.error) == false)
                {
                    this.logger.LogError(fr.error);
                }

                // Add a default price
                if (fr.model != null)
                {
                    PriceRoot price = new PriceRoot
                    {
                        Price = new Price
                        {
                            ArticleNumber = fr.model.Article.ArticleNumber,
                            PriceList = this.default_values.PriceList,
                            FromQuantity = 0,
                            Amount = row.unit_price
                        }
                    };

                    // Add a price
                    FortnoxResponse<PriceRoot> fr_price = await this.nox_client.Add<PriceRoot>(price, "prices");

                    // Log errors
                    if (string.IsNullOrEmpty(fr_price.error) == false)
                    {
                        this.logger.LogError(fr_price.error);
                    }
                }     
            }

            // Return the post
            return fr.model;

        } // End of the AddArticle method
예제 #33
0
 public ProductRowChangeEvent(ProductRow row, System.Data.DataRowAction action) {
     this.eventRow = row;
     this.eventAction = action;
 }
예제 #34
0
 public InvoiceDetailRow AddInvoiceDetailRow(
             InvoiceMasterRow parentInvoiceMasterRowByFK_InvoiceDetail_InvoiceMaster, 
             decimal Quantity, 
             decimal PricePurchase, 
             decimal DiscountSum, 
             decimal PurchaseNDS, 
             decimal PriceRetail, 
             decimal RetailNDS, 
             decimal PriceRetailNDS, 
             RemainsRow parentRemainsRowByRemains_InvoiceDetail, 
             int RemoteInvoiceDetailRef, 
             string Note, 
             string AuthorCreate, 
             string AuthorLastModif, 
             System.DateTime DateLastModif, 
             System.DateTime DateCreate, 
             byte[] RowVersion, 
             decimal RetailSum, 
             decimal Extra, 
             decimal Discount, 
             int DocumentTypeRef, 
             int Article, 
             ProductRow parentProductRowByInvoiceDetail_Product, 
             string Series, 
             System.DateTime UseByDate, 
             string ManufacturerName, 
             string ProductName, 
             int NumCheck, 
             System.DateTime Date, 
             decimal CalcSum) {
     InvoiceDetailRow rowInvoiceDetailRow = ((InvoiceDetailRow)(this.NewRow()));
     rowInvoiceDetailRow.ItemArray = new object[] {
             null,
             parentInvoiceMasterRowByFK_InvoiceDetail_InvoiceMaster[0],
             Quantity,
             PricePurchase,
             DiscountSum,
             PurchaseNDS,
             PriceRetail,
             RetailNDS,
             PriceRetailNDS,
             parentRemainsRowByRemains_InvoiceDetail[13],
             RemoteInvoiceDetailRef,
             Note,
             AuthorCreate,
             AuthorLastModif,
             DateLastModif,
             DateCreate,
             RowVersion,
             RetailSum,
             Extra,
             Discount,
             DocumentTypeRef,
             Article,
             parentProductRowByInvoiceDetail_Product[0],
             Series,
             UseByDate,
             ManufacturerName,
             ProductName,
             NumCheck,
             Date,
             CalcSum};
     this.Rows.Add(rowInvoiceDetailRow);
     return rowInvoiceDetailRow;
 }
예제 #35
0
 public ProductRowChangeEvent(ProductRow row, System.Data.DataRowAction action)
 {
     this.eventRow    = row;
     this.eventAction = action;
 }
예제 #36
0
        public ExcelImportResponse ExcelImport(IUnitOfWork uow, ExcelImportRequest request)
        {
            request.CheckNotNull();
            Check.NotNullOrWhiteSpace(request.FileName, "filename");

            UploadHelper.CheckFileNameSecurity(request.FileName);

            if (!request.FileName.StartsWith("temporary/"))
            {
                throw new ArgumentOutOfRangeException("filename");
            }

            ExcelPackage ep = new ExcelPackage();

            using (var fs = new FileStream(UploadHelper.DbFilePath(request.FileName), FileMode.Open, FileAccess.Read))
                ep.Load(fs);

            var p = ProductRow.Fields;
            var s = SupplierRow.Fields;
            var c = CategoryRow.Fields;

            var response = new ExcelImportResponse();

            response.ErrorList = new List <string>();

            var worksheet = ep.Workbook.Worksheets[1];

            for (var row = 2; row <= worksheet.Dimension.End.Row; row++)
            {
                try
                {
                    //  var product = uow.Connection.TryFirst < ProductRow >(q => q.Select(p.ProductID)
                    //    .Where(p.ProductName == productName));
                    //      var  product = new ProductRow
                    //  {

                    //  };



                    var product = new ProductRow();



                    var supplierName = Convert.ToString(worksheet.Cells[row, 4].Value ?? "");
                    if (!string.IsNullOrWhiteSpace(supplierName))
                    {
                        var supplier = uow.Connection.TryFirst <SupplierRow>(q => q
                                                                             .Select(s.SupplierID)
                                                                             .Where(s.CompanyName == supplierName));

                        if (supplier == null)
                        {
                            var suppliernew = new SupplierRow();
                            suppliernew.CompanyName = supplierName;

                            new SupplierRepository().Create(uow, new SaveRequest <SupplierRow>
                            {
                                Entity = suppliernew,
                            });
                            //  product.CategoryID = categorynew.CategoryID.Value;
                            var suppl = uow.Connection.TryFirst <SupplierRow>(q => q
                                                                              .Select(s.SupplierID)
                                                                              .Where(s.CompanyName == suppliernew.CompanyName));

                            product.SupplierID = supplier.SupplierID.Value;
                        }

                        product.SupplierID = supplier.SupplierID.Value;
                    }
                    else
                    {
                        product.SupplierID = null;
                    }

                    var categoryName = Convert.ToString(worksheet.Cells[row, 5].Value ?? "");
                    if (!string.IsNullOrWhiteSpace(categoryName))
                    {
                        var category = uow.Connection.TryFirst <CategoryRow>(q => q
                                                                             .Select(c.CategoryID)
                                                                             .Where(c.CategoryName == categoryName));

                        if (category == null)
                        {
                            var categorynew = new CategoryRow();
                            categorynew.CategoryName = categoryName;

                            new CategoryRepository().Create(uow, new SaveRequest <CategoryRow>
                            {
                                Entity = categorynew,
                            });
                            //  product.CategoryID = categorynew.CategoryID.Value;
                            var categoryy = uow.Connection.TryFirst <CategoryRow>(q => q
                                                                                  .Select(c.CategoryID)
                                                                                  .Where(c.CategoryName == categorynew.CategoryName));

                            product.CategoryID = categoryy.CategoryID.Value;
                        }
                        else
                        {
                            product.CategoryID = category.CategoryID.Value;
                        }
                    }
                    else
                    {
                        product.CategoryID = null;
                    }



                    product.ProductName  = Convert.ToString(worksheet.Cells[row, 3].Value ?? "");
                    product.UnitPrice    = Convert.ToDecimal(worksheet.Cells[row, 6].Value ?? 0);
                    product.UnitsInStock = Convert.ToDecimal(worksheet.Cells[row, 7].Value ?? 0);
                    product.Product2ID   = Convert.ToString(worksheet.Cells[row, 2].Value ?? "");
                    product.ProductID    = Convert.ToString(worksheet.Cells[row, 1].Value ?? "");


                    var producto = uow.Connection.TryFirst <ProductRow>(q => q
                                                                        .Select(p.ProductID)
                                                                        .Where(p.ProductID == product.ProductID));

                    if (producto == null)
                    {
                        new ProductRepository().Create(uow, new SaveRequest <MyRow>
                        {
                            Entity = product,
                        });

                        response.Inserted = response.Inserted + 1;
                    }
                    else
                    {
                        new ProductRepository().Update(uow, new SaveRequest <MyRow>
                        {
                            Entity   = product,
                            EntityId = product.ProductID
                        });

                        response.Updated = response.Updated + 1;
                    }
                }
                catch (Exception ex)
                {
                    response.ErrorList.Add("Exception on Row " + row + ": " + ex.Message);
                }
            }

            return(response);
        }