chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore - 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using WebLib;
|
||||
|
||||
namespace Education.Forms.溝通記錄
|
||||
{
|
||||
public partial class 溝通記錄附件 : FormBase
|
||||
{
|
||||
private int id;
|
||||
private DAC_檔案圖示 Dao檔案圖示;
|
||||
private DAC_訓練溝通記錄附件 Dao訓練溝通記錄附件;
|
||||
private DAC_訓練溝通記錄 Dao訓練溝通記錄;
|
||||
private string 圖檔儲存路徑;
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
FunctionName = "溝通紀錄附件管理";
|
||||
id = DAC.GetInt32(Request["id"]);
|
||||
Dao檔案圖示 = new DAC_檔案圖示();
|
||||
Dao訓練溝通記錄附件 = new DAC_訓練溝通記錄附件(conn);
|
||||
Dao訓練溝通記錄 = new DAC_訓練溝通記錄(conn);
|
||||
圖檔儲存路徑 = Server.MapPath(Education.PublicVariable.溝通記錄上傳路徑);
|
||||
|
||||
RegisterPostbackTrigger(btnInsert);
|
||||
|
||||
if (!IsPostBack)
|
||||
{
|
||||
var 訓練溝通記錄 = Dao訓練溝通記錄.SelectOne(id).FirstOrDefault();
|
||||
if (訓練溝通記錄 != null)
|
||||
{
|
||||
var 訓練課程企劃 = new DAC_訓練課程企劃().SelectOne(訓練溝通記錄.訓練課程企劃編號).FirstOrDefault();
|
||||
if (訓練課程企劃 != null)
|
||||
lb課程.Text = $"[{訓練課程企劃.顯示編號}] [{訓練課程企劃.訓練日期, 0:yyyy-MM-dd}]{訓練課程企劃.訓練名稱}";
|
||||
lb溝通歷程.Text = new DAC_訓練溝通記錄歷程().GetName(訓練溝通記錄.溝通歷程);
|
||||
lb檢附資料參考.Text = GetData.取得檢附資料參考(訓練溝通記錄.溝通歷程.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gv訓練溝通記錄附件.DataBind();
|
||||
}
|
||||
|
||||
(Master as PopupForm).RefreshOpener = true;
|
||||
}
|
||||
|
||||
protected string GetAttachImageUrl(object o編號, object o檔案名稱, object o副檔名)
|
||||
{
|
||||
var 編號 = DAC.GetInt32(o編號);
|
||||
var 檔案名稱 = DAC.GetString(o檔案名稱);
|
||||
var 副檔名 = DAC.GetString(o副檔名);
|
||||
var icon = Dao檔案圖示.GetName(副檔名.ToLower());
|
||||
if (icon == String.Empty)
|
||||
icon = "file.png";
|
||||
return ResolveClientUrl($"~/picture/{icon}");
|
||||
}
|
||||
|
||||
protected void gv訓練溝通記錄附件_RowDataBound(object sender, GridViewRowEventArgs e)
|
||||
{
|
||||
if (e.Row.RowType == DataControlRowType.DataRow)
|
||||
{
|
||||
var hlItem = e.Row.Cells[3].FindControl("hlItem") as HyperLink;
|
||||
hlItem.Attributes.Add("onclick", $"OpenAttachment({(e.Row.DataItem as 訓練溝通記錄附件Item)?.編號});");
|
||||
}
|
||||
}
|
||||
|
||||
protected void btnInsert_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsValid)
|
||||
return;
|
||||
|
||||
var fileName = fu檔案上傳.FileName;
|
||||
var fileExt = Path.GetExtension(fu檔案上傳.FileName).ToLower();
|
||||
if (fileExt.StartsWith("."))
|
||||
fileExt = fileExt.Substring(1);
|
||||
|
||||
var newValue = new 訓練溝通記錄附件Item()
|
||||
{
|
||||
訓練溝通記錄編號 = id,
|
||||
標題 = txt標題.Text,
|
||||
檔案名稱 = fileName,
|
||||
副檔名 = fileExt,
|
||||
ContentType = fu檔案上傳.PostedFile.ContentType
|
||||
};
|
||||
|
||||
Dao訓練溝通記錄附件.InsertOne(newValue);
|
||||
|
||||
string savePath = String.Format("{0}{1}", 圖檔儲存路徑, id);
|
||||
if (!Directory.Exists(savePath))
|
||||
Directory.CreateDirectory(savePath);
|
||||
|
||||
var tFullName = String.Format("{0}\\{1:000000}.{2}", savePath, newValue.編號, fileExt);
|
||||
fu檔案上傳.PostedFile.SaveAs(tFullName);
|
||||
|
||||
gv訓練溝通記錄附件.DataBind();
|
||||
}
|
||||
|
||||
protected void ds訓練溝通記錄附件Grid_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
|
||||
{
|
||||
e.ObjectInstance = Dao訓練溝通記錄附件;
|
||||
}
|
||||
|
||||
protected void gv訓練溝通記錄附件_RowDeleting(object sender, GridViewDeleteEventArgs e)
|
||||
{
|
||||
int 訓練溝通記錄編號 = DAC.GetInt32(e.Keys["訓練溝通記錄編號"]);
|
||||
int 編號 = DAC.GetInt32(e.Keys["編號"]);
|
||||
string 副檔名 = DAC.GetString(e.Keys["副檔名"]);
|
||||
string fileName1 = String.Format("{0}{1}\\{2:000000}.{3}", 圖檔儲存路徑, 訓練溝通記錄編號, 編號, 副檔名);
|
||||
if (File.Exists(fileName1))
|
||||
File.Delete(fileName1);
|
||||
}
|
||||
|
||||
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
|
||||
{
|
||||
args.IsValid = fu檔案上傳.HasFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user