Beispiel #1
0
        public WeightStruct GetContainerCost(int nWeightID, string sContainerTypeID)
        {
            int nTypeCatalog    = GetTypeCatalog(nWeightID);
            OleDbDataAdapter da = new OleDbDataAdapter();
            OleDbCommand     sc = new OleDbCommand();
            DataSet          ds = new DataSet();

            sc.Connection = mvarConnection;
            if (mvarConnection.State == ConnectionState.Closed)
            {
                mvarConnection.Open();
            }

            sc.CommandType = CommandType.Text;

            string strSQL = "";

            if (nTypeCatalog != 0) // not master
            {
                strSQL = "SELECT ContainerCost, ContainerTareWeight" + "\n\r";
                strSQL = strSQL + "FROM ContainerSubTypes " + "\n\r";
                strSQL = strSQL + "WHERE TypeCatalogID = " + nTypeCatalog.ToString() + " AND TypeID = '" + sContainerTypeID + "'";
                strSQL = strSQL + " AND Enabled = true";
            }
            else
            {
                strSQL = "SELECT Cost, TareWeight" + "\n\r";
                strSQL = strSQL + "FROM ContainerType " + "\n\r";
                strSQL = strSQL + "WHERE TypeID = '" + sContainerTypeID + "'";
            }

            sc.CommandText   = strSQL;
            da.SelectCommand = sc;

            try
            {
                da.Fill(ds);
            }
            catch (OleDbException e)
            {
                MessageBox.Show(e.Message, "");
            }

            if (ds.Tables[0].Rows.Count < 1)
            {
                return(null); // FoodTypeID not found
            }
            WeightStruct weight = new WeightStruct();

            weight.ContainerCost   = decimal.Parse(ds.Tables[0].Rows[0][0].ToString());
            weight.ContainerWeight = decimal.Parse(ds.Tables[0].Rows[0][1].ToString());
            return(weight);
        }
Beispiel #2
0
        private void gridViewWaste_CellChange(object sender, CellEventArgs e)
        {
            //   Use the BeforeEnterEditMode event to position the edit controls
            UltraGridCell objCell = this.gridViewWaste.ActiveCell;

            //   This should be impossible, but its good practice to check
            //   to make sure there is an active cell before continuing
            if (objCell == null)
            {
                return;
            }
            //   Get the UIElement associated with the active cell, which we will
            //   need so we can get the size and location of the cell

            if (objCell.IsDataCell && objCell.Band.Key == "Weights") // change cost for weights
            {
                WeightStruct weight = new WeightStruct();
                int          nID    = int.Parse(objCell.Row.Cells["ID"].Value.ToString());

                //   The edit control we will use depends on which column we are editing
                //   The values of the identity fields are not very useful to the end user.
                //   Let's display the name in these columns instead,
                //   using the intrisic ComboBox control
                if (objCell.Column.Key == "FoodTypeID")
                {
                    weight = m_VWAWeightsData.GetFoodCost(nID, objCell.Column.ValueList.GetValue(objCell.Column.ValueList.SelectedItemIndex).ToString());
                    if (weight != null)
                    {
                        objCell.Row.Cells["FoodTypeCost"].SetValue(weight.FoodCost, true);
                    }
                    else // wrong FoodTypeID
                    {
                        MessageBox.Show("This Food Type is not allowded for this Type Catalog", "WVA Error");
                        objCell.Selected = true;
                        return; // let user to change food type
                    }
                }
                else
                if (objCell.Column.Key == "ContainerTypeID")
                {
                    weight = m_VWAWeightsData.GetContainerCost(nID, objCell.Column.ValueList.GetValue(objCell.Column.ValueList.SelectedItemIndex).ToString());
                    if (weight != null)
                    {
                        objCell.Row.Cells["ContainerCost"].SetValue(weight.ContainerCost, true);
                        objCell.Row.Cells["ContainerWeight"].SetValue(weight.ContainerWeight, true);
                    }
                    else     // wrong ContainerTypeID
                    {
                        MessageBox.Show("This Container Type is not allowded for this Type Catalog", "WVA Error");
                        objCell.Selected = true;
                        return;     // let user to change food type
                    }
                }

                int    nItems   = int.Parse(objCell.Row.Cells["NItems"].Value.ToString());
                string discount = "1";
                if (objCell.Row.Cells.Exists("FoodTypeDiscount"))
                {
                    discount = objCell.Row.Cells["FoodTypeDiscount"].Value.ToString();
                }
                weight = new WeightStruct(objCell.Row.Cells["FoodTypeCost"].Value.ToString(), discount,
                                          objCell.Row.Cells["Weight"].Value.ToString(), objCell.Row.Cells["ContainerCost"].Value.ToString(),
                                          objCell.Row.Cells["ContainerWeight"].Value.ToString(), objCell.Row.Cells["NItems"].Value.ToString());

                if ((objCell.Column.Key == "FoodTypeCost") || (objCell.Column.Key == "Weight") || (objCell.Column.Key == "ContainerWeight") ||
                    (objCell.Column.Key == "ContainerCost") || (objCell.Column.Key == "NItems"))
                {
                    try
                    {
                        string str = objCell.Text;
                        // remove mask symbols to retrieve editing values
                        str = Regex.Match(str, @"(\d+\,?\d+\.?\d*|\d+\.?\d*|\.\d+)").ToString();
                        if (objCell.Column.Key == "FoodTypeCost")
                        {
                            weight.FoodCost = decimal.Parse(str);
                        }
                        if (objCell.Column.Key == "Weight")
                        {
                            weight.Weight = decimal.Parse(str);
                        }
                        if (objCell.Column.Key == "ContainerCost")
                        {
                            weight.ContainerCost = decimal.Parse(str);
                        }
                        if (objCell.Column.Key == "ContainerWeight")
                        {
                            weight.ContainerWeight = decimal.Parse(str);
                        }
                        if (objCell.Column.Key == "NItems")
                        {
                            str    = Regex.Match(str, @"(\d+)").ToString();
                            nItems = int.Parse(str);
                        }
                    } catch (Exception)
                    {
                        return;
                    }
                }
                if ((objCell.Column.Key == "FoodTypeID") || (objCell.Column.Key == "FoodTypeCost") || (objCell.Column.Key == "Weight") ||
                    (objCell.Column.Key == "ContainerTypeID") || (objCell.Column.Key == "ContainerWeight") ||
                    (objCell.Column.Key == "ContainerCost") || (objCell.Column.Key == "NItems"))
                {
                    objCell.Row.Cells["WasteCost"].SetValue(weight.WasteCost * nItems, true);
                }
            }
        }