private IList <SalesDetail> GetSalesDetails(int salesId)
        {
            const string salesDetailsQuery = "Select * from Sales_Product where SalesId = @salesid";

            _sqliteDataProvider.AddParameter("@salesid", salesId);
            DataSet dataSet      = _sqliteDataProvider.ExecuteDataSet(salesDetailsQuery);
            var     salesDetails = new List <SalesDetail>();

            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                var productId   = Convert.ToInt32(row["ProductId"]);
                var productCode = new ProductDataService().GetProductById(productId).Code;
                var quantity    = Convert.ToInt32(row["Quantity"]);
                var unitPrice   = Convert.ToDouble(row["UnitPrice"]);
                salesDetails.Add(new SalesDetail
                {
                    ProductCode = productCode,
                    Quantity    = quantity,
                    SalesId     = salesId,
                    UnitPrice   = unitPrice
                });
            }

            return(salesDetails);
        }
        public Sales GetSalesById(int id)
        {
            const string query = "SELECT * From sales Where id = @id";

            _sqliteDataProvider.AddParameter("@id", id);
            var dataRow = _sqliteDataProvider.ExecuteDataRows(query).First();
            var sales   = CreateSales(dataRow);

            const string salesDetailsQuery = "Select * from Sales_Product where SalesId = @salesid";

            _sqliteDataProvider.AddParameter("@salesid", id);
            DataSet dataSet      = _sqliteDataProvider.ExecuteDataSet(salesDetailsQuery);
            var     salesDetails = new List <SalesDetail>();

            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                var productId   = Convert.ToInt32(row["ProductId"]);
                var productCode = new ProductDataService().GetProductById(productId).Code;
                var quantity    = Convert.ToInt32(row["Quantity"]);
                var unitPrice   = Convert.ToDouble(row["UnitPrice"]);
                salesDetails.Add(new SalesDetail
                {
                    ProductCode = productCode,
                    Quantity    = quantity,
                    SalesId     = id,
                    UnitPrice   = unitPrice
                });
            }

            sales.SalesDetails = salesDetails;
            return(sales);
        }
        private PackedProduct CreatePackedProductObject(DataRow row)
        {
            var productId   = Convert.ToInt32(row["ProductId"]);
            var productCode = new ProductDataService().GetProductById(productId).Code;

            return(new PackedProduct
            {
                OrderId = Convert.ToInt32(row["SalesId"]),
                PalletId = Convert.ToInt32(row["PalletId"]),
                ProductCode = productCode,
                Quantity = Convert.ToInt32(row["Quantity"])
            });
        }
        private void CreateSalesDetails(SalesDetail salesDetail, int salesId)
        {
            string salesDetailQuery = "Insert into Sales_Product (SalesId,ProductId,Quantity,UnitPrice) values (@salesid,@productid," +
                                      "@quantity,@unitprice);";

            _sqliteDataProvider.AddParameter("@salesid", salesId);
            var productId = new ProductDataService().GetProductByCode(salesDetail.ProductCode).Id;

            _sqliteDataProvider.AddParameter("@productid", productId);
            _sqliteDataProvider.AddParameter("@quantity", salesDetail.Quantity);
            _sqliteDataProvider.AddParameter("@unitprice", salesDetail.UnitPrice);
            _sqliteDataProvider.ExecuteScalar(salesDetailQuery);
        }
        public bool CreatePackedProduct(PackedProduct packedProduct)
        {
            const string query = "Insert into Packing (SalesId, PalletId, ProductId, Quantity) values " +
                                 "(@SalesId, @PalletId, @ProductId, @Quantity);" +
                                 "select last_insert_rowid();";

            _sqliteDataProvider.AddParameter("@SalesId", packedProduct.OrderId);
            _sqliteDataProvider.AddParameter("@PalletId", packedProduct.PalletId);
            var productId = new ProductDataService().GetProductByCode(packedProduct.ProductCode).Id;

            _sqliteDataProvider.AddParameter("@ProductId", productId);
            _sqliteDataProvider.AddParameter("@Quantity", packedProduct.Quantity);
            var queryResult = _sqliteDataProvider.ExecuteScalar(query);

            return(queryResult != null);
        }