public static double ConvertUOM(decimal fromUOM, decimal toUOM, double fromValue, bool allowSameUOM)
        {
            double toValue = fromValue;

            if (fromUOM > 0 && (allowSameUOM || fromUOM != toUOM))
            {
                UOM      uom  = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == fromUOM);
                UOM_XREF xref = uom.UOM_XREF.FirstOrDefault(x => x.UOM_FROM == fromUOM && x.UOM_TO == toUOM);
                if (xref != null)
                {
                    toValue = fromValue * (double)xref.CONVERSION;
                }
            }

            return(toValue);
        }
        public static UOM UpdateUOM(PSsqmEntities entities, UOM uom, decimal convertToUOMID, double conversionFactor)
        {
            UOM ret;

            try
            {
                if (uom.UOM_ID > 0)
                {
                    ret = (from u in entities.UOM.Include("UOM_XREF") where u.UOM_ID == uom.UOM_ID select u).Single();
                    if (ret != null)
                    {
                        ret = (UOM)SQMModelMgr.CopyObjectValues(ret, uom, false);
                        ret.UOM_XREF.FirstOrDefault().UOM_TO     = convertToUOMID;
                        ret.UOM_XREF.FirstOrDefault().CONVERSION = Convert.ToDecimal(conversionFactor);
                        entities.SaveChanges();
                    }
                }
                else
                {
                    entities.AddToUOM(uom);
                    entities.SaveChanges();
                    if (convertToUOMID > 0 && uom.UOM_ID > 0)
                    {
                        UOM_XREF xref = new UOM_XREF();
                        xref.UOM_FROM   = uom.UOM_ID;
                        xref.UOM_TO     = convertToUOMID;
                        xref.CONVERSION = Convert.ToDecimal(conversionFactor);
                        xref.OPERATOR   = "MULT";
                        entities.AddToUOM_XREF(xref);
                        entities.SaveChanges();
                    }
                }

                ret = uom;
            }
            catch
            {
                ret = null;
            }

            return(ret);
        }
示例#3
0
        public int BindProfileMeasure(EHS_PROFILE_MEASURE pm)
        {
            int status = 0;

            divMetricUOM.Visible = true;
            divUserUOM.Visible   = false;
            if (pm == null)
            {
                ddlMetricCategory.SelectedIndex = ddlMetricID.SelectedIndex = ddlMetricDisposalCode.SelectedIndex = ddlMetricUOM.SelectedIndex = ddlMetricResponsible.SelectedIndex = 0;
                ddlMetricCurrency.SelectedValue = staticProfile.Plant.CURRENCY_CODE;
                lblMetricName.Text  = lblDisposalDesc.Text = "";
                tbMetricPrompt.Text = "";
            }
            else
            {
                staticProfileMeasure = pm;
                staticMeasure        = pm.EHS_MEASURE;

                //  ScriptManager.RegisterStartupScript(this, GetType(), "enablelist", "enableListItems('ddlMetricCategory','ddlMetricID'); enableListItems('ddlMetricUOMCategory','ddlMetricUOM');", true);

                ddlMetricCategory.SelectedValue = pm.EHS_MEASURE.MEASURE_CATEGORY;
                ddlMetricID.SelectedValue       = pm.EHS_MEASURE.MEASURE_CATEGORY + "|" + pm.EHS_MEASURE.MEASURE_ID.ToString();
                lblMetricName.Text  = pm.EHS_MEASURE.MEASURE_CD;
                tbMetricPrompt.Text = pm.MEASURE_PROMPT;
                ddlMetricRegStatus.SelectedValue    = pm.REG_STATUS;
                ddlMetricDisposalCode.SelectedValue = pm.UN_CODE;
                if (!string.IsNullOrEmpty(pm.UN_CODE))
                {
                    lblDisposalDesc.Text = disposalList.FirstOrDefault(l => l.UN_CODE == pm.UN_CODE).DESCRIPTION;
                }
                else
                {
                    lblDisposalDesc.Text = "";
                }

                if (pm.EHS_MEASURE.MEASURE_CATEGORY == "EUTL" || pm.EHS_MEASURE.MEASURE_CATEGORY == "PROD")
                {
                    tbWasteCode.Enabled = false;
                    tbWasteCode.Text    = "";
                }
                else
                {
                    tbWasteCode.Enabled = true;
                    tbWasteCode.Text    = pm.WASTE_CODE;
                }

                ddlMetricCurrency.SelectedValue = pm.DEFAULT_CURRENCY_CODE;
                if (pm.RESPONSIBLE_ID > 0)
                {
                    ddlMetricResponsible.SelectedValue = pm.RESPONSIBLE_ID.ToString();
                }
                if (pm.DEFAULT_UOM > 0)
                {
                    UOM uom = staticUOM = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == pm.DEFAULT_UOM);
                    if (uom != null)
                    {
                        ddlMetricUOM.SelectedValue = WebSiteCommon.PackItemValue(uom.UOM_CATEGORY, uom.UOM_ID.ToString());
                        if (uom.UOM_CATEGORY == "CUST")
                        {
                            divUserUOM.Visible = true;
                            tbUserUOMName.Text = uom.UOM_NAME;
                            tbUserUOMCode.Text = uom.UOM_CD;
                            UOM_XREF xref = uom.UOM_XREF.FirstOrDefault();
                            if (xref != null)
                            {
                                UOM refUOM = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == xref.UOM_TO);
                                if (refUOM != null)
                                {
                                    ddlUserUOMConvertTo.SelectedValue = WebSiteCommon.PackItemValue(refUOM.UOM_CATEGORY, refUOM.UOM_ID.ToString());
                                    tbUserUOMConversionFactor.Text    = SQMBasePage.FormatValue(xref.CONVERSION, 4);
                                }
                            }
                        }
                    }
                }

                ddlMetricStatus.SelectedValue = pm.STATUS;

                cbMetricNegValue.Checked = (bool)pm.NEG_VALUE_ALLOWED;
                cbMetricRequired.Checked = (bool)pm.IS_REQUIRED;
            }

            UpdateListTitles();
            pnlMetricEdit.Enabled = btnMetricCancel.Enabled = btnMetricSave.Enabled = true;

            return(status);
        }