private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int      orderId  = (int)dataGridView1[1, e.RowIndex].Value;
            string   custName = (string)dataGridView1[2, e.RowIndex].Value;
            DateTime time     = (DateTime)dataGridView1[3, e.RowIndex].Value;
            Order    order    = new Order()
            {
                Id        = orderId,
                CustName  = custName,
                TimeStamp = time
            };

            order.OrderItem = new OrderItem(orderId);
            order.OrderItem.GetAllItem();
            order.ItemList = order.OrderItem.ItemList;
            order.OrderItem.totalSellPriceAmount();
            order.OrderItem.totalCostAmount();
            Bill bill = new Bill();

            bill.GenerateBill(order);
            bill.SaveBillToDatabase();
            MessageBox.Show(bill.TotalAmountPaid + " tk, Payment Successful.");
            SellLog sLog = new SellLog()
            {
                TimeStamp = order.TimeStamp,
                SellPrice = order.OrderItem.TotalSellPrice,
                TotalCost = order.OrderItem.TotalCost
            };

            order.DeleteOrder();
            LoadDataGridView();
        }
Example #2
0
        public void DeleteOrder()
        {
            SellLog sellLog = new SellLog()
            {
                TimeStamp = this.TimeStamp,
                SellPrice = GetTotalSellPrice(),
                Tax       = CalculateTax(),
                TotalCost = GetTotalCost()
            };

            sellLog.InsertIntoSellLog();
            new DataAccess().ExecuteNonQuery($"DELETE FROM OrderItem WHERE OrderId = {Id}");
            new DataAccess().ExecuteNonQuery($"DELETE FROM OrderLog WHERE Id = {Id}");
        }
        public List <SellLog> GetAllSellLog()
        {
            SqlDataReader  reader      = new DataAccess().ExecuteQuery(@"SELECT * FROM SellLog");
            List <SellLog> SellLogList = new List <SellLog>();

            while (reader.Read())
            {
                SellLog selllog = new SellLog();
                selllog.Id        = reader.GetInt32(0);
                selllog.TimeStamp = DateTime.Parse(reader.GetString(1));
                selllog.SellPrice = reader.GetDouble(2);
                selllog.Tax       = reader.GetDouble(3);
                selllog.TotalCost = reader.GetDouble(4);
                SellLogList.Add(selllog);
            }
            return(SellLogList);
        }
        public void GenerateDailyLog()
        {
            Date = DateTime.Today;
            SellLog sl = new SellLog();

            TotalIncome = sl.GetTotalDailySell(Date);
            double TotalCost = sl.GetTotalDailyCost(Date);

            Profit   = TotalIncome - TotalCost;
            TotalTax = sl.GetTotalDailyTax(Date);
            int count = new DataAccess().CountExistingRows($"SELECT COUNT(Id) FROM DailyLog WHERE Date = '{Date}'");

            if (count > 0)
            {
                new DataAccess().ExecuteNonQuery($"UPDATE DailyLog SET Date = '{Date}', TotaIIncome = {TotalIncome}, Profit = {Profit}, TaxMoney = {TotalTax}");
            }
            else
            {
                new DataAccess().ExecuteNonQuery($"INSERT INTO DailyLog VALUES ('{Date}', {TotalIncome}, {Profit}, {TotalTax})");
            }
        }