/// <summary>
 /// Save PLC
 /// </summary>
 private void SavePLC()
 {
     using (PLC itemPLC = PLC.GetByKey(itemId, curCountryCode))
     {
         if (itemPLC != null)
         {
             #region Bundles rule
             // public intro date for bundles cannot be before the latest public intro dates of all the components.
             // Obsolescence dates cannot be set later than the earliest obsolescence date of the components
             if (curItemType == (int)ItemTypesEnum.BUNDLE)
             {
                 if (!itemPLC.CheckPLCforBundle(curCountryCode, (DateTime?)wdcPID.Value, (DateTime?)wdcObsoleteDate.Value))
                 {
                     lError.Text    = PLC.LastError;
                     lError.Visible = true;
                     return;
                 }
             }
             #endregion
             // all PLC are unlock before changes, prevent API rules
             #region PID
             itemPLC.FullLocked   = false;
             itemPLC.FullDate     = (DateTime?)wdcPID.Value;
             itemPLC.FullDateType = cboxPID.Checked ? 'C' : 'R';
             itemPLC.FullLocked   = cbPIDL.Checked;
             #endregion
             #region Announcement date
             itemPLC.AnnouncementLocked   = false;
             itemPLC.AnnouncementDate     = (DateTime?)wdcAnnouncementDate.Value;
             itemPLC.AnnouncementDateType = cboxAnnouncementDate.Checked ? 'C' : 'R';
             itemPLC.AnnouncementLocked   = cbAnnL.Checked;
             #endregion
             #region Blind date
             itemPLC.BlindLocked   = false;
             itemPLC.BlindDate     = (DateTime?)wdcBlindDate.Value;
             itemPLC.BlindDateType = cboxBlindDate.Checked ? 'C' : 'R';
             itemPLC.BlindLocked   = cbBlindL.Checked;
             #endregion
             #region Obsolete date
             itemPLC.ObsoleteLocked   = false;
             itemPLC.ObsoleteDate     = (DateTime?)wdcObsoleteDate.Value;
             itemPLC.ObsoleteDateType = cboxObsoleteDate.Checked ? 'C' : 'R';
             itemPLC.ObsoleteLocked   = cbObsoL.Checked;
             #endregion
             #region Removal date
             itemPLC.RemovalLocked   = false;
             itemPLC.RemovalDate     = (DateTime?)wdcRemovalDate.Value;
             itemPLC.RemovalDateType = cboxRemovalDate.Checked ? 'C' : 'R';
             itemPLC.RemovalLocked   = cbRemovL.Checked;
             #endregion
             if (itemPLC.Save(SessionState.User.Id))
             {
                 //Sateesh -- Language Scope Management - ACQ 3.6 - 27/05/2009
                 Item.UpdateWorkingTables(itemPLC.ItemId, SessionState.Culture.Code, true);
                 if (Request["dg"] == null)
                 {
                     Page.ClientScript.RegisterStartupScript(this.GetType(), "reloadParent", "<script>ReloadParent();</script>");
                 }
                 else // We have been opened by another page that contains an Infragistics Grid
                 // Call parent refresh function to reflect the changes.
                 {
                     if (Request["row"] != null && Request["col"] != null)
                     {
                         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "reloadParent", "<script>top.window.close()</script>");
                     }
                 }
             }
             else
             {
                 lError.Text    = PLC.LastError;
                 lError.Visible = true;
             }
         }
     }
 }
        /// <summary>
        /// Retrieve PLC for the item and culture requested
        /// </summary>
        private void RetrievePLC()
        {
            #region Update PLC Label
            lbPID.Text          = UITools.PIDLabel;
            lbPOD.Text          = UITools.PODLabel;
            lbBlind.Text        = UITools.BlindLabel;
            lbAnnouncement.Text = UITools.AnnouncementLabel;
            lbRemoval.Text      = UITools.RemovalLabel;
            #endregion
            using (PLC itemPLC = PLC.GetByKey(itemId, curCountryCode))
            {
                if (itemPLC != null)
                {
                    using (Country plcCountry = itemPLC.Country)
                    {
                        #region Announcement date
                        wdcAnnouncementDate.Value    = itemPLC.AnnouncementDate ?? null;
                        iRegionAnnouncement.ImageUrl = itemPLC.AnnouncementDateType == 'R' ? "/hc_v4/img/flags/" + plcCountry.MainRegionCode + ".gif" : "/hc_v4/img/flags/" + curCountryCode + ".gif";
                        iRegionAnnouncement.Visible  = itemPLC.AnnouncementDate != null;
                        iRegionAnnouncement.ToolTip  = itemPLC.AnnouncementDateType == 'R' ? "Regional date" : "Country date";
                        cboxAnnouncementDate.Visible = (itemPLC.AnnouncementDateType == 'R');
                        cboxAnnouncementDate.Checked = (itemPLC.AnnouncementDateType == 'C');
                        cbAnnL.Checked = itemPLC.AnnouncementLocked;
                        #endregion
                        #region Blind date
                        wdcBlindDate.Value    = itemPLC.BlindDate ?? null;
                        iRegionBlind.ImageUrl = itemPLC.BlindDateType == 'R' ? "/hc_v4/img/flags/" + plcCountry.MainRegionCode + ".gif" : "/hc_v4/img/flags/" + curCountryCode + ".gif";
                        iRegionBlind.Visible  = itemPLC.BlindDate != null;
                        iRegionBlind.ToolTip  = itemPLC.BlindDateType == 'R' ? "Regional date" : "Country date";
                        cboxBlindDate.Visible = (itemPLC.BlindDateType == 'R');
                        cboxBlindDate.Checked = (itemPLC.BlindDateType == 'C');
                        cbBlindL.Checked      = itemPLC.BlindLocked;
                        #endregion
                        #region PID
                        wdcPID.Value        = itemPLC.FullDate ?? null;
                        iRegionPID.ImageUrl = itemPLC.FullDateType == 'R' ? "/hc_v4/img/flags/" + plcCountry.MainRegionCode + ".gif" : "/hc_v4/img/flags/" + curCountryCode + ".gif";
                        iRegionPID.Visible  = itemPLC.FullDate != null;
                        iRegionPID.ToolTip  = itemPLC.FullDateType == 'R' ? "Regional date" : "Country date";
                        cboxPID.Visible     = (itemPLC.FullDateType == 'R');
                        cboxPID.Checked     = (itemPLC.FullDateType == 'C');
                        cbPIDL.Checked      = itemPLC.FullLocked;
                        #endregion
                        #region Obsolete date
                        wdcObsoleteDate.Value    = itemPLC.ObsoleteDate ?? null;
                        iRegionObso.ImageUrl     = itemPLC.ObsoleteDateType == 'R' ? "/hc_v4/img/flags/" + plcCountry.MainRegionCode + ".gif" : "/hc_v4/img/flags/" + curCountryCode + ".gif";
                        iRegionObso.Visible      = itemPLC.ObsoleteDate != null;
                        iRegionObso.ToolTip      = itemPLC.ObsoleteDateType == 'R' ? "Regional date" : "Country date";
                        cboxObsoleteDate.Visible = (itemPLC.ObsoleteDateType == 'R');
                        cboxObsoleteDate.Checked = (itemPLC.ObsoleteDateType == 'C');
                        cbObsoL.Checked          = itemPLC.ObsoleteLocked;
                        //Prabhu - Fix for HPeZilla Bug 70814  - CRYS: Issue with the "PLC" Edit Window Date Fields
                        //Commented out the if condition as it not needed
                        //if ((Convert.ToDateTime(wdcObsoleteDate.Value).AddDays(30) < DateTime.Now) && (itemPLC.ObsoleteDate != null))
                        //{
                        //  wdcObsoleteDate.Enabled = false;
                        //  cboxObsoleteDate.Enabled = false;
                        //  cbObsoL.Enabled = false;
                        //}
                        #endregion
                        #region Removal date
                        wdcRemovalDate.Value    = itemPLC.RemovalDate ?? null;
                        iRegionRemoval.ImageUrl = itemPLC.RemovalDateType == 'R' ? "/hc_v4/img/flags/" + plcCountry.MainRegionCode + ".gif" : "/hc_v4/img/flags/" + curCountryCode + ".gif";
                        iRegionRemoval.Visible  = itemPLC.RemovalDate != null;
                        iRegionRemoval.ToolTip  = itemPLC.RemovalDateType == 'R' ? "Regional date" : "Country date";
                        cboxRemovalDate.Visible = (itemPLC.RemovalDateType == 'R');
                        cboxRemovalDate.Checked = (itemPLC.RemovalDateType == 'C');
                        cbRemovL.Checked        = itemPLC.RemovalLocked;
                        #endregion
                        #region "Ugly PMT code"
                        // Easy Content awesome requirement
                        // Display a warning when PMT date is more recent and different from current obso and full date
                        if (itemPLC.ObsoleteLocked || itemPLC.FullLocked)
                        {
                            bool bShowFullPMT = false, bShowObsoletePMT = false;
                            using (Database dbObj = new Database(SessionState.CacheComponents["Inbound_DB"].ConnectionString))
                            {
                                if (dbObj != null)
                                {
                                    using (DataSet dsPMT = dbObj.RunSQLReturnDataSet("Select FileTimeStamp FROM Interfaces WHERE InterfaceId = 3"))
                                    {
                                        if (dsPMT != null && dsPMT.Tables.Count == 1 && dsPMT.Tables[0].Rows.Count == 1 && dsPMT.Tables[0].Rows[0][0] != DBNull.Value)
                                        {
                                            DateTime?pmtFileDate = Utils.PMTConvertToDate(dsPMT.Tables[0].Rows[0][0].ToString());
                                            if (pmtFileDate != null)
                                            {
                                                using (DataSet ds = dbObj.RunSPReturnDataSet("QDE_GetPMTInfo", new SqlParameter("@CountryCode", curCountryCode)
                                                                                             , new SqlParameter("@LanguageCode", curLanguageCode)
                                                                                             , new SqlParameter("@Sku", curSku)))
                                                {
                                                    if (ds != null && ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 1)
                                                    {
                                                        DateTime?pmtFull = HyperCatalog.DataAccessLayer.SqlDataAccessLayer.GetProperDate(ds.Tables[0].Rows[0]["FullDate"]);
                                                        DateTime?pmtObso = HyperCatalog.DataAccessLayer.SqlDataAccessLayer.GetProperDate(ds.Tables[0].Rows[0]["ObsoleteDate"]);
                                                        bShowFullPMT     = pmtFull.HasValue && itemPLC.FullLocked && pmtFileDate > itemPLC.FullModifyDate && itemPLC.FullDate != pmtFull;
                                                        bShowObsoletePMT = pmtObso.HasValue && itemPLC.ObsoleteLocked && pmtFileDate > itemPLC.ObsoleteModifyDate && itemPLC.ObsoleteDate != pmtObso;
                                                        if (bShowFullPMT)
                                                        {
                                                            lbPID.Text = lbPID.Text + "<a href='javascript://' title='" + SessionState.User.FormatUtcDate(pmtFull.Value, false, SessionState.User.FormatDate).Substring(0, 10) + "'><font color=red><b>(PMT)</b></font></a>";
                                                        }
                                                        if (bShowObsoletePMT)
                                                        {
                                                            lbPOD.Text = lbPOD.Text + "<a href='javascript://' title='" + SessionState.User.FormatUtcDate(pmtObso.Value, false, SessionState.User.FormatDate).Substring(0, 10) + "'><font color=red><b>(PMT)</b></font></a>";
                                                        }
                                                    }
                                                    else
                                                    {
                                                        Trace.Warn("Error running [Select * FROM PMT WHERE CountryCode = '" + curCountryCode + "' AND LanguageCode = '" + curLanguageCode + "' AND ProductNumber = '" + curSku + "'] query :" + dbObj.LastError);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                Trace.Warn("Error : pmtFileDate return invalid datetime");
                                            }
                                        }
                                        else
                                        {
                                            Trace.Warn("Error : Interface Id (#3) not found");
                                        }
                                    }
                                }
                                else
                                {
                                    Trace.Warn("Error : Cannot connect to Inbound DB [" + SessionState.CacheComponents["Inbound_DB"].ConnectionString + "]");
                                }
                            }
                        }
                        #endregion
                        // stored in JS the current value of announcement and the type of announcement date, use for the rule
                        // stored in JS the current value of blind and the type of blind date, use for the rule

                        //Commented for #2807 -- ITG GS: Error in "Products Nearly Obsolete" Page
                        //string script = "var annR='" + itemPLC.AnnouncementDateType.Value + "';var blindR='" + itemPLC.BlindDateType.Value + "';";
                        // Fix for 2807 and 71549 are the same (Chardonnay and PRISM fixes)
                        string script = "var annR='" + itemPLC.AnnouncementDateType + "';var blindR='" + itemPLC.BlindDateType + "';";

                        if (itemPLC.AnnouncementDate.HasValue)
                        {
                            int m = itemPLC.AnnouncementDate.Value.Month - 1;
                            script = script + "var pann= new Date(" + itemPLC.AnnouncementDate.Value.Year.ToString() + ", " + m.ToString() + ", " + itemPLC.AnnouncementDate.Value.Day.ToString() + ");";
                        }
                        else
                        {
                            script = script + "var pann= null;";
                        }
                        if (itemPLC.BlindDate.HasValue)
                        {
                            int m = itemPLC.BlindDate.Value.Month - 1;
                            script = script + "var pblind= new Date(" + itemPLC.BlindDate.Value.Year.ToString() + ", " + m.ToString() + ", " + itemPLC.BlindDate.Value.Day.ToString() + ");";
                        }
                        else
                        {
                            script = script + "var pblind= null;";
                        }
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "<script>" + script + "</script>");
                    }
                }
            }
        }