private void BindInsightSupplier()
        {
            try
            {
                InsightSupplier insightSupplier = InsightSupplier.GetInsightSupplierByInsightSupplierId(Convert.ToInt32(ViewState["InsightSupplierId"]));
                TextBoxSupplierName.Text     = insightSupplier.SupplierName;
                TextBoxCustomSupplierId.Text = InsightSupplierMerchandising.GetCustomSupplierByInsightSupplierId(Convert.ToInt32(ViewState["InsightSupplierId"])).CustomSupplierId;

                DropDownListModelType.ClearSelection();
                DropDownListModelType.Items.FindByValue(insightSupplier.ModelTypeId.ToString()).Selected = true;
                BindModelTypeSecurity();

                CloseSupplierAuthorization();
            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                for (int i = 0; i < sqlEx.Errors.Count; i++)
                {
                    LabelError.Text += (sqlEx.Errors[i].Message + "<br />");
                }
                PanelError.Visible = true;
            }
            catch (Exception exception)
            {
                LabelError.Text   += (exception.Message + "<br />");
                PanelError.Visible = true;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.insightSupplierId = Common.GetEncryptedQueryStringValue("InsightSupplierId", 0);

            InsightSupplierCustomHeader customHeader = InsightSupplierCustomHeader.GetInsightSupplierCustomHeaderByInsightSupplierId(this.insightSupplierId);

            this.customHeaderDescription       = customHeader.Description;
            this.insightSupplierCustomHeaderId = customHeader.InsightSupplierCustomHeaderId;

            LabelPageTitle.Text = String.Format("{0} - CUSTOM", InsightSupplier.GetInsightSupplierByInsightSupplierId(this.insightSupplierId).SupplierName);

            Page.Form.DefaultFocus  = TextBoxCustomDetail.ClientID;
            Page.Form.DefaultButton = ButtonSaveNew.UniqueID;

            if (!IsPostBack)
            {
                TextBoxCustomDetail.Focus();
                ButtonSaveNew.Visible = true;

                BindCustomType();
                BindCustomFrequency();
                BindCustomResponsibility();
                BindStatus();

                if (ViewState["InsightSupplierId"] != null)
                {
                    this.insightSupplierId = Convert.ToInt32(ViewState["InsightSupplierId"].ToString());
                }

                if (this.insightSupplierId != 0)
                {
                    BindInsightSupplierCustomHeader();
                    BindGridViewCustomDetail();
                }
            }
        }
        private void BindInsightSupplier()
        {
            try
            {
                InsightSupplier insightSupplier = InsightSupplier.GetInsightSupplierByInsightSupplierId(this.insightSupplierId);
                TextBoxSupplierName.Text      = insightSupplier.SupplierName;
                TextBoxSupplierNameModel.Text = insightSupplier.SupplierNameModel;
                TextBoxPastelRef.Text         = insightSupplier.PastelRef;
                TextBoxMonths.Text            = insightSupplier.Months.ToString();
                TextBoxNotes.Text             = insightSupplier.Notes;

                DropDownListSupplierType.Items.FindByValue(insightSupplier.SupplierTypeId.ToString()).Selected = true;
                //DropDownListOption.Items.FindByValue(insightSupplier.OptionId.ToString()).Selected = true;
                DropDownListSecurity.Items.FindByValue(insightSupplier.SecurityId.ToString()).Selected = true;
                //DropDownListLink.Items.FindByValue(insightSupplier.LinkId.ToString()).Selected = true;
                DropDownListCategoryReduction.Items.FindByValue(insightSupplier.CategoryReductionId.ToString()).Selected = true;
                DropDownListBuild.Items.FindByValue(insightSupplier.BuildId.ToString()).Selected   = true;
                DropDownListStatus.Items.FindByValue(insightSupplier.StatusId.ToString()).Selected = true;
                DropDownListCatman.Items.FindByValue(insightSupplier.CatmanId.ToString()).Selected = true;
                DropDownListCustom.Items.FindByValue(insightSupplier.CustomId.ToString()).Selected = true;
                DropDownListDaily.Items.FindByValue(insightSupplier.DailyId.ToString()).Selected   = true;
                DropDownListWeekly.Items.FindByValue(insightSupplier.WeeklyId.ToString()).Selected = true;
                DropDownListPromo.Items.FindByValue(insightSupplier.PromoId.ToString()).Selected   = true;

                List <InsightSupplierModel> ismList = InsightSupplierModel.GetInsightSupplierModelByInsightSupplierId(this.insightSupplierId);

                foreach (ListItem listItem in CheckBoxListModel.Items)
                {
                    foreach (InsightSupplierModel ism in ismList)
                    {
                        if (listItem.Value == ism.ModelId.ToString())
                        {
                            listItem.Selected = true;
                        }
                    }
                }

                List <InsightSupplierOption> isoList = InsightSupplierOption.GetInsightSupplierOptionByInsightSupplierId(this.insightSupplierId);

                foreach (ListItem listItem in CheckBoxListOption.Items)
                {
                    foreach (InsightSupplierOption iso in isoList)
                    {
                        if (listItem.Value == iso.OptionId.ToString())
                        {
                            listItem.Selected = true;
                        }
                    }
                }

                List <InsightSupplierLink> islList = InsightSupplierLink.GetInsightSupplierLinkByInsightSupplierId(this.insightSupplierId);

                foreach (ListItem listItem in CheckBoxListLink.Items)
                {
                    foreach (InsightSupplierLink isl in islList)
                    {
                        if (listItem.Value == isl.LinkId.ToString())
                        {
                            listItem.Selected = true;
                        }
                    }
                }
            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                for (int i = 0; i < sqlEx.Errors.Count; i++)
                {
                    LabelError.Text += (sqlEx.Errors[i].Message + "<br />");
                }
                PanelError.Visible = true;
            }
            catch (Exception exception)
            {
                LabelError.Text   += (exception.Message + "<br />");
                PanelError.Visible = true;
            }
        }
Exemple #4
0
        protected async void ButtonValidateLinks_Click(object sender, EventArgs e)
        {
            bool       hasError   = false;
            HttpClient client     = new HttpClient();
            string     apiAddress = ConfigurationManager.AppSettings["WebApiUrl"].ToString();

            List <SupplierNotification> supplierNotificationList = new List <SupplierNotification>();
            SupplierNotification        supplierNotification     = new SupplierNotification();

            int optionId = Convert.ToInt32(DropDownListOption.SelectedValue);

            if (Convert.ToInt32(DropDownListInsightSupplier.SelectedValue) != Convert.ToInt32(allId))
            {
                //string supplierDirectoryPath = "C:\\Development\\SPARInsightManagement\\Trunk\\Source\\Document\\SupplierLinks\\3M";//insightSupplier.SupplierDirectoryPath;
                //string supplierFolder = "3M";//insightSupplier.SupplierFolder;

                InsightSupplier insightSupplier = InsightSupplier.GetInsightSupplierByInsightSupplierId(Convert.ToInt32(DropDownListInsightSupplier.SelectedValue));

                supplierNotification = new SupplierNotification();
                supplierNotification.InsightSupplierId = insightSupplier.InsightSupplierId;
                supplierNotification.OptionId          = optionId;
                supplierNotification.FolderPath        = Path.Combine(insightSupplier.SupplierDirectoryPath, insightSupplier.SupplierFolder);

                supplierNotificationList = new List <SupplierNotification>();
                supplierNotificationList.Add(supplierNotification);

                string      supplierNotificationJSON = JsonConvert.SerializeObject(supplierNotificationList, Formatting.Indented);
                HttpContent httpContent = new StringContent(supplierNotificationJSON, System.Text.Encoding.UTF8, "application/json");
                var         response    = await client.PostAsync(apiAddress, httpContent);

                if (response.IsSuccessStatusCode)
                {
                    string responseString = await response.Content.ReadAsStringAsync();

                    List <SupplierNotification> supplierNotificationReturnList = JsonConvert.DeserializeObject <List <SupplierNotification> >(responseString);

                    Guid batchId = Guid.NewGuid();

                    foreach (SupplierNotification supplierNotificationReturn in supplierNotificationReturnList)
                    {
                        SupplierNotification SupplierNotification = new SupplierNotification();
                        supplierNotification.InsightSupplierId = supplierNotificationReturn.InsightSupplierId;
                        supplierNotification.OptionId          = supplierNotificationReturn.OptionId;
                        supplierNotification.FolderPath        = supplierNotificationReturn.FolderPath;
                        supplierNotification.File             = supplierNotificationReturn.File;
                        supplierNotification.IsValid          = supplierNotificationReturn.IsValid;
                        supplierNotification.Note             = supplierNotificationReturn.Note;
                        supplierNotification.FileModifiedDate = supplierNotificationReturn.FileModifiedDate;
                        supplierNotification.FileSize         = supplierNotificationReturn.FileSize;
                        supplierNotification.BatchId          = batchId;
                        supplierNotification.ModifiedUser     = Context.User.Identity.GetUserName();

                        supplierNotification.Save();

                        if (supplierNotificationReturn.IsValid == false)
                        {
                            hasError = true;
                        }
                    }

                    if (hasError == true)
                    {
                        GridViewResult.DataSource = SupplierNotification.GetSupplierNotificationListByBatchId(batchId);
                        GridViewResult.DataBind();

                        LabelBatch.Text       = String.Format("{0} - {1}", "Batch", batchId);
                        ButtonEmailLinks.Text = String.Format("{0}", "Email below Batch");
                    }
                    else
                    {
                        LabelBatch.Text          = String.Format("{0} - {1}", "Batch", batchId);
                        ButtonEmailLinks.Text    = String.Format("{0}", "Email below Batch");
                        ButtonEmailLinks.Enabled = true;
                    }
                }
            }
            else
            {
                supplierNotificationList = new List <SupplierNotification>();
                IEnumerable <InsightSupplier> insightSupplierList = InsightSupplier.GetInsightSupplierList();

                foreach (InsightSupplier insightSupplier in insightSupplierList)
                {
                    supplierNotification = new SupplierNotification();
                    supplierNotification.InsightSupplierId = insightSupplier.InsightSupplierId;
                    supplierNotification.OptionId          = optionId;
                    supplierNotification.FolderPath        = Path.Combine(insightSupplier.SupplierDirectoryPath, insightSupplier.SupplierFolder);

                    supplierNotificationList.Add(supplierNotification);
                }

                string      supplierNotificationJSON = JsonConvert.SerializeObject(supplierNotificationList, Formatting.Indented);
                HttpContent httpContent = new StringContent(supplierNotificationJSON, System.Text.Encoding.UTF8, "application/json");
                var         response    = await client.PostAsync(apiAddress, httpContent);

                if (response.IsSuccessStatusCode)
                {
                    string responseString = await response.Content.ReadAsStringAsync();

                    List <SupplierNotification> supplierNotificationReturnList = JsonConvert.DeserializeObject <List <SupplierNotification> >(responseString);

                    Guid batchId = Guid.NewGuid();

                    foreach (SupplierNotification supplierNotificationReturn in supplierNotificationReturnList)
                    {
                        SupplierNotification SupplierNotification = new SupplierNotification();
                        supplierNotification.InsightSupplierId = supplierNotificationReturn.InsightSupplierId;
                        supplierNotification.OptionId          = supplierNotificationReturn.OptionId;
                        supplierNotification.FolderPath        = supplierNotificationReturn.FolderPath;
                        supplierNotification.File             = supplierNotificationReturn.File;
                        supplierNotification.IsValid          = supplierNotificationReturn.IsValid;
                        supplierNotification.Note             = supplierNotificationReturn.Note;
                        supplierNotification.FileModifiedDate = supplierNotificationReturn.FileModifiedDate;
                        supplierNotification.FileSize         = supplierNotificationReturn.FileSize;
                        supplierNotification.BatchId          = batchId;
                        supplierNotification.ModifiedUser     = Context.User.Identity.GetUserName();

                        supplierNotification.Save();

                        if (supplierNotificationReturn.IsValid == false)
                        {
                            hasError = true;
                        }
                    }

                    if (hasError == true)
                    {
                        GridViewResult.DataSource = SupplierNotification.GetSupplierNotificationListByBatchId(batchId);
                        GridViewResult.DataBind();
                    }
                    else
                    {
                        LabelBatch.Text          = String.Format("{0} - {1}", "Batch", batchId);
                        ButtonEmailLinks.Text    = String.Format("{0} - {1}", "Email Batch", batchId);
                        ButtonEmailLinks.Enabled = true;
                    }
                }
            }
        }