예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Login"] == null || Session["Package"] == null)
            {
                Response.Redirect("/Authorization/Login");
            }

            if (!IsPostBack)
            {
                if (Session["Uploaded"] != null)
                {
                    Session.Remove("Uploaded");
                }

                if (Request.Params["code"] != null)
                {
                    string[] code       = Request.Params["code"].Split('U');
                    string   Leasing_id = code[1];
                    string   number_img = code[2];

                    cls_photo = cls_mng.getLeasingsCarPhotoSelected(Leasing_id, number_img);

                    if (string.IsNullOrEmpty(cls_photo.Car_img_path))
                    {
                        cls_mng.removeLeasingsCarPhoto(cls_photo.Leasing_id, cls_photo.Car_img_num);
                    }
                    else
                    {
                        File.Delete(cls_photo.Car_img_local_path);
                        cls_mng.removeLeasingsCarPhoto(cls_photo.Leasing_id, cls_photo.Car_img_num);
                    }

                    cls = (Car_Leasings)Session["Leasings"];

                    /// Acticity Logs System
                    ///

                    package_login = (Base_Companys)Session["Package"];
                    acc_lgn       = (Account_Login)Session["Login"];

                    string message = Messages_Logs._messageLogsNormal(acc_lgn.Account_F_name, " ลบรูปรถ ในสัญญา : " + cls.Leasing_no + " เลขที่ฝาก : " + cls.Deps_no, acc_lgn.resu, package_login.Company_N_name);

                    new Activity_Log_Manager().addActivityLogs(message, acc_lgn.Account_id, package_login.Company_id);

                    /// Acticity Logs System

                    Session["Remove_Message"]        = 1;
                    Session["Class_Active_Customer"] = 9;
                    Response.Redirect("/Form_Leasings/Leasing_Car_Img");
                }
            }
        }
        protected void Upload_Btn_Click(object sender, EventArgs e)
        {
            ctm = (Customers)Session["Customer_Leasing"];

            string server_path = Server.MapPath("/");

            /* Create Main Folder for Detected Images of Contact Leasing  */
            string mainDirectory = ctm.Cust_id;

            string mainDirectoryPath = server_path + "\\Uploaded_Images\\" + mainDirectory;

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

            cls = (Car_Leasings)Session["Leasings"];

            /* Create Sub Folder for Save Images of Car */
            string subDirectory = "Car_Images_" + cls.Leasing_id;

            string subDirectoryPath = mainDirectoryPath + "\\" + subDirectory;

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


            /* Get File From TextFile  */
            HttpFileCollection uploadedFiles = Request.Files;

            for (int i = 0; i < uploadedFiles.Count; i++)
            {
                HttpPostedFile userPostedFile = uploadedFiles[i];

                try
                {
                    if (userPostedFile.ContentLength > 0)
                    {
                        cls_mng = new Car_Leasings_Manager();
                        string number_img = cls_mng.getLastNumberLeasingsCarPhotoId(cls.Leasing_id);
                        string digit      = cls_mng.generateLeasingsCarDigitID();

                        string old_name = userPostedFile.FileName;
                        string new_name = number_img + "_" + cls.Leasing_id + "_" + digit + Path.GetExtension(userPostedFile.FileName);

                        string db_path       = "../Uploaded_Images/" + mainDirectory + "/" + subDirectory + "/" + new_name;
                        string db_full_path  = subDirectoryPath.Replace('\\', '/') + "/" + new_name;
                        string db_local_path = subDirectoryPath + "\\" + new_name;

                        userPostedFile.SaveAs(subDirectoryPath + "\\" + Path.GetFileName(old_name).Replace(old_name, new_name));

                        Car_Leasings_Photo cls_photo = new Car_Leasings_Photo();

                        cls_photo.Leasing_id         = cls.Leasing_id;
                        cls_photo.Car_img_num        = Convert.ToInt32(number_img);
                        cls_photo.Car_img_old_name   = old_name;
                        cls_photo.Car_img_path       = db_path;
                        cls_photo.Car_img_full_path  = db_full_path;
                        cls_photo.Car_img_local_path = db_local_path;

                        cls_mng.addLeasingsCarPhoto(cls_photo);

                        /// Acticity Logs System
                        ///

                        package_login = (Base_Companys)Session["Package"];
                        acc_lgn       = (Account_Login)Session["Login"];

                        string message = Messages_Logs._messageLogsNormal(acc_lgn.Account_F_name, " เพิ่มรูปรถ ในสัญญา : " + cls.Leasing_no + " เลขที่ฝาก : " + cls.Deps_no, acc_lgn.resu, package_login.Company_N_name);

                        new Activity_Log_Manager().addActivityLogs(message, acc_lgn.Account_id, package_login.Company_id);

                        /// Acticity Logs System
                    }
                }
                catch (Exception ex)
                {
                    Session["Uploaded_Leasing"] = 0;
                    string error = "ไม่สามารถ Upload รูปภาพนี้ได้ ";
                    Log_Error._writeErrorFile(error, ex);
                }
            }

            Session["Uploaded_Leasing"] = 1;

            _GetHomePhoto();
        }