Esempio n. 1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int    id        = int.Parse(this.hdnSelectedID.Value);
            string imagePath = string.Empty;

            if (id > 0)
            {
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        EmbroideryBO objEmbroider = new EmbroideryBO(this.ObjContext);
                        objEmbroider.ID = id;
                        objEmbroider.GetObject();

                        foreach (EmbroideryDetailsBO embDetail in objEmbroider.EmbroideryDetailssWhereThisIsEmbroidery)
                        {
                            // delete Image
                            EmbroideryDetailsBO objEmbroiderDetails = new EmbroideryDetailsBO(this.ObjContext);
                            objEmbroiderDetails.ID = embDetail.ID;
                            objEmbroiderDetails.GetObject();

                            foreach (EmbroideryImageBO image in objEmbroiderDetails.EmbroideryImagesWhereThisIsEmbroideryDetails)
                            {
                                imagePath = IndicoConfiguration.AppConfiguration.DataFolderName + "/EmbroideryImages/" + "/" + image.EmbroideryDetails.ToString() + "/" + image.Filename + image.Extension;

                                if (File.Exists(Server.MapPath(imagePath)))
                                {
                                    File.Delete(Server.MapPath(imagePath));
                                }

                                EmbroideryImageBO objEmbroideryImage = new EmbroideryImageBO(this.ObjContext);
                                objEmbroideryImage.ID = image.ID;
                                objEmbroideryImage.GetObject();

                                objEmbroideryImage.Delete();
                            }

                            objEmbroiderDetails.Delete();
                        }

                        objEmbroider.Delete();

                        this.ObjContext.SaveChanges();
                        ts.Complete();
                    }
                }
                catch (Exception ex)
                {
                    IndicoLogging.log.Error("Error occured while deleting From ViewEmbriderDetails.aspx", ex);
                }
            }
            this.PopulateDataGrid();
        }
        protected void linkEdit_Click(object sender, EventArgs e)
        {
            int id = int.Parse(((HtmlAnchor)sender).Attributes["qid"].ToString());

            this.hdnEmbDetail.Value = id.ToString();

            this.ddlFabricColor.Items.FindByValue("0").Selected = false;
            this.ddlStatus.Items.FindByValue("0").Selected      = false;
            this.ddlFabric.Items.FindByValue("0").Selected      = false;

            this.btnAddEmbroidery.InnerText = "Update Embroider Detail";

            //NNM
            if (id > 0)
            {
                try
                {
                    EmbroideryDetailsBO objEmbroiderDetails = new EmbroideryDetailsBO();
                    objEmbroiderDetails.ID = id;
                    objEmbroiderDetails.GetObject();

                    this.txtLocation.Text = objEmbroiderDetails.Location;
                    this.ddlFabric.Items.FindByValue(objEmbroiderDetails.FabricType.ToString()).Selected       = true;
                    this.ddlFabricColor.Items.FindByValue(objEmbroiderDetails.FabricColor.ToString()).Selected = true;
                    this.txtHeight.Text = Convert.ToDecimal(objEmbroiderDetails.Height.ToString()).ToString("0.00");
                    this.txtWidth.Text  = Convert.ToDecimal(objEmbroiderDetails.Width.ToString()).ToString("0.00");
                    this.ddlStatus.Items.FindByValue(objEmbroiderDetails.Status.ToString()).Selected = true;
                    this.txtNotes.Text = objEmbroiderDetails.Notes;

                    this.PopulateEmbroideryImage(id);
                }
                catch (Exception ex)
                {
                    IndicoLogging.log.Error("Error occured while edit Embroider Detail From AddEditEmbroider.aspx Page", ex);
                }
            }

            ViewState["isCompareImage"] = false;

            this.collapse2.Attributes.Add("class", "accordion-body collapse in");
        }
        private void ProcessForm(bool isEmbDetails = false)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    // Save Embroider
                    #region Save Embroidery

                    EmbroideryBO objEmbroidery = new EmbroideryBO(this.ObjContext);
                    if (this.QueryID > 0 || this.EmbroiderID > 0)
                    {
                        objEmbroidery.ID = (this.QueryID > 0) ? this.QueryID : this.EmbroiderID;
                        objEmbroidery.GetObject();
                    }
                    else
                    {
                        objEmbroidery.Creator     = this.LoggedUser.ID;
                        objEmbroidery.CreatedDate = DateTime.Now;
                    }

                    objEmbroidery.EmbStrikeOffDate = Convert.ToDateTime(this.txtEmbStrikeOffDate.Text);
                    objEmbroidery.JobName          = this.txtJobName.Text;
                    objEmbroidery.Distributor      = int.Parse(this.ddlDistributor.SelectedValue);
                    objEmbroidery.Coordinator      = int.Parse(this.hdnCoordinator.Value);
                    objEmbroidery.Client           = this.txtClient.Text;
                    objEmbroidery.Product          = this.txtProduct.Text;
                    objEmbroidery.PhotoRequiredBy  = Convert.ToDateTime(this.txtRequiredBy.Text);
                    objEmbroidery.Assigned         = int.Parse(this.ddlAssigned.SelectedValue);
                    objEmbroidery.Modifier         = this.LoggedUser.ID;
                    objEmbroidery.ModifiedDate     = DateTime.Now;

                    this.ObjContext.SaveChanges();
                    ViewState["ID"] = objEmbroidery.ID.ToString();

                    #endregion

                    //Save Embroider Details
                    #region Save Embroidery Detail

                    if (isEmbDetails == true)
                    {
                        int EmbDetailID = int.Parse(this.hdnEmbDetail.Value);

                        EmbroideryDetailsBO objEmbroideryDetails = new EmbroideryDetailsBO(this.ObjContext);

                        if (EmbDetailID > 0)
                        {
                            objEmbroideryDetails.ID = EmbDetailID;
                            objEmbroideryDetails.GetObject();
                        }

                        objEmbroideryDetails.Location    = this.txtLocation.Text;
                        objEmbroideryDetails.FabricColor = int.Parse(this.ddlFabricColor.SelectedValue);
                        objEmbroideryDetails.FabricType  = int.Parse(this.ddlFabric.SelectedValue);
                        objEmbroideryDetails.Width       = Convert.ToDecimal(this.txtWidth.Text);
                        objEmbroideryDetails.Height      = Convert.ToDecimal(this.txtHeight.Text);
                        objEmbroideryDetails.Notes       = this.txtNotes.Text;
                        objEmbroideryDetails.Embroidery  = int.Parse(ViewState["ID"].ToString());
                        objEmbroideryDetails.Status      = int.Parse(this.ddlStatus.SelectedValue);

                        this.ObjContext.SaveChanges();

                        ViewState["EmbroideryDetailID"] = objEmbroideryDetails.ID.ToString();
                    }

                    #endregion

                    // save Requested Images for Embroidery
                    #region Save Embroidery Requested Image

                    if (!string.IsNullOrEmpty(this.hdnUploadFiles.Value) && this.hdnUploadFiles.Value != "REMOVED")
                    {
                        foreach (string img in this.hdnUploadFiles.Value.Split('|').Select(o => o.Split(',')[0]))
                        {
                            if (!string.IsNullOrEmpty(img))
                            {
                                EmbroideryImageBO objEmbroideryImage = new EmbroideryImageBO(this.ObjContext);
                                objEmbroideryImage.Filename          = Path.GetFileNameWithoutExtension(img);
                                objEmbroideryImage.Extension         = Path.GetExtension(img);
                                objEmbroideryImage.Size              = (int)(new FileInfo(IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\temp\\" + img)).Length;
                                objEmbroideryImage.IsRequested       = true;
                                objEmbroideryImage.EmbroideryDetails = int.Parse(ViewState["EmbroideryDetailID"].ToString());
                            }
                        }

                        this.ObjContext.SaveChanges();
                    }



                    #endregion

                    // Save Embroidery Produced Image
                    #region Save Embroidery Produced Image


                    if (!string.IsNullOrEmpty(this.hdnUploadFiles_1.Value) && this.hdnUploadFiles_1.Value != "REMOVED")
                    {
                        foreach (string img in this.hdnUploadFiles_1.Value.Split('|').Select(o => o.Split(',')[0]))
                        {
                            if (!string.IsNullOrEmpty(img))
                            {
                                EmbroideryImageBO objEmbroideryImage = new EmbroideryImageBO(this.ObjContext);
                                objEmbroideryImage.Filename          = Path.GetFileNameWithoutExtension(img);
                                objEmbroideryImage.Extension         = Path.GetExtension(img);
                                objEmbroideryImage.Size              = (int)(new FileInfo(IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\temp\\" + img)).Length;
                                objEmbroideryImage.IsRequested       = false;
                                objEmbroideryImage.EmbroideryDetails = int.Parse(ViewState["EmbroideryDetailID"].ToString());
                            }
                        }

                        this.ObjContext.SaveChanges();
                    }

                    #endregion

                    ts.Complete();
                }

                #region Copy Template Images

                string sourceFileLocation    = string.Empty;
                string destinationFolderPath = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\EmbroideryImages\\" + ViewState["EmbroideryDetailID"].ToString();
                if (!string.IsNullOrEmpty(this.hdnUploadFiles.Value))
                {
                    // Save Embroidery Requested Image
                    foreach (string fileName in this.hdnUploadFiles.Value.Split('|').Select(o => o.Split(',')[0]))
                    {
                        sourceFileLocation = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\temp\\" + fileName;

                        if (fileName != string.Empty)
                        {
                            if (File.Exists(destinationFolderPath + "\\" + fileName))
                            {
                                File.Delete(destinationFolderPath + "\\" + fileName);
                            }
                            else
                            {
                                if (!Directory.Exists(destinationFolderPath))
                                {
                                    Directory.CreateDirectory(destinationFolderPath);
                                }
                                File.Copy(sourceFileLocation, destinationFolderPath + "\\" + fileName);
                            }
                        }
                    }
                }
                // Save Embroidery Produced Image
                if (this.hdnUploadFiles_1.Value != "0")
                {
                    foreach (string fileTemplateName in this.hdnUploadFiles_1.Value.Split('|').Select(o => o.Split(',')[0]))
                    {
                        sourceFileLocation = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\temp\\" + fileTemplateName;

                        if (fileTemplateName != string.Empty)
                        {
                            if (File.Exists(destinationFolderPath + "\\" + fileTemplateName))
                            {
                                File.Delete(destinationFolderPath + "\\" + fileTemplateName);
                            }
                            else
                            {
                                if (!Directory.Exists(destinationFolderPath))
                                {
                                    Directory.CreateDirectory(destinationFolderPath);
                                }
                                File.Copy(sourceFileLocation, destinationFolderPath + "\\" + fileTemplateName);
                            }
                        }
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                IndicoLogging.log.Error("Error occured while saving  or updating Embroidery details in AddEditEbroidery.aspx", ex);
            }
        }
        protected void dgEmbroiderDetails_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            DataGridItem item = e.Item;

            if (item.ItemIndex > -1 && item.DataItem is EmbroideryDetailsBO)
            {
                EmbroideryDetailsBO objEmbroiderDetails = (EmbroideryDetailsBO)item.DataItem;

                Literal litLocation = (Literal)item.FindControl("litLocation");
                litLocation.Text = objEmbroiderDetails.Location;

                Literal litFabricType = (Literal)item.FindControl("litFabricType");
                litFabricType.Text = objEmbroiderDetails.objFabricType.Name;

                HtmlGenericControl dvFabricColor = (HtmlGenericControl)item.FindControl("dvFabricColor");
                dvFabricColor.Attributes.Add("style", (objEmbroiderDetails.FabricColor > 0) ? "background-color: " + objEmbroiderDetails.objFabricColor.ColorValue.ToString() : "background-color:#FFFFFF");

                Literal litWidth = (Literal)item.FindControl("litWidth");
                litWidth.Text = Convert.ToDecimal(objEmbroiderDetails.Width.ToString()).ToString("0.00");

                Literal litHeight = (Literal)item.FindControl("litHeight");
                litHeight.Text = Convert.ToDecimal(objEmbroiderDetails.Height.ToString()).ToString("0.00");

                Literal litStatus = (Literal)item.FindControl("litStatus");
                litStatus.Text = objEmbroiderDetails.objStatus.Name;

                Literal litNotes = (Literal)item.FindControl("litNotes");
                litNotes.Text = objEmbroiderDetails.Notes;

                HtmlAnchor         ancProducedIamge = (HtmlAnchor)item.FindControl("ancProducedIamge");
                HtmlGenericControl iProimageView    = (HtmlGenericControl)item.FindControl("iProimageView");

                // Procedure Image
                EmbroideryImageBO objEmbroideryImage = new EmbroideryImageBO();
                objEmbroideryImage.EmbroideryDetails = objEmbroiderDetails.ID;


                List <EmbroideryImageBO> lstProImage = objEmbroideryImage.SearchObjects().Where(o => o.IsRequested == false).ToList();


                if (lstProImage.Count > 0)
                {
                    ancProducedIamge.HRef = IndicoConfiguration.AppConfiguration.DataFolderName + "/EmbroideryImages/" + "/" + objEmbroiderDetails.ID.ToString() + "/" + lstProImage[0].Filename + lstProImage[0].Extension;

                    if (!File.Exists(Server.MapPath(ancProducedIamge.HRef)))
                    {
                        ancProducedIamge.HRef = IndicoConfiguration.AppConfiguration.DataFolderName + "/noimage-png-350px-350px.png";
                    }

                    ancProducedIamge.Attributes.Add("class", "btn-link preview");
                    iProimageView.Attributes.Add("class", "icon-eye-open");
                    List <float> lstProcImageDimensions = (new ImageProcess()).GetResizedImageDimension(960, 720, 420, 360);
                    if (lstProcImageDimensions.Count > 0)
                    {
                        ancProducedIamge.Attributes.Add("height", lstProcImageDimensions[0].ToString());
                        ancProducedIamge.Attributes.Add("width", lstProcImageDimensions[1].ToString());
                    }
                }
                else
                {
                    ancProducedIamge.Title = "Produced Image Not Found";
                    iProimageView.Attributes.Add("class", "icon-eye-close");
                }

                // <! --------- / ----------------->


                // Requested Image

                HtmlAnchor         ancRequestedIamge = (HtmlAnchor)item.FindControl("ancRequestedIamge");
                HtmlGenericControl iReqimageView     = (HtmlGenericControl)item.FindControl("iReqimageView");

                List <EmbroideryImageBO> lstReqImage = objEmbroideryImage.SearchObjects().Where(o => o.IsRequested == true).ToList();

                if (lstReqImage.Count > 0)
                {
                    ancRequestedIamge.HRef = IndicoConfiguration.AppConfiguration.DataFolderName + "/EmbroideryImages/" + "/" + objEmbroiderDetails.ID.ToString() + "/" + lstReqImage[0].Filename + lstReqImage[0].Extension;

                    if (!File.Exists(Server.MapPath(ancRequestedIamge.HRef)))
                    {
                        ancRequestedIamge.HRef = IndicoConfiguration.AppConfiguration.DataFolderName + "/noimage-png-350px-350px.png";
                    }

                    ancRequestedIamge.Attributes.Add("class", "btn-link preview");
                    iReqimageView.Attributes.Add("class", "icon-eye-open");
                    List <float> lstProcImageDimensions = (new ImageProcess()).GetResizedImageDimension(960, 720, 420, 360);
                    if (lstProcImageDimensions.Count > 0)
                    {
                        ancRequestedIamge.Attributes.Add("height", lstProcImageDimensions[0].ToString());
                        ancRequestedIamge.Attributes.Add("width", lstProcImageDimensions[1].ToString());
                    }
                }
                else
                {
                    ancRequestedIamge.Title = "Requested Image Not Found";
                    iReqimageView.Attributes.Add("class", "icon-eye-close");
                }


                // <! --------- / ----------------->

                HtmlAnchor linkCompare = (HtmlAnchor)item.FindControl("linkCompare");
                linkCompare.Attributes.Add("qid", objEmbroiderDetails.ID.ToString());

                HtmlAnchor linkEdit = (HtmlAnchor)item.FindControl("linkEdit");
                linkEdit.Attributes.Add("qid", objEmbroiderDetails.ID.ToString());

                HyperLink linkDelete = (HyperLink)item.FindControl("linkDelete");
                linkDelete.Attributes.Add("qid", objEmbroiderDetails.ID.ToString());
            }
        }