Ejemplo n.º 1
0
        public PERSPECTIVE_TARGET GetTarget(string perspective, string calcScope, string calcStat, decimal companyID, decimal busOrgID, decimal plantID, int effYear)
        {
            PERSPECTIVE_TARGET target = null;

            bool byYear    = effYear == 0 ? false : true;
            bool byStat    = this.TargetList.Where(l => l.Target.SSTAT != null && l.Target.SSTAT != "").Count() > 0 ? true : false;
            bool byPlant   = this.TargetList.Where(l => l.PlantID != null && l.PlantID > 0).Count() > 0 && plantID > 0 ? true : false;
            bool byBusOrg  = this.TargetList.Where(l => l.BusOrgID != null && l.BusOrgID > 0).Count() > 0 && busOrgID > 0 && !byPlant ? true : false;
            bool byCompany = !byBusOrg && !byPlant ? true : false;                      // finally default to getting the company targets

            this.TargetList.Where(l => l.PlantID != null && l.PlantID > 0).Count();

            if (byYear)
            {
                // get most current effyear target
                target = this.TargetList.Where(l => l.Target.PERSPECTIVE == perspective && l.Target.CALCS_SCOPE == calcScope &&
                                               (!byStat || l.Target.SSTAT == calcStat) &&
                                               (!byCompany || l.CompanyID == companyID) &&
                                               (!byBusOrg || l.BusOrgID == busOrgID) &&
                                               (!byPlant || l.PlantID == plantID) &&
                                               l.Target.EFF_YEAR <= effYear
                                               ).Select(l => l.Target).LastOrDefault();
            }
            else
            {
                target = this.TargetList.Where(l => l.Target.PERSPECTIVE == perspective && l.Target.CALCS_SCOPE == calcScope &&
                                               (!byStat || l.Target.SSTAT == calcStat) &&
                                               (!byCompany || l.CompanyID == companyID) &&
                                               (!byBusOrg || l.BusOrgID == busOrgID) &&
                                               (!byPlant || l.PlantID == plantID)
                                               ).Select(l => l.Target).FirstOrDefault();
            }

            return(target);
        }
 protected void btnTargetAdd_Click(object sender, EventArgs e)
 {
     staticTarget           = new PERSPECTIVE_TARGET();
     staticTarget.TARGET_ID = 0;
     staticTarget.STATUS    = "A";
     staticTarget.EFF_YEAR  = DateTime.UtcNow.Year;
     BindTarget(staticTarget);
 }
        protected void lnkTargetList_Click(object sender, EventArgs e)
        {
            LinkButton lnk = (LinkButton)sender;
            decimal    id  = Convert.ToDecimal(lnk.CommandArgument.ToString().Trim());

            BindTarget((staticTarget = targetList.FirstOrDefault(l => l.TARGET_ID == id)));
            lblAddTarget.Visible = true;
        }
Ejemplo n.º 4
0
        public static PERSPECTIVE_TARGET LookupTarget(PSsqmEntities ctx, decimal targetID)
        {
            PERSPECTIVE_TARGET target = null;

            try
            {
                target = (from t in ctx.PERSPECTIVE_TARGET
                          where (t.TARGET_ID == targetID)
                          select t).Single();
            }
            catch
            {; }

            return(target);
        }
Ejemplo n.º 5
0
        public int TargetMetric(string targetScope, decimal[] plantIDS, DateTime targetDate)
        {
            int status = 0;

            this.Results.ValidResult = false;

            try
            {
                PERSPECTIVE_TARGET      target = this.TargetList.Where(t => t.CALCS_SCOPE == targetScope).FirstOrDefault();
                PERSPECTIVE_TARGET_CALC tc     = null;

                if (targetDate > DateTime.MinValue)
                {                             // get specific date period
                    if (plantIDS.Length == 1) // get specific plant
                    {
                        tc = target.PERSPECTIVE_TARGET_CALC.Where(l => l.PLANT_ID != null && plantIDS.Contains((decimal)l.PLANT_ID) && (l.PERIOD_YEAR == targetDate.Year && l.PERIOD_MONTH == targetDate.Month)).FirstOrDefault();
                    }
                    else
                    {
                        tc = target.PERSPECTIVE_TARGET_CALC.Where(l => l.PLANT_ID == null && (l.PERIOD_YEAR == targetDate.Year && l.PERIOD_MONTH == targetDate.Month)).FirstOrDefault();
                    }
                }
                else
                {   // get the most recent results
                    if (plantIDS.Length == 1)
                    {
                        tc = target.PERSPECTIVE_TARGET_CALC.Where(l => l.PLANT_ID != null && plantIDS.Contains((decimal)l.PLANT_ID) && l.VALUE_IND == true).FirstOrDefault();
                    }
                    else
                    {
                        tc = target.PERSPECTIVE_TARGET_CALC.Where(l => l.PLANT_ID == null && l.VALUE_IND == true).FirstOrDefault();
                    }
                }
                if (tc != null)
                {
                    this.Results.Text        = this.TargetList.Where(t => t.CALCS_SCOPE == targetScope).Select(t => t.DESCR_LONG).FirstOrDefault();
                    this.Results.ValidResult = (bool)tc.VALUE_IND;
                    this.Results.Result      = (decimal)tc.VALUE;
                    this.Results.ResultDate  = new DateTime(tc.PERIOD_YEAR, tc.PERIOD_MONTH, DateTime.DaysInMonth(tc.PERIOD_YEAR, tc.PERIOD_MONTH));
                }
            }
            catch
            {
                status = -1;
            }

            return(status);
        }
Ejemplo n.º 6
0
        public static PERSPECTIVE_TARGET UpdateTarget(PSsqmEntities ctx, PERSPECTIVE_TARGET target, string updateBy)
        {
            PERSPECTIVE_TARGET ret = null;

            target = (PERSPECTIVE_TARGET)SQMModelMgr.SetObjectTimestamp(target, updateBy, target.EntityState);
            if (target.EntityState == EntityState.Detached)
            {
                ctx.AddToPERSPECTIVE_TARGET(target);
            }
            if (ctx.SaveChanges() > 0)
            {
                ret = target;
            }

            return(ret);
        }
        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();
        }
        protected void BindTarget(PERSPECTIVE_TARGET target)
        {
            int n = -1;

            if (target != null)
            {
                if (!string.IsNullOrEmpty(target.CALCS_SCOPE))
                {
                    foreach (RadComboBoxItem item in ddlTarget.Items)
                    {
                        ++n;
                        string[] args = item.Value.Split('|');
                        if (!item.IsSeparator && args[0] == target.CALCS_SCOPE)
                        {
                            ddlTarget.SelectedIndex = n;
                            break;
                        }
                    }
                }

                tbTargetDescLong.Text = target.DESCR_LONG;
                if (ddlStatType.Items.FindByValue(target.SSTAT) != null)
                {
                    ddlStatType.SelectedValue = target.SSTAT;
                }
                if (target.EFF_YEAR > 0)
                {
                    ddlEffYear.SelectedValue = target.EFF_YEAR.ToString();
                }

                btnYTDMetric.Checked = btnYOYMetric.Checked = btnABSMetric.Checked = false;
                if (target.DATE_SPAN <= 0)
                {
                    btnABSMetric.Checked = true;
                }
                else if (target.DATE_SPAN == 1)
                {
                    btnYTDMetric.Checked = true;
                }
                else
                {
                    btnYOYMetric.Checked = true;
                }

                if (target.TARGET_VALUE.HasValue)
                {
                    tbTargetValue.Text = SQMBasePage.FormatValue((decimal)target.TARGET_VALUE, 4);
                }
                else
                {
                    tbTargetValue.Text = "";
                }

                btnTargetMin.Checked = btnTargetMax.Checked = false;
                if (target.MIN_MAX > 0)
                {
                    btnTargetMax.Checked = true;
                }
                else
                {
                    btnTargetMin.Checked = true;
                }

                ddlTargetStatus.SelectedValue = target.STATUS;
                pnlTargetEdit.Enabled         = true;
                btnTargetSave.Enabled         = btnTargetCancel.Enabled = true;

                udpTarget.Update();
            }
        }