public void payOrder(string oID, decimal payment) { var test = new DatabaseConn(); // toDo: 1 insert for payment var present_pay = test.Select("order_payment", "SUM(payment)") .NJoin("orders") .Where("order_id", oID) .Group("order_id") .GetQueryData() .Rows[0][0]; decimal total_pay = Convert.ToDecimal(present_pay) + payment; MessageBox.Show(total_pay.ToString()); test.Insert("order_payment", "order_id", oID, "payment", payment.ToString(), "payment_date", DateTime.Now.ToString("yyyy-MM-dd")) .GetQueryData(); var total_price = test.Select("orderline", "SUM(total_price)") .Where("order_id", oID) .Group("order_id") .GetQueryData() .Rows[0][0]; if (total_pay >= total_price) { test.Update("orders", "payment_status", "1") .Where("order_id", oID) .GetQueryData(); } showOrderDetails(); }
public void claimOrder(string olID, decimal quantity) { if (quantity == 0) { return; } var itemDetails = conn.Select("orderline", "quantity", "quantity_claimed") .Where("orderline_id", olID) .GetQueryData(); decimal quantityClaimed = Convert.ToDecimal(itemDetails.Rows[0][1].ToString()); decimal total = Convert.ToDecimal(itemDetails.Rows[0][0].ToString()); decimal max = total - quantityClaimed; //checks if claimed quantity is more than possible, if true will set quantity to max possible quantity = quantity > max ? max : quantity; quantityClaimed += quantity; conn.Update("orderline", "quantity_claimed", quantityClaimed.ToString()) .Where("orderline_id", olID) .GetQueryData(); conn.Insert("order_claim", "orderline_id", olID, "quantity_no", quantity.ToString(), "date_claimed", DateTime.Now.ToString("yyyy-MM-dd")) .GetQueryData(); showOrderDetails(); }