protected void ddlSelectChanged(object sender, EventArgs e)
        {
            DropDownList ddlSender = (DropDownList)sender;
            decimal      recordID  = 0;

            if (ddlSender.ID.Contains("PlantLine"))
            {
                if (staticPlantLine == null || staticPlantLine.PLANT_LINE_ID != Convert.ToDecimal(ddlSender.SelectedValue))
                {
                    staticPlantLine = SQMModelMgr.LookupPlantLine(costReport.Entities, 0, Convert.ToDecimal(ddlSender.SelectedValue), "", false);
                }
            }
            if (ddlSender.ID.Contains("LaborType"))
            {
                if (staticLaborType == null || staticLaborType.LABOR_TYP_ID != Convert.ToDecimal(ddlSender.SelectedValue))
                {
                    staticLaborType = SQMModelMgr.LookupLaborType(costReport.Entities, 0, 0, 0, Convert.ToDecimal(ddlSender.SelectedValue), "", false);
                }
            }

            switch (ddlSender.ID)
            {
            case "ddlCRPlantLineActual":

                if (staticPlantLine != null)
                {
                    tbCRDowntimeRateActual.Text = staticPlantLine.DOWNTIME_RATE.ToString();
                    udpBurdenActual.Update();
                }
                break;

            case "ddlCRPlantLineAvoid":
                if (staticPlantLine != null)
                {
                    tbCRDowntimeRateAvoid.Text = staticPlantLine.DOWNTIME_RATE.ToString();
                    udpBurdenAvoid.Update();
                }
                break;

            case "ddlCRLaborTypeActual":

                if (staticLaborType != null)
                {
                    tbCRLaborRateActual.Text = staticLaborType.LABOR_RATE.ToString();
                    udpLaborActual.Update();
                }
                break;

            case "ddlCRLaborTypeAvoid":
                if (staticLaborType != null)
                {
                    tbCRLaborRateAvoid.Text = staticLaborType.LABOR_RATE.ToString();
                    udpLaborAvoid.Update();
                }
                break;

            default:
                break;
            }
        }
        protected void SaveLine()
        {
            PLANT plant = (PLANT)SessionManager.EffLocation.Plant;
            bool  success;

            if (uclAdminEdit.IsNew)
            {
                PLANT_LINE lineNew = new PLANT_LINE();
                lineNew = uclAdminEdit.ReadPlantLine(lineNew);
                SQMModelMgr.CreatePlantLine(entities, plant, lineNew, SessionManager.UserContext.UserName());
                // plant.PLANT_LINE.Load();
            }
            else
            {
                PLANT_LINE line = (PLANT_LINE)LocalOrg().EditObject;
                line = SQMModelMgr.LookupPlantLine(entities, line.PLANT_ID, line.PLANT_LINE_ID, "", false);
                line = uclAdminEdit.ReadPlantLine(line);
                PLANT_LINE lineExisting = SQMModelMgr.UpdatePlantLine(entities, line, SessionManager.UserContext.UserName());
                //PLANT_LINE lineExisting = SQMModelMgr.FindPlantLine(entities, plant, line.PLANT_LINE_ID, "", false);
                lineExisting.PLANT_LINE_NAME = line.PLANT_LINE_NAME;
                lineExisting.DOWNTIME_RATE   = line.DOWNTIME_RATE;
                lineExisting.STATUS          = line.STATUS;
            }

            SessionManager.EffLocation.Plant = plant;
            LocalOrg().EditObject            = null;
            DoLineList();
            pnlAdminEdit.Visible = false;
        }
        protected void uclAdminList_OnLineClick(decimal lineID)
        {
            PLANT_LINE line = LocalOrg().LineList.FirstOrDefault(l => l.PLANT_LINE_ID == lineID);

            if (line != null)
            {
                uclSubLists.ToggleVisible(null);
                pnlAdminEdit.Visible = true;
                uclAdminEdit.BindPlantLine(line);
                LocalOrg().EditObject = line;
            }
        }
        public PLANT_LINE ReadPlantLine(PLANT_LINE line)
        {
            decimal decVal = 0;

            line.PLANT_LINE_NAME = tbLineName.Text;
            line.STATUS          = ddlLineStatus.SelectedValue;
            if (decimal.TryParse(tbLineDownRate.Text.Trim(), out decVal))
            {
                line.DOWNTIME_RATE = decVal;
            }
            isNew = false;
            return(line);
        }
 public void BindPlantLine(PLANT_LINE line)
 {
     isNew = true;
     ToggleVisible(pnlLineEdit);
     tbLineName.Text        = line.PLANT_LINE_NAME;
     tbLineDownRate.Text    = line.DOWNTIME_RATE.ToString();
     lblLineLastUpdate.Text = line.LAST_UPD_BY;
     if (line.LAST_UPD_DT != null)
     {
         lblLineLastUpdateDate.Text = SQMBasePage.FormatDate(WebSiteCommon.LocalTime((DateTime)line.LAST_UPD_DT, SessionManager.UserContext.TimeZoneID), "d", false);  //WebSiteCommon.LocalTime((DateTime)line.LAST_UPD_DT, SessionManager.UserContext.TimeZoneID).ToString();
         isNew = false;
     }
     if (string.IsNullOrEmpty(line.STATUS))
     {
         SetStatusList(ddlLineStatus, "A");
     }
     else
     {
         SetStatusList(ddlLineStatus, line.STATUS);
     }
 }
        public void BindIncident(decimal incidentID)
        {
            staticIncidentID = incidentID;
            try
            {
                COST_REPORT_ITEM    item   = costReport.CostReport.COST_REPORT_ITEM.Where(l => l.INCIDENT_ID == incidentID).FirstOrDefault();
                QualityIncidentData qiData = costReport.IncidentList.Where(l => l.Incident.INCIDENT_ID == item.INCIDENT_ID).FirstOrDefault();

                lblCRIncidentIDHdr.Text = WebSiteCommon.FormatID(qiData.Incident.INCIDENT_ID, 6);

                tbCRItemQtyActual.Text = item.NCM_ACT_QTY.ToString();
                tbCRItemQtyActual.Focus();
                tbCRItemQtyAvoid.Text   = item.NCM_POT_QTY.ToString();
                tbCRUnitCostActual.Text = item.UNIT_COST.ToString();
                tbCRUnitCostAvoid.Text  = item.UNIT_COST.ToString();
                tbCRItemCostActual.Text = item.NCM_ACT_COST.ToString();
                tbCRItemCostAvoid.Text  = item.NCM_POT_COST.ToString();
                tbCRItemNote.Text       = item.NCM_COMMENTS;

                List <PLANT_LINE> lineList = SQMModelMgr.SelectPlantLineList(this.entities, (decimal)qiData.Incident.DETECT_PLANT_ID);
                ddlCRPlantLineActual.DataSource     = lineList;
                ddlCRPlantLineActual.DataValueField = "PLANT_LINE_ID";
                ddlCRPlantLineActual.DataTextField  = "PLANT_LINE_NAME";
                ddlCRPlantLineActual.DataBind();
                ddlCRPlantLineActual.Items.Insert(0, new ListItem("", "0"));
                ddlCRPlantLineAvoid.DataSource     = lineList;
                ddlCRPlantLineAvoid.DataValueField = "PLANT_LINE_ID";
                ddlCRPlantLineAvoid.DataTextField  = "PLANT_LINE_NAME";
                ddlCRPlantLineAvoid.DataBind();
                ddlCRPlantLineAvoid.Items.Insert(0, new ListItem("", "0"));

                if (ddlCRPlantLineActual.Items.FindByValue(item.DWN_ACT_LINE_ID.ToString()) != null)
                {
                    ddlCRPlantLineActual.SelectedValue = item.DWN_ACT_LINE_ID.ToString();
                }
                tbCRDowntimeRateActual.Text = item.DWN_ACT_RATE.ToString();
                tbCRDowntimeRateAvoid.Text  = item.DWN_POT_RATE.ToString();
                tbCRDowntimeActual.Text     = item.DWN_ACT.ToString();
                if (ddlCRPlantLineAvoid.Items.FindByValue(item.DWN_POT_LINE_ID.ToString()) != null)
                {
                    ddlCRPlantLineAvoid.SelectedValue = item.DWN_POT_LINE_ID.ToString();
                }
                tbCRDowntimeAvoid.Text      = item.DWN_POT.ToString();
                tbCRDowntimeCostActual.Text = item.DWN_ACT_COST.ToString();
                tbCRDowntimeCostAvoid.Text  = item.DWN_POT_COST.ToString();
                tbCRDowntimeNote.Text       = item.DWN_COMMENTS;

                List <DEPARTMENT> deptList = SQMModelMgr.SelectDepartmentList(this.entities, (decimal)qiData.Incident.DETECT_COMPANY_ID, 0, (decimal)qiData.Incident.DETECT_PLANT_ID);
                ddlCRLaborDeptActual.DataSource     = deptList;
                ddlCRLaborDeptActual.DataValueField = "DEPT_ID";
                ddlCRLaborDeptActual.DataTextField  = "DEPT_NAME";
                ddlCRLaborDeptActual.DataBind();
                ddlCRLaborDeptActual.Items.Insert(0, new ListItem("", "0"));
                ddlCRLaborDeptAvoid.DataSource     = deptList;
                ddlCRLaborDeptAvoid.DataValueField = "DEPT_ID";
                ddlCRLaborDeptAvoid.DataTextField  = "DEPT_NAME";
                ddlCRLaborDeptAvoid.DataBind();
                ddlCRLaborDeptAvoid.Items.Insert(0, new ListItem("", "0"));

                List <LABOR_TYPE> laborList = SQMModelMgr.SelectLaborTypeList(this.entities, (decimal)qiData.Incident.DETECT_COMPANY_ID, 0, (decimal)qiData.Incident.DETECT_PLANT_ID);
                ddlCRLaborTypeActual.DataSource     = laborList;
                ddlCRLaborTypeActual.DataValueField = "LABOR_TYP_ID";
                ddlCRLaborTypeActual.DataTextField  = "LABOR_NAME";
                ddlCRLaborTypeActual.DataBind();
                ddlCRLaborTypeActual.Items.Insert(0, new ListItem("", "0"));
                ddlCRLaborTypeAvoid.DataSource     = laborList;
                ddlCRLaborTypeAvoid.DataValueField = "LABOR_TYP_ID";
                ddlCRLaborTypeAvoid.DataTextField  = "LABOR_NAME";
                ddlCRLaborTypeAvoid.DataBind();
                ddlCRLaborTypeAvoid.Items.Insert(0, new ListItem("", "0"));

                if (ddlCRLaborDeptActual.Items.FindByValue(item.LABOR_ACT_DEPT_ID.ToString()) != null)
                {
                    ddlCRLaborDeptActual.SelectedValue = item.LABOR_ACT_DEPT_ID.ToString();
                }
                if (ddlCRLaborTypeActual.Items.FindByValue(item.LABOR_ACT_TYPE_ID.ToString()) != null)
                {
                    ddlCRLaborTypeActual.SelectedValue = item.LABOR_ACT_TYPE_ID.ToString();
                }
                tbCRLaborRateActual.Text = item.LABOR_ACT_RATE.ToString();
                tbCRLaborRateAvoid.Text  = item.LABOR_POT_RATE.ToString();
                tbCRLaborActual.Text     = item.LABOR_ACT.ToString();
                if (ddlCRLaborDeptAvoid.Items.FindByValue(item.LABOR_POT_DEPT_ID.ToString()) != null)
                {
                    ddlCRLaborDeptAvoid.SelectedValue = item.LABOR_POT_DEPT_ID.ToString();
                }
                if (ddlCRLaborTypeAvoid.Items.FindByValue(item.LABOR_POT_TYPE_ID.ToString()) != null)
                {
                    ddlCRLaborTypeAvoid.SelectedValue = item.LABOR_POT_TYPE_ID.ToString();
                }
                tbCRLaborAvoid.Text      = item.LABOR_POT.ToString();
                tbCRLaborCostActual.Text = item.LABOR_ACT_COST.ToString();
                tbCRLaborCostAvoid.Text  = item.LABOR_POT_COST.ToString();
                tbCRLaborNote.Text       = item.LABOR_COMMENTS;

                tbCRShipDescActual.Text = item.SHIP_ACT_TYPE.ToString();
                tbCRShipDescAvoid.Text  = item.SHIP_POT_TYPE.ToString();
                tbCRShipCostActual.Text = item.SHIP_ACT_COST.ToString();
                tbCRShipCostAvoid.Text  = item.SHIP_POT_COST.ToString();
                tbCRShipNote.Text       = item.SHIP_COMMENTS;

                tbCRIncidentCostActual.Text    = FormatValue((decimal)item.TOTAL_ACT_COST, 2);
                tbCRIncidentCostAvoid.Text     = FormatValue((decimal)item.TOTAL_POT_COST, 2);
                tbCRIncidentCostActual.Enabled = tbCRIncidentCostAvoid.Enabled = false;
                btnCRCalculate.Enabled         = true;
                tbCRTotalNote.Text             = item.TOTAL_COMMENTS;

                // copy relevant incident data to the cost report when creating new
                if (costReport.IsNew || item.EntityState == System.Data.EntityState.Added || item.EntityState == System.Data.EntityState.Detached)
                {
                    QI_OCCUR_ITEM insp = qiData.QIIssue.QI_OCCUR_ITEM.FirstOrDefault();
                    tbCRItemQtyActual.Text  = FormatValue((decimal)insp.TOTAL_NC_QTY, 2);
                    tbCRUnitCostActual.Text = tbCRUnitCostAvoid.Text = "1.0";   // td
                    tbCRItemCostActual.Text = FormatValue((decimal)insp.TOTAL_NC_QTY, 2);
                    if (qiData.Incident.DETECT_PLANT_LINE_ID.HasValue && ddlCRPlantLineActual.Items.FindByValue(qiData.Incident.DETECT_PLANT_LINE_ID.ToString()) != null)
                    {
                        PLANT_LINE line = lineList.Where(l => l.PLANT_LINE_ID == qiData.Incident.DETECT_PLANT_LINE_ID).FirstOrDefault();
                        ddlCRPlantLineActual.SelectedValue = qiData.Incident.DETECT_PLANT_LINE_ID.ToString();
                        tbCRDowntimeRateActual.Text        = FormatValue((decimal)line.DOWNTIME_RATE, 2);
                    }
                }
            }
            catch
            {
            }
        }