コード例 #1
0
ファイル: s_add.cs プロジェクト: sriramanand/OrdersLK
        private void button3_Click(object sender, EventArgs e)
        {
            string mailOrder = null, orderQuery, orderItemQuery;
            float  totalBill = float.Parse(txtGrandTotal.Text);
            double totalCost = this.unitCount;

            try
            {
                if (!string.IsNullOrEmpty(txtInvoiceNo.Text) ||
                    !string.IsNullOrEmpty(this.tempBuyerId) ||
                    cartTable.Rows.Count != 0 ||
                    !string.IsNullOrEmpty(this.tempAgent))
                {
                    orderQuery = "INSERT INTO Orders (OrderId, OrderDate, OrderStatus, PaymentStatus, CustomerId, EmpId, TotalAmount, CostOfAmount) VALUES ("

                                 + "'" + this.tempOrderId + "', "
                                 + "'" + this.tempDate + "', "
                                 + "'Confirmed', "
                                 + "'Pending',"
                                 + "'" + this.tempBuyerId + "', "
                                 + "'" + this.tempAgent + "', "
                                 + totalBill + ","
                                 + totalCost + ")";

                    Functions.ExecuteQuery(orderQuery);


                    for (int i = 0; i < cartTable.Rows.Count - 1; i++)
                    {
                        string _orderItemId = Functions.getNextID("OrderItemId", "OrderItem", "OIT");
                        orderItemQuery = "INSERT INTO OrderItem (OrderItemId, OrderId, ProductId, Quantity) VALUES ("
                                         + "'" + _orderItemId + "',"
                                         + "'" + this.tempOrderId + "',"
                                         + "'" + cartTable.Rows[i].Cells[0].Value.ToString() + "',"
                                         + cartTable.Rows[i].Cells[3].Value + ")";

                        string _productAlter = "UPDATE Product SET QuantityAvailable = '"
                                               + (this.tempAvailableInt - Int32.Parse(cartTable.Rows[i].Cells[3].Value.ToString()))
                                               + "' WHERE ProductId = '" + cartTable.Rows[i].Cells[0].Value.ToString() + "'";

                        Functions.ExecuteQuery(orderItemQuery);
                        Functions.ExecuteQuery(_productAlter);

                        mailOrder += ""
                                     + cartTable.Rows[i].Cells[0].Value
                                     + " - " + cartTable.Rows[i].Cells[1].Value
                                     + " (" + cartTable.Rows[i].Cells[3].Value
                                     + ") =" + cartTable.Rows[i].Cells[4].Value
                                     + " \n";
                    }

                    MessageBox.Show(this, "Order has been placed.\nPlease wait the mail is being processed...");

                    if (!String.IsNullOrEmpty(this.tempMail))
                    {
                        try
                        {
                            mailOrder += "------------------------------------------ \n"
                                         + "Grand total = " + this.count + "\n";

                            emailThis mail = new emailThis();
                            mail.sendMail(this.tempMail, mailOrder);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(this, "Error", "Mail has not been sent.\nReason: " + ex);
                        }
                    }
                }

                else
                {
                    MessageBox.Show(this, "Invalid inputs", "Please recheck your entry");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error", "Invoice duplicating is not allowed\n" + ex);
            }
        }
コード例 #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (cartTable.RowCount > 1)
            {
                DialogResult dialogResult = MessageBox.Show("Do you wish to confirm the order?", "Confirm Order", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    string mailOrder = null, orderQuery, orderItemQuery;
                    float  totalBill = float.Parse(txtGrandTotal.Text);
                    double totalCost = this.unitCount;

                    try
                    {
                        if (!string.IsNullOrEmpty(this.tempOrderId) &&
                            (this.tempDate.ToString() != "" || !string.IsNullOrEmpty(this.tempDate.ToString()) || !string.IsNullOrWhiteSpace(this.tempDate.ToString())) &&
                            (!string.IsNullOrEmpty(tempBuyerId) || !string.IsNullOrWhiteSpace(tempBuyerId)) &&
                            (!string.IsNullOrEmpty(this.tempAgent) || !string.IsNullOrWhiteSpace(this.tempAgent)))

                        {
                            DisableAfterConfirm();

                            orderQuery = "INSERT INTO Orders (OrderId, OrderDate, OrderStatus, PaymentStatus, CustomerId, EmpId, TotalAmount, CostOfAmount) VALUES ("
                                         + "'" + this.tempOrderId + "', "
                                         + "'" + this.tempDate + "', "
                                         + "'Confirmed', "
                                         + "'Pending',"
                                         + "'" + tempBuyerId + "', "
                                         + "'" + this.tempAgent + "', "
                                         + totalBill + ","
                                         + totalCost + ")";

                            Functions.ExecuteQuery(orderQuery);


                            for (int i = 0; i < cartTable.Rows.Count - 1; i++)
                            {
                                string _orderItemId = Functions.getNextID("OrderItemId", "OrderItem", "OIT");
                                orderItemQuery = "INSERT INTO OrderItem (OrderItemId, OrderId, ProductId, Quantity) VALUES ("
                                                 + "'" + _orderItemId + "',"
                                                 + "'" + this.tempOrderId + "',"
                                                 + "'" + cartTable.Rows[i].Cells[0].Value.ToString() + "',"
                                                 + cartTable.Rows[i].Cells[3].Value + ")";

                                string _productAlter = "UPDATE Product SET QuantityAvailable = '"
                                                       + (this.tempAvailableInt - Int32.Parse(cartTable.Rows[i].Cells[3].Value.ToString()))
                                                       + "' WHERE ProductId = '" + cartTable.Rows[i].Cells[0].Value.ToString() + "'";

                                Functions.ExecuteQuery(orderItemQuery);
                                Functions.ExecuteQuery(_productAlter);

                                mailOrder += ""
                                             + cartTable.Rows[i].Cells[0].Value
                                             + " - " + cartTable.Rows[i].Cells[1].Value
                                             + " (" + cartTable.Rows[i].Cells[3].Value
                                             + ") =" + cartTable.Rows[i].Cells[4].Value
                                             + " \n";
                            }

                            if (!String.IsNullOrEmpty(this.tempMail))
                            {
                                MessageBox.Show(this, "Order has been placed.\nPlease wait the mail is being processed...");
                                try
                                {
                                    mailOrder += "------------------------------------------ \n"
                                                 + "Grand total = " + string.Concat(this.count, ".00");


                                    emailThis mail = new emailThis();
                                    //mail.sendMail(this.tempMail, mailOrder);

                                    if (mail.sendMail(this.tempMail, mailOrder))
                                    {
                                        MessageBox.Show("Mail has been sent to Customer");
                                    }
                                    newOrder();
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(this, "Error", "Mail has not been sent.\nReason: " + ex);
                                }
                            }
                            else
                            {
                                MessageBox.Show(this, "Order has been placed.");

                                DialogResult dialogResultEmail = MessageBox.Show("Would you like to update the customer profile with an Email to send automated order?", "Update Customer details", MessageBoxButtons.YesNo);
                                if (dialogResultEmail == DialogResult.Yes)
                                {
                                    b_update_single bu = new b_update_single();
                                    bu.ShowDialog();
                                    Console.WriteLine("Email added");
                                    newOrder();
                                }
                                if (dialogResultEmail == DialogResult.No)
                                {
                                    newOrder();
                                }
                            }
                        }

                        else
                        {
                            MessageBox.Show(this, "Invalid inputs", "Please recheck your entry");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, "Error", "Invoice duplicating is not allowed\n" + ex);
                    }
                }
            }

            else
            {
                MessageBox.Show("Please add some item before checking out.");
            }
        }