Esempio n. 1
0
        /// <summary>
        /// Возвращает список элементов накладной
        /// </summary>
        /// <param name="id_invoice">ID накладной</param>
        /// <param name="isPurchase">TRUE если приходная накладная, FALSE если расходная</param>
        /// <param name="connection">соединение с БД</param>
        public static List <InvoiceItem> GetInvoiceItemList(int id_invoice, bool isPurchase, MySqlConnection connection)
        {
            List <InvoiceItem> Items = new List <InvoiceItem>();

            try
            {
                string table = (isPurchase) ? "PURCHASE_INVOICE_UNIT" : "SALES_INVOICE_UNIT";

                string sql = String.Format(@"SELECT * FROM `{0}` WHERE `{0}`.`ID_INVOICE` = {1}", table, id_invoice);

                using (MySqlCommand command = new MySqlCommand(sql, connection))
                {
                    using (MySqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            InvoiceItem item = new InvoiceItem();
                            item.ID_Invoice = id_invoice;

                            item.ID            = Conversion.ToInt(reader["ID"].ToString());
                            item.ID_Product    = Conversion.ToInt(reader["ID_PRODUCT"].ToString());
                            item.ProductCost   = Conversion.ToDouble(reader["PRODUCT_COST"].ToString());
                            item.ProductCoupon = Conversion.ToDouble(reader["PRODUCT_COUPON"].ToString());
                            item.Count         = Conversion.ToDouble(reader["COUNT"].ToString());
                            item.Cost          = Conversion.ToDouble(reader["COST"].ToString());
                            item.Coupon        = Conversion.ToDouble(reader["COUPON"].ToString());

                            Items.Add(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Dialog.ErrorMessage(null, "Ошибка получения списка элементов накладной", ex.Message);
            }

            return(Items);
        }
Esempio n. 2
0
        /// <summary>
        /// Создать элемент накладной
        /// </summary>
        /// <param name="id_invoice">ID накладной</param>
        /// <param name="id_product">ID товара</param>
        /// <param name="productCost">стоимость единицы товара</param>
        /// <param name="productCoupon">купон на единицу товара</param>
        /// <param name="count">количество товара</param>
        /// <param name="isPurshase">элемент приходной накладной</param>
        /// <returns>возвращает элемент накладной</returns>
        public static InvoiceItem CreateItem(int id_invoice, int id_product, double productCost, double productCoupon, double count, bool isPurshase)
        {
            InvoiceItem item = null;

            try
            {
                item = new InvoiceItem();

                item.ID_Invoice    = id_invoice;
                item.ID_Product    = id_product;
                item.ProductCost   = productCost;
                item.ProductCoupon = productCoupon;
                item.Count         = count;

                item.CreateItem(isPurshase);
            }
            catch (Exception ex)
            {
                item = null;
                Dialog.ErrorMessage(null, "Ошибка создания элемента накладной", ex.Message);
            }

            return(item);
        }