Exemplo n.º 1
0
        private void ShowWorkZOneDetail()
        {
            WorkZoneDetail wzd = new WorkZoneDetail();

            wzd                = WorkZoneDetail.GetWorkZoneDetail(int.Parse(HiddenWorkZoneId.Value), int.Parse(HiddenWorkZoneDetailId.Value));
            txtNo.Text         = wzd.No;
            txtNCfileName.Text = wzd.NCFileName;
            txtPathType.Text   = wzd.PathType;
            txtCommetWZD.Text  = wzd.Comment;
            txtImgWZD.Text     = wzd.ImageFile;

            WorkZone wz             = WorkZone.GetWorkZone(int.Parse(HiddenWorkZoneId.Value));
            string   pathFileDetail = Server.MapPath("~/" + Common.GetFolderWorkZoneDetail(wz.CompanyId, wz.CompanyName, wz.FactoryId, wz.FactoryName, wz.WorkZoneId, wz.Name)) + "/" + wzd.ImageFile;

            if (File.Exists(pathFileDetail))
            {
                imgWZD.ImageUrl = "~/" + Common.GetFolderWorkZoneDetail(wz.CompanyId, wz.CompanyName, wz.FactoryId, wz.FactoryName, wz.WorkZoneId, wz.Name) + "/" + txtImgWZD.Text + "?" + (new Random()).Next(int.MinValue, int.MaxValue) + "";
            }
            else
            {
                imgWZD.ImageUrl = "~/Images/no-image.png";
            }

            panelMain.Visible       = false;
            panelEidtDetail.Visible = true;
        }
Exemplo n.º 2
0
        protected void btnSaveWZD_Click(object sender, EventArgs e)
        {
            try
            {
                WorkZoneDetail wzd = new WorkZoneDetail();
                wzd           = WorkZoneDetail.GetWorkZoneDetail(int.Parse(HiddenWorkZoneId.Value), int.Parse(HiddenWorkZoneDetailId.Value));
                wzd.Comment   = txtCommetWZD.Text;
                wzd.ImageFile = string.Format(Constant.WORKNC_WZ_DETAIL_IMAGE_NAME, wzd.WorkZoneDetailId);
                wzd.Update();
                if (ViewState["imgWZD"] == null)
                {
                    return;
                }

                WorkZone wz = WorkZone.GetWorkZone(int.Parse(HiddenWorkZoneId.Value));

                string path = "~/" + Common.GetFolderWorkZoneDetail(wz.CompanyId, wz.CompanyName, wz.FactoryId, wz.FactoryName, wz.WorkZoneId, wz.Name);

                SaveImage("imgWZD", path, wzd.ImageFile);
                ViewState.Remove("imgWZD");
                panelMain.Visible       = true;
                panelEidtDetail.Visible = false;
            }
            catch (Exception ex)
            {
                RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), ex.Message) + "\");");
                logger.Error("Error in Save WorkZoneDetail:", ex);
            }
        }
Exemplo n.º 3
0
        public void UploadFile(DetailProblem problem)
        {
            logger.DebugFormat("Begin UploadFile , WorkZoneId = {0},  workZOneDetailId id = {1}", problem.WorkZoneId, problem.WorkZoneDetailId);
            WorkZone wk = WorkZone.GetWorkZone(problem.WorkZoneId);
            string   pathFolderProblem = Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, Common.GetFolderWorkZoneProblem(wk.CompanyId, wk.CompanyName, wk.FactoryId, wk.FactoryName, wk.WorkZoneId, wk.Name));

            logger.Debug("PhysicalPath pathFolder =" + pathFolderProblem);

            string uploadFilePath = "";

            try
            {
                using (DBContext db = new DBContext())
                {
                    using (System.Data.Common.DbTransaction tran = db.UseTransaction())
                    {
                        try
                        {
                            if (problem.FileId == 0) // case insert New
                            {
                                logger.Debug(" Case Insert new problem");

                                WorkZoneDetail d = WorkZoneDetail.GetWorkZoneDetail(problem.WorkZoneId, problem.WorkZoneDetailId);
                                d.Status          = 1; // Has Problem
                                d.ModifiedAccount = problem.CreateAccount;
                                d.Update();


                                problem.FileId = DetailProblem.GetNextFileID(d.WorkZoneId, d.WorkZoneDetailId);
                                if (problem.Base64Data != null)
                                {
                                    problem.ImageFile = string.Format("{0}_{1}.png", d.WorkZoneDetailId, problem.FileId);
                                }
                                problem.ModifiedAccount = problem.CreateAccount;
                                problem.Insert();

                                logger.Debug(" Update problem and WorkZone Detail");

                                if (!Directory.Exists(pathFolderProblem))
                                {
                                    Directory.CreateDirectory(pathFolderProblem);
                                }

                                if (!string.IsNullOrEmpty(problem.Base64Data))
                                {
                                    uploadFilePath = Path.Combine(pathFolderProblem, problem.ImageFile);
                                    logger.Debug("Case Create file problem = " + uploadFilePath);
                                    Byte[] data = Convert.FromBase64String(problem.Base64Data);
                                    File.WriteAllBytes(uploadFilePath, data);
                                    problem.Base64Data = null;
                                }
                            }
                            else if (problem.FileId != 0) // Update or Delete
                            {
                                DetailProblem p = DetailProblem.GetDetailProblem(problem.WorkZoneId, problem.WorkZoneDetailId, problem.FileId);
                                if (string.IsNullOrEmpty(problem.ImageFile))
                                {
                                    //delete
                                    logger.Debug("Case Delete detail Problem");
                                    p.Delete();

                                    uploadFilePath = Path.Combine(pathFolderProblem, p.ImageFile);
                                    logger.Debug("Case Delete file uploadFilePath = " + uploadFilePath);
                                    if (File.Exists(uploadFilePath))
                                    {
                                        File.Delete(uploadFilePath);
                                    }
                                }
                                else
                                {
                                    logger.Debug("Case update detail Problem");
                                    p.Comment         = problem.Comment;
                                    p.ModifiedAccount = problem.CreateAccount;
                                    p.Update();
                                }
                            }
                            tran.Commit();
                        }
                        catch (Exception ex)
                        {
                            tran.Rollback();
                            logger.Error("Error UploadFile", ex);
                            throw ex;
                        }
                    }
                }
                logger.Debug("End UploadFile");
            }
            catch (Exception ex)
            {
                logger.Error("Error UploadFile ", ex);
                throw ex;
            }
        }