protected void Page_Load(object sender, EventArgs e) { if (Session["Login"] == null || Session["Package"] == null) { Response.Redirect("/Authorization/Login"); } package_login = (Base_Companys)Session["Package"]; acc_lgn = (Account_Login)Session["Login"]; if (!IsPostBack) { if (Session["Uploaded"] != null) { Session.Remove("Uploaded"); } if (Request.Params["code"] != null) { string[] code = Request.Params["code"].Split('U'); string Cust_id = code[1]; string number_img = code[2]; Customers_Manager ctm_mng = new Customers_Manager(); Customers_Home_Photo ctm_home_photo = ctm_mng.getCustomersHomePhotoSelected(Cust_id, number_img); if (string.IsNullOrEmpty(ctm_home_photo.Home_img_path)) { ctm_mng.removeCustomersHomePhoto(ctm_home_photo.Cust_id, ctm_home_photo.Home_img_num); } else { File.Delete(ctm_home_photo.Home_img_local_path); ctm_mng.removeCustomersHomePhoto(ctm_home_photo.Cust_id, ctm_home_photo.Home_img_num); } /// 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, " ลบรูปบ้าน", 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"] = 2; Response.Redirect("/Form_Customer/Customer_Home_Photo"); } } }
protected void Upload_Btn_Click(object sender, EventArgs e) { ctm = (Customers)Session["Customer"]; 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); } /* Create Sub Folder for Save Images of Car */ string subDirectory = "Home_Images"; 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) { ctm_mng = new Customers_Manager(); string number_img = ctm_mng.getLastNumberPhotoId(ctm.Cust_id); string digit = ctm_mng.generateDigitID(); string old_name = userPostedFile.FileName; string new_name = number_img + "_" + ctm.Cust_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)); Customers_Home_Photo ctm_photo = new Customers_Home_Photo(); ctm_photo.Cust_id = ctm.Cust_id; ctm_photo.Home_img_num = Convert.ToInt32(number_img); ctm_photo.Home_img_old_name = old_name; ctm_photo.Home_img_path = db_path; ctm_photo.Home_img_full_path = db_full_path; ctm_photo.Home_img_local_path = db_local_path; ctm_mng.addCustomersHomePhoto(ctm_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, " เพิ่มรูปบ้าน", 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"] = 0; string error = "ไม่สามารถ Upload รูปภาพนี้ได้ "; Log_Error._writeErrorFile(error, ex); } } Session["Uploaded"] = 1; _GetHomePhoto(); }