예제 #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);
            }
        }