Beispiel #1
0
        private void Row_Changed(object sender, DataGridCellEditEndingEventArgs e)
        {
            if (e.Column.Header == "Qty")
            {
                DataTable Dat = ItemsDGV.DataContext as DataTable;
                float     to_rest_Qty = 0; float to_rest_Cost = 0; float from_rest_Qty = 0; float from_rest_Cost = 0;
                for (int i = 0; i < Dat.Columns.Count; i++)
                {
                    Dat.Columns[i].ReadOnly = false;
                }
                string ItemCode = (e.Row.Item as DataRowView).Row["Code"].ToString();

                try
                {
                    if ((bool)(e.Row.Item as DataRowView).Row["Recipe"] == true)
                    {
                        DataTable TheValues = Classes.RetriveCostAndQtyRecipes(Resturant.Text, From_Kitchen.Text, ItemCode);
                        try
                        {
                            from_rest_Qty  = float.Parse(TheValues.Rows[0][0].ToString());
                            from_rest_Cost = float.Parse(TheValues.Rows[0][1].ToString());
                        }
                        catch
                        {
                            from_rest_Qty  = 0;
                            from_rest_Cost = 0;
                        }
                        TheValues = Classes.RetriveCostAndQtyRecipes(Resturant.Text, To_Kitchen.Text, ItemCode);
                        try
                        {
                            to_rest_Qty  = float.Parse(TheValues.Rows[0][0].ToString());
                            to_rest_Cost = float.Parse(TheValues.Rows[0][1].ToString());
                        }
                        catch
                        {
                            to_rest_Qty  = 0;
                            to_rest_Cost = 0;
                        }

                        Dat.Rows[e.Row.GetIndex()]["Qty"] = (float.Parse((e.EditingElement as TextBox).Text)).ToString();
                        Dat.Rows[e.Row.GetIndex()][From_Kitchen.Text + " Qty"]        = (from_rest_Qty - float.Parse((e.EditingElement as TextBox).Text)).ToString();
                        Dat.Rows[e.Row.GetIndex()][From_Kitchen.Text + " Unit Cost"]  = from_rest_Cost.ToString();
                        Dat.Rows[e.Row.GetIndex()][From_Kitchen.Text + " Total Cost"] = (from_rest_Cost * (from_rest_Qty - float.Parse((e.EditingElement as TextBox).Text))).ToString();

                        Dat.Rows[e.Row.GetIndex()][To_Kitchen.Text + " Qty"]        = (to_rest_Qty + float.Parse((e.EditingElement as TextBox).Text)).ToString();
                        Dat.Rows[e.Row.GetIndex()][To_Kitchen.Text + " Unit Cost"]  = (((to_rest_Cost * to_rest_Qty) + (float.Parse((e.EditingElement as TextBox).Text) * from_rest_Cost)) / (to_rest_Qty + (float.Parse((e.EditingElement as TextBox).Text)))).ToString();
                        Dat.Rows[e.Row.GetIndex()][To_Kitchen.Text + " Total Cost"] = (((to_rest_Cost * to_rest_Qty) + (float.Parse((e.EditingElement as TextBox).Text) * from_rest_Cost)) / (to_rest_Qty + (float.Parse((e.EditingElement as TextBox).Text))) * (to_rest_Qty + float.Parse((e.EditingElement as TextBox).Text))).ToString();
                    }
                    else
                    {
                        DataTable TheValues = Classes.RetriveCostAndQty(Resturant.Text, From_Kitchen.Text, ItemCode);
                        try
                        {
                            from_rest_Qty  = float.Parse(TheValues.Rows[0][0].ToString());
                            from_rest_Cost = float.Parse(TheValues.Rows[0][1].ToString());
                        }
                        catch
                        {
                            from_rest_Qty  = 0;
                            from_rest_Cost = 0;
                        }
                        TheValues = Classes.RetriveCostAndQty(Resturant.Text, To_Kitchen.Text, ItemCode);
                        try
                        {
                            to_rest_Qty  = float.Parse(TheValues.Rows[0][0].ToString());
                            to_rest_Cost = float.Parse(TheValues.Rows[0][1].ToString());
                        }
                        catch
                        {
                            to_rest_Qty  = 0;
                            to_rest_Cost = 0;
                        }

                        Dat.Rows[e.Row.GetIndex()]["Qty"] = (float.Parse((e.EditingElement as TextBox).Text)).ToString();
                        Dat.Rows[e.Row.GetIndex()][From_Kitchen.Text + " Qty"]        = (from_rest_Qty - float.Parse((e.EditingElement as TextBox).Text)).ToString();
                        Dat.Rows[e.Row.GetIndex()][From_Kitchen.Text + " Unit Cost"]  = from_rest_Cost.ToString();
                        Dat.Rows[e.Row.GetIndex()][From_Kitchen.Text + " Total Cost"] = (from_rest_Cost * (from_rest_Qty - float.Parse((e.EditingElement as TextBox).Text))).ToString();

                        Dat.Rows[e.Row.GetIndex()][To_Kitchen.Text + " Qty"]        = (to_rest_Qty + float.Parse((e.EditingElement as TextBox).Text)).ToString();
                        Dat.Rows[e.Row.GetIndex()][To_Kitchen.Text + " Unit Cost"]  = (((to_rest_Cost * to_rest_Qty) + (float.Parse((e.EditingElement as TextBox).Text) * from_rest_Cost)) / (to_rest_Qty + (float.Parse((e.EditingElement as TextBox).Text)))).ToString();
                        Dat.Rows[e.Row.GetIndex()][To_Kitchen.Text + " Total Cost"] = (((to_rest_Cost * to_rest_Qty) + (float.Parse((e.EditingElement as TextBox).Text) * from_rest_Cost)) / (to_rest_Qty + (float.Parse((e.EditingElement as TextBox).Text))) * (to_rest_Qty + float.Parse((e.EditingElement as TextBox).Text))).ToString();
                    }
                    try
                    {
                        double totalPrice = 0;
                        for (int i = 0; i < ItemsDGV.Items.Count; i++)
                        {
                            try
                            {
                                totalPrice += (Convert.ToDouble(((DataRowView)ItemsDGV.Items[i]).Row.ItemArray[5]) * Convert.ToDouble(((DataRowView)ItemsDGV.Items[i]).Row.ItemArray[7]));
                            }
                            catch
                            {
                            }
                        }
                        NUmberOfItems.Text = (ItemsDGV.Items.Count).ToString();
                        Total_Price.Text   = (totalPrice).ToString();
                    }
                    catch { }
                    for (int i = 0; i < Dat.Columns.Count; i++)
                    {
                        Dat.Columns[i].ReadOnly = true;
                    }
                    Dat.Columns["Qty"].ReadOnly = false;
                    ItemsDGV.DataContext        = Dat;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    (e.EditingElement as TextBox).Text = "";
                }
            }
        }       //Done