public bool UpdateUOMType(UOMType data)
        {
            bool          updated = false;
            SqlConnection con     = new SqlConnection(connectionString);
            SqlCommand    cmd     = new SqlCommand("UOMType_Update", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@GUID", data.GUID);
            cmd.Parameters.AddWithValue("@Type", data.Type);
            cmd.Parameters.AddWithValue("@UpDatedDate", data.UpDatedDate);
            cmd.Parameters.AddWithValue("@UpDatedBy", data.UpDatedBy);

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                updated = true;
            }
            catch (Exception e)
            {
                string error = e.Message;
                updated = false;
            }
            finally
            {
                con.Close();
            }
            return(updated);
        }
Beispiel #2
0
        public ActionResult EditUOMTypeForm(string GUID)
        {
            UOMType data = new UOMType();

            if (!string.IsNullOrEmpty(GUID))
            {
                data = da.GetAllUOMTypeByGUID(GUID);
            }
            return(PartialView("EditUOMTypeForm", data));
        }
        public UOMType GetAllUOMTypeByGUID(string GUID)
        {
            UOMType        mdl  = new UOMType();
            List <UOMType> list = this.GetAllUOMTypes();

            list = list.Where(a => (!string.IsNullOrEmpty(GUID)) ? a.GUID == GUID : true).ToList();
            if (list != null)
            {
                mdl = list.First();
            }
            return(mdl);
        }
Beispiel #4
0
 public ActionResult EditUOMType(UOMType data)
 {
     if (Session["UserInfo"] != null)
     {
         SystemUser userInfo = (SystemUser)Session["UserInfo"];
         if (!string.IsNullOrEmpty(data.GUID))
         {
             data.UpDatedDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
             data.UpDatedBy   = userInfo.GUID;
             bool updated = da.UpdateUOMType(data);
             if (updated)
             {
                 return(Json("Success", JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json("Fail", JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             data.GUID        = Guid.NewGuid().ToString();
             data.CreatedDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
             data.CreatedBy   = userInfo.GUID;
             data.UpDatedDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
             data.UpDatedBy   = userInfo.GUID;
             data.Status      = 1;
             bool added = da.AddUOMType(data);
             if (added)
             {
                 return(Json("Success", JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json("Fail", JsonRequestBehavior.AllowGet));
             }
         }
     }
     else
     {
         return(RedirectToAction("SessionTimeOut", "Error"));
     }
 }
Beispiel #5
0
        /// <summary>
        /// If the unit of measure is unclassified, from its base unit map find a matching unit type.
        /// </summary>
        /// <returns>Unit of measure</returns>
        public UnitOfMeasure Classify()
        {
            if (!UOMType.Equals(UnitType.UNCLASSIFIED))
            {
                // already classified
                return(this);
            }

            // base unit map
            Dictionary <UnitOfMeasure, int> uomBaseMap = GetReducer().Terms;

            // try to find this map in the unit types
            UnitType matchedType = UnitType.UNCLASSIFIED;

            foreach (UnitType unitType in UnitType.GetValues(typeof(UnitType)))
            {
                ConcurrentDictionary <UnitType, int> unitTypeMap = MeasurementSystem.GetSystem().GetTypeMap(unitType);

                if (unitTypeMap.Count != uomBaseMap.Count)
                {
                    // not a match
                    continue;
                }

                Boolean match = true;

                // same size, now check base unit types and exponents
                foreach (KeyValuePair <UnitOfMeasure, int> kvp in uomBaseMap)
                {
                    UnitType uomBaseType     = kvp.Key.UOMType;
                    int      uomBaseExponent = kvp.Value;

                    if (unitTypeMap.TryGetValue(uomBaseType, out int unitExponent))
                    {
                        // value is in map, check exponents
                        if (unitExponent != uomBaseExponent)
                        {
                            // not a match
                            match = false;
                            break;
                        }
                    }
                    else
                    {
                        // value not in map
                        match = false;
                        break;
                    }
                }

                if (match)
                {
                    matchedType = unitType;
                    break;
                }
            }

            if (!matchedType.Equals(UnitType.UNCLASSIFIED))
            {
                this.UOMType = matchedType;
            }

            return(this);
        }
Beispiel #6
0
        /// <summary>
        /// Build a string representation of this unit of measure
        /// </summary>
        /// <returns>String value</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            // type
            sb.Append(MeasurementSystem.UnitsManager.GetString("unit.type.text")).Append(' ').Append(UOMType.ToString()).Append(", ");

            // unit enumeration
            if (Enumeration.HasValue)
            {
                sb.Append(MeasurementSystem.UnitsManager.GetString("enum.text")).Append(' ').Append(Enumeration.ToString()).Append(", ");
            }

            // symbol
            sb.Append(MeasurementSystem.UnitsManager.GetString("symbol.text")).Append(' ').Append(Symbol);
            sb.Append(", ").Append(MeasurementSystem.UnitsManager.GetString("conversion.text")).Append(' ');

            // scaling factor
            if (ScalingFactor.CompareTo(1) != 0)
            {
                sb.Append(ScalingFactor.ToString()).Append(MULT);
            }

            // abscissa unit
            if (AbscissaUnit != null)
            {
                sb.Append(AbscissaUnit.Symbol);
            }

            // offset
            if (Offset.CompareTo(0d) != 0)
            {
                sb.Append(" + ").Append(Offset.ToString());
            }

            sb.Append(", ").Append(MeasurementSystem.UnitsManager.GetString("base.text")).Append(' ');

            // base symbol
            sb.Append(GetBaseSymbol());

            return(sb.ToString());
        }