コード例 #1
0
ファイル: Sales.cs プロジェクト: EngrKhurramShahzad/BMS
        private void Update_Button_Click(object sender, EventArgs e)
        {
            bool result = false;

            try
            {
                string orderType = "";
                if (Current_RadioButton.Checked == true)
                {
                    orderType = Current_RadioButton.Text;
                }
                else
                {
                    orderType = Delivery_RadioButton.Text;
                }
                string status = "";
                if (PAmount_Textbox.Text == "0")
                {
                    status = "Unpaid";
                }
                else if (Convert.ToDouble(Balance_Textbox.Text) == 0)
                {
                    status = "Paid";
                }
                else if (Convert.ToDouble(Balance_Textbox.Text) > 0 && Convert.ToDouble(PAmount_Textbox.Text) > 0)
                {
                    status = "Partially Paid";
                }
                int cusID = 0;
                if (Customer_CBox.Text == "Mr Walking Customer")
                {
                    cusID = 0;
                }
                else
                {
                    cusID = Convert.ToInt32(db.ReturnValueFromDB("select CustomerID from Customer where Name ='" + Customer_CBox.Text + "'"));
                }
                if (Convert.ToInt32(Balance_Textbox.Text) == 0)
                {
                    db.DataManupulationOperation("insert into Sales(OrderID,OrderType,OrderDate,DeliveryDate,TotalQty,TotalAmount,Remarks,Status,SalesmanID,CustomerID) values('" + Convert.ToInt32(ID_Box.Text) + "','" + orderType + "','" + DateTime.Now + "','" + Convert.ToDateTime(DDate_DTP.Text) + "','" + TQty_Textbox.Text + "','" + TAmount_Textbox.Text + "','" + Remarks_Box.Text + "','" + status + "','" + smanID + "','" + cusID + "')");
                    result = true;
                }
                else if (Convert.ToInt32(Balance_Textbox.Text) > 0)
                {
                    if (Customer_CBox.Text == "Mr Walking Customer")
                    {
                        MetroMessageBox.Show(this, "Loan can only be given to Parmanent Customers...!!!", "Error..!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        result = false;
                    }
                    else
                    {
                        db.DataManupulationOperation("Update Customer set Balance+='" + Balance_Textbox.Text + ",Dues+='" + Dues_Textbox.Text + "' where Name='" + Customer_CBox.Text + "'");
                        db.DataManupulationOperation("insert into Sales(OrderID,OrderType,OrderDate,DeliveryDate,TotalQty,TotalAmount,Remarks,Status,SalesmanID,CustomerID) values('" + Convert.ToInt32(ID_Box.Text) + "','" + orderType + "','" + DateTime.Now + "','" + Convert.ToDateTime(DDate_DTP.Text) + "','" + TQty_Textbox.Text + "','" + TAmount_Textbox.Text + "','" + Remarks_Box.Text + "','" + status + "','" + smanID + "','" + cusID + "')");
                        result = true;
                    }
                }
                for (int i = 0; i < Item_Grid.RowCount; i++)
                {
                    string Name     = Item_Grid.Rows[i].Cells[0].Value.ToString();
                    double qty      = Convert.ToDouble(Item_Grid.Rows[i].Cells[1].Value.ToString());
                    string category = Item_Grid.Rows[i].Cells[3].Value.ToString();
                    double amt      = Convert.ToDouble(Item_Grid.Rows[i].Cells[5].Value.ToString());
                    int    itemID   = 0;
                    double price    = 0;
                    if (result == true)
                    {
                        db.DataManupulationOperation("Delete from ReportData where OrderID<'" + ID_Box.Text + "'");
                        if (category == "Bakery Products")
                        {
                            itemID = Convert.ToInt32(db.ReturnValueFromDB("Select ItemID from BakeryItems where Name='" + Name + "'"));
                            price  = Convert.ToDouble(db.ReturnValueFromDB("Select Price from BakeryItems where Name='" + Name + "'"));
                            db.DataManupulationOperation("insert into SalesLineItems(OrderID,BakeryItemID,Qty,Amount,Category) values('" + Convert.ToInt32(ID_Box.Text) + "','" + itemID + "','" + qty + "','" + amt + "','" + category + "')");
                            db.DataManupulationOperation("Update BakeryItems set Qty-='" + qty + "' where ItemID='" + itemID + "'");
                        }
                        else
                        {
                            itemID = Convert.ToInt32(db.ReturnValueFromDB("Select ID from CompanyProducts where Name='" + Name + "'"));
                            price  = Convert.ToDouble(db.ReturnValueFromDB("Select Price from CompanyProducts where Name='" + Name + "'"));
                            db.DataManupulationOperation("insert into SalesLineItems(OrderID,CompanyProductID,Qty,Amount,Category) values('" + Convert.ToInt32(ID_Box.Text) + "','" + itemID + "','" + qty + "','" + amt + "','" + category + "')");
                            db.DataManupulationOperation("Update CompanyProducts set Qty-='" + qty + "' where ID='" + itemID + "'");
                        }
                        db.DataManupulationOperation("insert into ReportData(OrderID,Item_Name,Qty,Price,Amount) values('" + Convert.ToInt32(ID_Box.Text) + "','" + Name + "','" + qty + "','" + price + "','" + amt + "')");
                    }
                    else
                    {
                        result = false;
                    }
                }
                if (result == true)
                {
                    Reciept    rp    = new Reciept();
                    TextObject Ctext = (TextObject)rp.ReportDefinition.Sections["Section2"].ReportObjects["Text2"];
                    Ctext.Text = Customer_CBox.Text;
                    TextObject OrderID = (TextObject)rp.ReportDefinition.Sections["Section2"].ReportObjects["Text4"];
                    OrderID.Text = ID_Box.Text;
                    TextObject OrderType = (TextObject)rp.ReportDefinition.Sections["Section2"].ReportObjects["Text6"];
                    OrderType.Text = orderType;
                    TextObject ODate = (TextObject)rp.ReportDefinition.Sections["Section2"].ReportObjects["Text8"];
                    ODate.Text = DateTime.Now.ToString("dd-MM-yyyy");
                    TextObject DDate = (TextObject)rp.ReportDefinition.Sections["Section2"].ReportObjects["Text9"];
                    DDate.Text = Convert.ToDateTime(DDate_DTP.Text).ToString("dd-MM-yyyy");
                    TextObject TotQty = (TextObject)rp.ReportDefinition.Sections["Section4"].ReportObjects["Text17"];
                    TotQty.Text = TQty_Textbox.Text;
                    TextObject TotAmt = (TextObject)rp.ReportDefinition.Sections["Section4"].ReportObjects["Text19"];
                    TotAmt.Text = TAmount_Textbox.Text;
                    TextObject Paid = (TextObject)rp.ReportDefinition.Sections["Section4"].ReportObjects["Text21"];
                    Paid.Text = PAmount_Textbox.Text;
                    TextObject Return = (TextObject)rp.ReportDefinition.Sections["Section4"].ReportObjects["Text23"];
                    Return.Text = Return_Textbox.Text;
                    TextObject Dues = (TextObject)rp.ReportDefinition.Sections["Section4"].ReportObjects["Text25"];
                    Dues.Text = Dues_Textbox.Text;
                    TextObject Balance = (TextObject)rp.ReportDefinition.Sections["Section4"].ReportObjects["Text27"];
                    Balance.Text = Balance_Textbox.Text;
                    TextObject Salesman = (TextObject)rp.ReportDefinition.Sections["Section4"].ReportObjects["Text32"];
                    Salesman.Text = Salesman_Label.Text;
                    rp.Refresh();
                    rp.PrintOptions.PaperSize = PaperSize.PaperA4;
                    rp.PrintToPrinter(1, false, 1, 1);
                    MetroMessageBox.Show(this, "Record Has been Updated...!!!", "Production Done...!!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    db.DataManupulationOperation("Delete from ReportData where OrderID='" + ID_Box.Text + "'");
                    refresh();
                }
            }
            catch (Exception ex)
            {
                MetroMessageBox.Show(this, ex.Message);
                MetroMessageBox.Show(this, "Failed to Update Data...!!!", "Insertion Error..!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }