Ejemplo n.º 1
0
		public decimal GetBaseUnitValue(Int64 ProductID, Int32 UnitIDToConvert, decimal Quantity, int BranchID = 0)
		{
			try
			{
				Products clsProduct = new Products(base.Connection, base.Transaction);
                //Int32 BaseUnitID = clsProduct.Details1(BranchID, ProductID).BaseUnitID;
                Int32 BaseUnitID = clsProduct.BaseUnitID(ProductID);
				
				Int32 origUnitIDToConvert = UnitIDToConvert;

				decimal ConvertedUnit = Quantity;

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandType = System.Data.CommandType.Text;

                while (BaseUnitID != UnitIDToConvert)
                {
                    string SQL = "SELECT " +
                                    "BaseUnitID, " +
                                    "BottomUnitValue, " +
                                    "BaseUnitValue " +
                                "FROM tblProductUnitMatrix " +
                                "WHERE ProductID = @ProductID " +
                                "AND BottomUnitID = @UnitIDToConvert ";

                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("@ProductID", ProductID);
                    cmd.Parameters.AddWithValue("@UnitIDToConvert", UnitIDToConvert);

                    cmd.CommandText = SQL;
                    System.Data.DataTable dt = new System.Data.DataTable("tblProductUnit");
                    base.MySqlDataAdapterFill(cmd, dt);
                    
                    int iCtr = 0;
                    foreach(System.Data.DataRow dr in dt.Rows)
                    {
                        iCtr++;
                        UnitIDToConvert = Int32.Parse(dr["BaseUnitID"].ToString());
                        ConvertedUnit = Decimal.Parse(dr["BaseUnitValue"].ToString()) * ConvertedUnit / Decimal.Parse(dr["BottomUnitValue"].ToString());
                    }
                    if (iCtr == 0) break;
                }

				return ConvertedUnit;
			}
			catch (Exception ex)
			{
				throw base.ThrowException(ex);
			}	
		}