Beispiel #1
0
        public PROB_VERIFY_VERS AddVerifyTrial()
        {
            PROB_VERIFY_VERS newTrial = new PROB_VERIFY_VERS();

            newTrial = (PROB_VERIFY_VERS)SQMModelMgr.CopyObjectValues(newTrial, this.ProbCase.PROB_VERIFY, false);
            newTrial.VERIFY_TRIAL_NO = this.ProbCase.PROB_VERIFY.PROB_VERIFY_VERS.Count + 1;
            this.Entities.AddToPROB_VERIFY_VERS(newTrial);
            foreach (PROB_CAUSE_ACTION action in this.ProbCase.PROB_CAUSE_ACTION)
            {
                PROB_CAUSE_ACTION_VERS trial = new PROB_CAUSE_ACTION_VERS();
                trial = (PROB_CAUSE_ACTION_VERS)SQMModelMgr.CopyObjectValues(trial, action, false);
                trial.VERIFY_TRIAL_NO = newTrial.VERIFY_TRIAL_NO;
                this.Entities.AddToPROB_CAUSE_ACTION_VERS(trial);
            }
            try
            {
                this.Entities.SaveChanges();
            }
            catch (Exception e)
            {
                //  SQMLogger.LogException(e);
                newTrial = null;
            }

            return(newTrial);
        }
        protected void btnMeasureSave_Click(object sender, EventArgs e)
        {
            bool success;

            if (hfOper.Value == "add")
            {
                staticMeasure            = new EHS_MEASURE();
                staticMeasure.COMPANY_ID = SessionManager.SessionContext.ActiveCompany().COMPANY_ID;
                staticMeasure.STATUS     = "A";
            }
            else
            {
                staticMeasure = SQMResourcesMgr.LookupEHSMeasure(entities, staticMeasure.MEASURE_ID, "");
            }

            btnMeasureSave.Enabled = false;
            hfOper.Value           = "";

            staticMeasure.MEASURE_CATEGORY    = ddlMeasureCategory.SelectedValue;
            staticMeasure.STD_CURRENCY_CODE   = ddlMeasureCurrency.SelectedValue;
            staticMeasure.MEASURE_SUBCATEGORY = ddlMeasureSubcategory.SelectedValue;
            staticMeasure.STATUS  = ddlMeasureStatus.SelectedValue;
            staticMeasure.STD_UOM = Convert.ToDecimal(null);
            string sel = GetFindControlValue("hfMeasureUOM_out", hfBase, out success);

            if (!string.IsNullOrEmpty(sel))
            {
                string[] parms = sel.Split('|');
                if (parms.Length > 1)
                {
                    staticMeasure.STD_UOM = Convert.ToDecimal(parms[1]);
                }
            }

            staticMeasure.MEASURE_CD   = tbMeasureCode.Text;
            staticMeasure.MEASURE_NAME = tbMeasureName.Text;
            staticMeasure.MEASURE_DESC = tbMeasureDesc.Text;

            if ((staticMeasure = SQMResourcesMgr.UpdateEHSMeasure(entities, staticMeasure, SessionManager.UserContext.UserName())) != null)
            {
                EHS_MEASURE measure;
                if ((measure = measureList.FirstOrDefault(l => l.MEASURE_ID == staticMeasure.MEASURE_ID)) == null)
                {
                    measureList.Add(staticMeasure);
                }
                else
                {
                    if (staticMeasure.EntityState == System.Data.EntityState.Detached || staticMeasure.EntityState == System.Data.EntityState.Deleted)
                    {
                        measureList.Remove(measure);
                    }
                    else
                    {
                        measure = (EHS_MEASURE)SQMModelMgr.CopyObjectValues(measure, staticMeasure, false);
                    }
                }
                BindMeasureList(measureList);
            }
        }
        protected void btnNonconfSave_Click(object sender, EventArgs e)
        {
            bool success;

            if (hfOper.Value == "add")
            {
                staticNonconf            = new NONCONFORMANCE();
                staticNonconf.COMPANY_ID = SessionManager.UserContext.HRLocation.Company.COMPANY_ID;
                staticNonconf.STATUS     = "A";
            }
            else
            {
                staticNonconf = SQMResourcesMgr.LookupNonconf(entities, staticNonconf.NONCONF_ID, "");
            }

            btnNonconfSave.Enabled = false;
            hfOper.Value           = "";

            staticNonconf.PROBLEM_AREA     = ddlProblemArea.SelectedValue;
            staticNonconf.NONCONF_CATEGORY = ddlNonconfCategory.SelectedValue;
            staticNonconf.NONCONF_CD       = tbNonconfCode.Text;
            staticNonconf.NONCONF_NAME     = tbNonconfName.Text;
            staticNonconf.NONCONF_DESC     = tbNonconfDesc.Text;
            staticNonconf.STATUS           = ddlNonconfStatus.SelectedValue;

            if ((staticNonconf = SQMResourcesMgr.UpdateNonconf(entities, staticNonconf, SessionManager.UserContext.UserName())) != null)
            {
                NONCONFORMANCE nonconf = null;
                if ((nonconf = nonconfList.FirstOrDefault(l => l.NONCONF_ID == staticNonconf.NONCONF_ID)) == null)
                {
                    nonconfList.Add(staticNonconf);
                }
                else
                {
                    if (staticNonconf.EntityState == System.Data.EntityState.Detached || staticNonconf.EntityState == System.Data.EntityState.Deleted)
                    {
                        nonconfList.Remove(nonconf);
                    }
                    else
                    {
                        nonconf = (NONCONFORMANCE)SQMModelMgr.CopyObjectValues(nonconf, staticNonconf, false);
                    }
                }
                BindNonconfList(nonconfList);
            }
        }
        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);
        }
        protected void btnMeasureSave_Click(object sender, EventArgs e)
        {
            bool        success;
            EHS_MEASURE subCategory = null;

            if (hfOper.Value == "add")
            {
                staticMeasure                  = new EHS_MEASURE();
                staticMeasure.COMPANY_ID       = SessionManager.UserContext.HRLocation.Company.COMPANY_ID;
                staticMeasure.MEASURE_CATEGORY = ddlMeasureCategory.SelectedValue;
            }
            else
            {
                staticMeasure = EHSModel.LookupEHSMeasure(entities, staticMeasure.MEASURE_ID, "");
            }

            staticMeasure.MEASURE_SUBCATEGORY = ddlMeasureSubcategory.SelectedValue;
            staticMeasure.STATUS       = ddlMeasureStatus.SelectedValue;
            staticMeasure.MEASURE_CD   = tbMeasureCode.Text;
            staticMeasure.MEASURE_NAME = tbMeasureName.Text;
            staticMeasure.MEASURE_DESC = tbMeasureDesc.Text;

            // validate
            if (hfOper.Value == "add" && measureList.FirstOrDefault(l => l.MEASURE_CD == tbMeasureCode.Text) != null)
            {
                BindMeasure(staticMeasure);
                DisplayErrorMessage(hfDuplicateMeasure);
                return;
            }
            if (string.IsNullOrEmpty(staticMeasure.MEASURE_CD) || string.IsNullOrEmpty(staticMeasure.MEASURE_NAME))
            {
                BindMeasure(staticMeasure);
                DisplayErrorMessage(hfErrRequiredInputs);
                return;
            }

            btnMeasureSave.Enabled = false;

            staticMeasure.PLANT_ACCT_FIELD = "";
            if (staticMeasure.MEASURE_CATEGORY == "PROD")
            {
                staticMeasure.PLANT_ACCT_FIELD = ddlProdTableField.SelectedValue;
            }
            else if (staticMeasure.MEASURE_CATEGORY == "SAFE")
            {
                staticMeasure.PLANT_ACCT_FIELD = ddlSafeTableField.SelectedValue;
            }
            else if (staticMeasure.MEASURE_CATEGORY == "FACT")
            {
                if (ddlOutputUOM.SelectedIndex > 0)
                {
                    staticMeasure.STD_UOM = Convert.ToDecimal(ddlOutputUOM.SelectedValue);
                }
                else
                {
                    staticMeasure.STD_UOM = null;
                }
            }

            if (ddlMeasureEFMType.SelectedIndex == 0)
            {
                staticMeasure.EFM_TYPE = null;
            }
            else
            {
                staticMeasure.EFM_TYPE = ddlMeasureEFMType.SelectedValue;
            }

            hfOper.Value = "";

            if ((staticMeasure = EHSModel.UpdateEHSMeasure(entities, staticMeasure, SessionManager.UserContext.UserName())) != null)
            {
                EHS_MEASURE measure;
                if ((measure = measureList.FirstOrDefault(l => l.MEASURE_ID == staticMeasure.MEASURE_ID)) == null)
                {
                    measureList.Add(staticMeasure);
                }
                else
                {
                    if (staticMeasure.EntityState == System.Data.EntityState.Detached || staticMeasure.EntityState == System.Data.EntityState.Deleted)
                    {
                        measureList.Remove(measure);
                    }
                    else
                    {
                        measure = (EHS_MEASURE)SQMModelMgr.CopyObjectValues(measure, staticMeasure, false);
                    }
                }

                ClearMeasure(null, null);
                BindMeasureList(measureList);
            }
        }
        protected void btnTargetSave_Click(object sender, EventArgs e)
        {
            bool   success;
            Button btn = (Button)sender;

            if (btn.CommandArgument == "save")
            {
                if (staticTarget.TARGET_ID < 1)
                {
                    staticTarget            = new PERSPECTIVE_TARGET();
                    staticTarget.COMPANY_ID = SessionManager.EffLocation.Company.COMPANY_ID;
                }
                else
                {
                    staticTarget = ViewModel.LookupTarget(entities, staticTarget.TARGET_ID);
                }

                string perspective = ddlTarget.SelectedValue.Substring(ddlTarget.SelectedValue.IndexOf('|') + 1);
                staticTarget.PERSPECTIVE = perspective;
                staticTarget.CALCS_SCOPE = ddlTarget.SelectedValue.Substring(0, ddlTarget.SelectedValue.IndexOf('|'));
                staticTarget.DESCR_LONG  = staticTarget.DESCR_SHORT = ddlTarget.SelectedItem.Text;
                if (!string.IsNullOrEmpty(tbTargetDescLong.Text))
                {
                    staticTarget.DESCR_LONG = tbTargetDescLong.Text;
                }
                staticTarget.SSTAT    = ddlStatType.SelectedValue;
                staticTarget.EFF_YEAR = Convert.ToInt32(ddlEffYear.SelectedValue);
                staticTarget.STATUS   = ddlTargetStatus.SelectedValue;

                if (btnABSMetric.Checked)
                {
                    staticTarget.DATE_SPAN = 0;
                }
                else if (btnYTDMetric.Checked)
                {
                    staticTarget.DATE_SPAN = 1;
                }
                else
                {
                    staticTarget.DATE_SPAN = 2;
                }

                decimal value;
                if (decimal.TryParse(tbTargetValue.Text, out value))
                {
                    staticTarget.TARGET_VALUE = value;
                    staticTarget.VALUE_IND    = true;
                }
                else
                {
                    staticTarget.TARGET_VALUE = Convert.ToDecimal(null);
                    staticTarget.VALUE_IND    = false;
                }

                if (btnTargetMax.Checked)
                {
                    staticTarget.MIN_MAX = 1;
                }
                else
                {
                    staticTarget.MIN_MAX = 0;
                }

                if ((staticTarget = ViewModel.UpdateTarget(entities, staticTarget, SessionManager.UserContext.UserName())) != null)
                {
                    PERSPECTIVE_TARGET target = null;
                    if ((target = targetList.FirstOrDefault(l => l.TARGET_ID == staticTarget.TARGET_ID)) == null)
                    {
                        targetList.Add(staticTarget);
                    }
                    else
                    {
                        if (staticTarget.EntityState == System.Data.EntityState.Detached || staticTarget.EntityState == System.Data.EntityState.Deleted)
                        {
                            targetList.Remove(target);
                        }
                        else
                        {
                            target = (PERSPECTIVE_TARGET)SQMModelMgr.CopyObjectValues(target, staticTarget, false);
                        }
                    }
                    BindTargetList(targetList);
                }
            }
            else
            {
                staticTarget = new PERSPECTIVE_TARGET();
                BindTarget(staticTarget);
            }

            pnlTargetEdit.Enabled = false;
            btnTargetSave.Enabled = btnTargetCancel.Enabled = false;
            udpList.Update();
            udpTarget.Update();
        }