Ejemplo n.º 1
0
 public static CellInStock Restore(int in_id, DateTime in_modified, SkuInStock in_parent, string in_x, string in_y, int in_amount, bool in_isNew)
 {
     return(new CellInStock()
     {
         Id = in_id,
         _modified = in_modified,
         _parent = in_parent,
         _x = in_x,
         _y = in_y,
         _amount = in_amount,
         _amountOld = in_isNew ? 0 : in_amount
     });
 }
Ejemplo n.º 2
0
        public static SkuInStock Restore(Article in_article, PointOfSale in_pointOfSale)
        {
            SkuInStock skuInStock = new SkuInStock()
            {
                Article     = in_article,
                PointOfSale = in_pointOfSale
            };

            using SQLiteConnection conn = ConnectionRegistry.Instance.OpenNewConnection();
            using SQLiteCommand cmd     = conn.CreateCommand();

            cmd.CommandType = CommandType.Text;

            cmd.Parameters.Add(new SQLiteParameter("@in_articleId", in_article.Id));
            cmd.Parameters.Add(new SQLiteParameter("@in_pointOfSaleId", in_pointOfSale.Id));

            cmd.CommandText = "select *" +
                              " from cell_in_stock" +
                              " where point_of_sale_id = @in_pointOfSaleId" +
                              "   and article_id = @in_articleId";

            DataTable table = new DataTable();

            using (SQLiteDataAdapter a = new SQLiteDataAdapter(cmd))
                a.Fill(table);

            DressMatrix mtx = in_article.Matrix;

            CellInStock[,] cells = new CellInStock[mtx.CellsX.Count, mtx.CellsY.Count];

            foreach (DataRow row in table.Rows)
            {
                int x = mtx.CellsX.IndexOf((string)row["x"]);
                int y = mtx.CellsY.IndexOf((string)row["y"]);
                cells[x, y] = CellInStock.Restore((int)(long)row["id"], UnixEpoch.ToDateTime((long)row["modified"]), skuInStock, (string)row["x"], (string)row["y"], (int)(long)row["amount"]);
            }
            for (int x = 0; x < mtx.CellsX.Count; x++)
            {
                for (int y = 0; y < mtx.CellsY.Count; y++)
                {
                    if (cells[x, y] == null)
                    {
                        cells[x, y] = CellInStock.Restore(0, DateTime.Now, skuInStock, mtx.CellsX[x], mtx.CellsY[y], 0);
                    }
                }
            }

            skuInStock.SetCells(cells);

            return(skuInStock);
        }
Ejemplo n.º 3
0
        public static SkuInStock CreateNew(Article in_article, PointOfSale in_pointOfSale)
        {
            SkuInStock result = new SkuInStock()
            {
                _article     = in_article,
                _pointOfSale = in_pointOfSale
            };
            DressMatrix mtx = in_article.Matrix;

            result._cells = new CellInStock[mtx.CellsX.Count, mtx.CellsY.Count];
            for (int x = 0; x < mtx.CellsX.Count; x++)
            {
                for (int y = 0; y < mtx.CellsY.Count; y++)
                {
                    result._cells[x, y] = CellInStock.Restore(0, DateTime.Now, result, mtx.CellsX[x], mtx.CellsY[y], 0);
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        public static CellInStock Restore(string in_x, string in_y, SkuInStock in_skuInStock)
        {
            using SQLiteConnection conn = ConnectionRegistry.Instance.OpenNewConnection();
            using SQLiteCommand cmd     = conn.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select *" +
                              " from cell_in_stock" +
                              " where point_of_sale_id = @in_pointOfSaleId" +
                              " and article_id = @in_articleId" +
                              " and x = @in_x" +
                              " and y = @in_y";

            cmd.Parameters.Add(new SQLiteParameter("@in_pointOfSaleId", in_skuInStock.PointOfSale.Id));
            cmd.Parameters.Add(new SQLiteParameter("@in_articleId", in_skuInStock.Article.Id));
            cmd.Parameters.Add(new SQLiteParameter("@in_x", in_x));
            cmd.Parameters.Add(new SQLiteParameter("@in_y", in_y));

            DataTable table = new DataTable();

            using (SQLiteDataAdapter a = new SQLiteDataAdapter(cmd))
                a.Fill(table);

            if (table.Rows.Count == 0)
            {
                return(null);
            }
            else if (table.Rows.Count == 1)
            {
                DataRow row = table.Rows[0];
                return(CellInStock.Restore((int)(long)row["id"], UnixEpoch.ToDateTime((long)row["modified"]), in_skuInStock, in_x, in_y, (int)(long)row["amount"]));
            }
            else
            {
                throw new ApplicationException("CellInStock.Restore(string in_x, string in_y, SkuInStock in_skuInStock) returned more than 1 row.");
            }
        }
Ejemplo n.º 5
0
 public static CellInStock Restore(int in_id, DateTime in_modified, SkuInStock in_parent, string in_x, string in_y, int in_amount)
 {
     return(Restore(in_id, in_modified, in_parent, in_x, in_y, in_amount, false));
 }