using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using WebLib; namespace Education.Forms.辦訓狀況 { public partial class 課程剪影處理 : FormBase { private DAC_課程剪影 Dao課程剪影; private string 圖檔儲存路徑; protected void Page_Load(object sender, EventArgs e) { FunctionName = "課程剪影"; Dao課程剪影 = new DAC_課程剪影(conn); 圖檔儲存路徑 = Server.MapPath(Education.PublicVariable.課程剪影路徑); if (IsPostBack) { GridView1.DataBind(); } Panel1.Style["display"] = 訓練企劃搜尋.訓練企劃編號 > 0 ? "block" : "none"; RegisterPostbackTrigger(btnInsert); } protected void ds已上課_ObjectCreating(object sender, ObjectDataSourceEventArgs e) { e.ObjectInstance = Dao訓練課程企劃; } protected void btnInsert_Click(object sender, EventArgs e) { if (!IsValid) return; 課程剪影 newValue = new 課程剪影(); newValue.課程企劃編號 = 訓練企劃搜尋.訓練企劃編號; newValue.照片說明 = txt照片說明.Text; newValue.照片序號 = Dao課程剪影.Next照片序號(newValue.課程企劃編號); newValue.DB_CRUSR = UserId; Dao課程剪影.InsertOne(newValue); string savePath = String.Format("{0}{1}", 圖檔儲存路徑, newValue.課程企劃編號); if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath); string tFullName = String.Format("{0}\\T_{1:000000}.jpg", savePath, newValue.照片序號); MemoryStream ms = PictureProcess.縮圖(fu照片上傳.PostedFile.InputStream, 270, 270); File.WriteAllBytes(tFullName, ms.ToArray()); ms.Dispose(); tFullName = String.Format("{0}\\{1:000000}.jpg", savePath, newValue.照片序號); ms = PictureProcess.縮圖(fu照片上傳.PostedFile.InputStream, 1200, 1200); File.WriteAllBytes(tFullName, ms.ToArray()); ms.Dispose(); GridView1.DataBind(); } protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) { args.IsValid = fu照片上傳.HasFile; } protected void btn查詢_Click(object sender, EventArgs e) { GridView1.DataBind(); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType != DataControlRowType.DataRow) return; 課程剪影 dataItem = e.Row.DataItem as 課程剪影; (e.Row.Cells[3].FindControl("Image1") as Image).ImageUrl = String.Format(Education.PublicVariable.課程剪影路徑 + "{0}/T_{1:000000}.jpg", dataItem.課程企劃編號, dataItem.照片序號); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int 課程企劃ID = DAC.GetInt32(e.Keys["課程企劃編號"]); int 照片序號 = DAC.GetInt32(e.Keys["照片序號"]); string fileName1 = String.Format("{0}{1}\\T_{2:000000}.jpg", 圖檔儲存路徑, 課程企劃ID, 照片序號); string fileName2 = String.Format("{0}{1}\\{2:000000}.jpg", 圖檔儲存路徑, 課程企劃ID, 照片序號); if (File.Exists(fileName1)) File.Delete(fileName1); if (File.Exists(fileName2)) File.Delete(fileName2); } } }