355 lines
12 KiB
C#
355 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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 bool fileOK = false;
|
|
private int 新編號;
|
|
private string 圖檔儲存路徑;
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
FunctionName = "場地基本資料";
|
|
圖檔儲存路徑 = Server.MapPath(Education.PublicVariable.場地照片路徑);
|
|
|
|
Form_View = FormView1;
|
|
Grid_View = GridView1;
|
|
FormView_DataSource = dsForm;
|
|
GridView_DataSource = dsGrid;
|
|
|
|
AddTabButton(MultiView1, 0, btnSearchTab);
|
|
AddTabButton(MultiView1, 1, btnProcessTab);
|
|
|
|
if (!IsPostBack)
|
|
{
|
|
BindSearchDDL();
|
|
ActivateTab(MultiView1, 1);
|
|
}
|
|
else
|
|
{
|
|
Grid_View.DataBind();
|
|
Form_View.DataBind();
|
|
}
|
|
|
|
if (Form_View.CurrentMode != FormViewMode.ReadOnly)
|
|
{
|
|
Grid_View.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void BindSearchDDL()
|
|
{
|
|
ddl場地地區.DataSource = Dao場地.Select地區ForDropDown();
|
|
ddl場地地區.DataTextField = "Name";
|
|
ddl場地地區.DataValueField = "Value";
|
|
ddl場地地區.DataBind();
|
|
|
|
ddl場地教室類型.DataSource = Dao場地.Select教室類型ForDropDown();
|
|
ddl場地教室類型.DataTextField = "Name";
|
|
ddl場地教室類型.DataValueField = "Value";
|
|
ddl場地教室類型.DataBind();
|
|
}
|
|
|
|
protected override void CalcFields(object sender, ObjectDataSourceMethodEventArgs e)
|
|
{
|
|
base.CalcFields(sender, e);
|
|
}
|
|
|
|
protected override void FormView_ReadOnlyDataBound(object sender, EventArgs e)
|
|
{
|
|
base.FormView_ReadOnlyDataBound(sender, e);
|
|
|
|
int 編號 = 0;
|
|
Label lb編號 = FindControl<Label>(Form_View, "lb編號");
|
|
if (lb編號 != null)
|
|
編號 = DAC.GetInt32(lb編號.Text);
|
|
|
|
Image image1 = FindControl<Image>(Form_View, "Image1");
|
|
if (image1 != null)
|
|
{
|
|
string[] tmp = image1.ImageUrl.Split('?');
|
|
if (tmp.Length > 0 && !File.Exists(Server.MapPath(tmp[0])))
|
|
{
|
|
image1.ImageUrl = "~/picture/nopicture.jpg";
|
|
image1.Attributes.Remove("onclick");
|
|
image1.Style.Remove("cursor");
|
|
}
|
|
else
|
|
{
|
|
image1.Attributes.Add("onclick", GetOpenWindowJS("../Common/ShowLargePicture.aspx", "_picture", "pic", String.Format(Education.PublicVariable.場地照片路徑 + "{0:000000}_1.jpg", 編號)));
|
|
image1.Style.Add("cursor", "pointer");
|
|
}
|
|
}
|
|
|
|
Image image2 = FindControl<Image>(Form_View, "Image2");
|
|
if (image2 != null)
|
|
{
|
|
string[] tmp = image2.ImageUrl.Split('?');
|
|
if (tmp.Length > 0 && !File.Exists(Server.MapPath(tmp[0])))
|
|
{
|
|
image2.ImageUrl = "~/picture/nopicture.jpg";
|
|
image2.Attributes.Remove("onclick");
|
|
image2.Style.Remove("cursor");
|
|
}
|
|
else
|
|
{
|
|
image2.Attributes.Add("onclick", GetOpenWindowJS("../Common/ShowLargePicture.aspx", "_picture", "pic", String.Format(Education.PublicVariable.場地照片路徑 + "{0:000000}_2.jpg", 編號)));
|
|
image2.Style.Add("cursor", "pointer");
|
|
}
|
|
}
|
|
|
|
System.Data.DataTable 滿意度 = Dao場地.Select滿意度統計(編號);
|
|
if (滿意度.Rows.Count > 0)
|
|
{
|
|
Label lb5分 = FindControl<Label>(Form_View, "lb5分");
|
|
Label lb4分 = FindControl<Label>(Form_View, "lb4分");
|
|
Label lb3分 = FindControl<Label>(Form_View, "lb3分");
|
|
Label lb2分 = FindControl<Label>(Form_View, "lb2分");
|
|
Label lb1分 = FindControl<Label>(Form_View, "lb1分");
|
|
Label lb總分 = FindControl<Label>(Form_View, "lb總分");
|
|
if (lb5分 != null)
|
|
lb5分.Text = DAC.GetString(滿意度.Rows[0]["場地滿意度5"]);
|
|
if (lb4分 != null)
|
|
lb4分.Text = DAC.GetString(滿意度.Rows[0]["場地滿意度4"]);
|
|
if (lb3分 != null)
|
|
lb3分.Text = DAC.GetString(滿意度.Rows[0]["場地滿意度3"]);
|
|
if (lb2分 != null)
|
|
lb2分.Text = DAC.GetString(滿意度.Rows[0]["場地滿意度2"]);
|
|
if (lb1分 != null)
|
|
lb1分.Text = DAC.GetString(滿意度.Rows[0]["場地滿意度1"]);
|
|
if (lb總分 != null)
|
|
lb總分.Text = String.Format("{0:##0.00}", 滿意度.Rows[0]["場地滿意度總分"]);
|
|
}
|
|
|
|
RegisterPostbackTrigger(Form_View.FindControl("btnUploadPhoto1"));
|
|
RegisterPostbackTrigger(Form_View.FindControl("btnUploadPhoto2"));
|
|
}
|
|
|
|
protected override void FormView_InsertDataBound(object sender, EventArgs e)
|
|
{
|
|
base.FormView_InsertDataBound(sender, e);
|
|
|
|
FormViewSetControlValue("txt價格", "0");
|
|
FormViewSetControlValue("txt坪數", "0");
|
|
FormViewSetControlValue("txt容納人數", "0");
|
|
FormViewSetControlValue("txt捷運分鐘", "0");
|
|
FormViewSetControlValue("txt公車分鐘", "0");
|
|
FormViewSetControlValue("txt火車分鐘", "0");
|
|
FormViewSetControlValue("txt步行分鐘", "0");
|
|
}
|
|
|
|
protected override void FormView_ItemInserted(object sender, FormViewInsertedEventArgs e)
|
|
{
|
|
base.FormView_ItemInserted(sender, e);
|
|
//FileUpload fu1 = Form_View.FindControl("fuPhoto1") as FileUpload;
|
|
//FileUpload fu2 = Form_View.FindControl("fuPhoto2") as FileUpload;
|
|
// 儲存照片與縮圖(fu1, fu2, 新編號);
|
|
BindSearchDDL();
|
|
}
|
|
|
|
protected override void FormView_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
|
|
{
|
|
base.FormView_ItemUpdated(sender, e);
|
|
//FileUpload fu1 = Form_View.FindControl("fuPhoto1") as FileUpload;
|
|
//FileUpload fu2 = Form_View.FindControl("fuPhoto2") as FileUpload;
|
|
//儲存照片與縮圖(fu1, fu2, DAC.GetInt32(e.Keys["編號"]));
|
|
BindSearchDDL();
|
|
}
|
|
|
|
protected override void FormView_ItemDeleting(object sender, FormViewDeleteEventArgs e)
|
|
{
|
|
base.FormView_ItemDeleting(sender, e);
|
|
if (Dao場地.IsOccipued(DAC.GetInt32(e.Keys["編號"])))
|
|
{
|
|
ClientShowMessage("此場地已經選用過,不可刪除!");
|
|
e.Cancel = true;
|
|
}
|
|
}
|
|
|
|
protected override void FormView_ItemDeleted(object sender, FormViewDeletedEventArgs e)
|
|
{
|
|
base.FormView_ItemDeleted(sender, e);
|
|
// 刪除縮圖與大圖
|
|
string s1 = String.Format("{0}T_{1:000000}_1.jpg", 圖檔儲存路徑, e.Keys["編號"]);
|
|
string s2 = String.Format("{0}T_{1:000000}_2.jpg", 圖檔儲存路徑, e.Keys["編號"]);
|
|
string s3 = String.Format("{0}{1:000000}_1.jpg", 圖檔儲存路徑, e.Keys["編號"]);
|
|
string s4 = String.Format("{0}{1:000000}_2.jpg", 圖檔儲存路徑, e.Keys["編號"]);
|
|
if (File.Exists(s1))
|
|
File.Delete(s1);
|
|
if (File.Exists(s2))
|
|
File.Delete(s2);
|
|
if (File.Exists(s3))
|
|
File.Delete(s3);
|
|
if (File.Exists(s4))
|
|
File.Delete(s4);
|
|
BindSearchDDL();
|
|
}
|
|
|
|
protected override void FormView_DataSource_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
|
|
{
|
|
base.FormView_DataSource_Inserted(sender, e);
|
|
新編號 = DAC.GetInt32(e.ReturnValue);
|
|
}
|
|
|
|
protected override void FormView_ItemCommand(object sender, FormViewCommandEventArgs e)
|
|
{
|
|
base.FormView_ItemCommand(sender, e);
|
|
if (e.CommandName == "刪除圖片1")
|
|
{
|
|
string s1 = String.Format("{0}T_{1:000000}_1.jpg", 圖檔儲存路徑, DAC.GetInt32(e.CommandArgument));
|
|
string s3 = String.Format("{0}{1:000000}_1.jpg", 圖檔儲存路徑, DAC.GetInt32(e.CommandArgument));
|
|
if (File.Exists(s1))
|
|
File.Delete(s1);
|
|
if (File.Exists(s3))
|
|
File.Delete(s3);
|
|
Form_View.DataBind();
|
|
}
|
|
if (e.CommandName == "刪除圖片2")
|
|
{
|
|
string s2 = String.Format("{0}T_{1:000000}_2.jpg", 圖檔儲存路徑, DAC.GetInt32(e.CommandArgument));
|
|
string s4 = String.Format("{0}{1:000000}_2.jpg", 圖檔儲存路徑, DAC.GetInt32(e.CommandArgument));
|
|
if (File.Exists(s2))
|
|
File.Delete(s2);
|
|
if (File.Exists(s4))
|
|
File.Delete(s4);
|
|
Form_View.DataBind();
|
|
}
|
|
|
|
if (e.CommandName == "上傳照片1")
|
|
{
|
|
FileUpload fu = FindControl<FileUpload>(Form_View, "fuPhoto1");
|
|
CheckPhoto(fu, out fileOK);
|
|
儲存照片與縮圖(fu, DAC.GetInt32(e.CommandArgument), 1);
|
|
Form_View.DataBind();
|
|
}
|
|
|
|
if (e.CommandName == "上傳照片2")
|
|
{
|
|
FileUpload fu = FindControl<FileUpload>(Form_View, "fuPhoto2");
|
|
CheckPhoto(fu, out fileOK);
|
|
儲存照片與縮圖(fu, DAC.GetInt32(e.CommandArgument), 2);
|
|
Form_View.DataBind();
|
|
}
|
|
}
|
|
|
|
protected override void GridView_DataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
|
|
{
|
|
base.GridView_DataSource_Selected(sender, e);
|
|
|
|
if (MultiView1.ActiveViewIndex == 0)
|
|
{
|
|
if (e.ReturnValue is 場地List list && list.Count > 0)
|
|
ActivateTab(MultiView1, 1);
|
|
else
|
|
lbMessage.Text = "找不到合乎條件的資料";
|
|
}
|
|
}
|
|
|
|
protected void 儲存照片與縮圖(FileUpload fu1, int 編號, int 序號)
|
|
{
|
|
if (fileOK)
|
|
{
|
|
string tFullName = String.Format("{0}T_{1:000000}_{2}.jpg", 圖檔儲存路徑, 編號, 序號);
|
|
MemoryStream ms = PictureProcess.縮圖(fu1.PostedFile.InputStream, 300, 300);
|
|
File.WriteAllBytes(tFullName, ms.ToArray());
|
|
ms.Dispose();
|
|
|
|
tFullName = String.Format("{0}{1:000000}_{2}.jpg", 圖檔儲存路徑, 編號, 序號);
|
|
ms = PictureProcess.縮圖(fu1.PostedFile.InputStream, 1200, 1200);
|
|
File.WriteAllBytes(tFullName, ms.ToArray());
|
|
ms.Dispose();
|
|
}
|
|
|
|
/*
|
|
if (file2OK)
|
|
{
|
|
string tFullName = String.Format("{0}T_{1:000000}_2.jpg", 圖檔儲存路徑, 編號);
|
|
MemoryStream ms = PictureProcess.縮圖(fu2.PostedFile.InputStream, 270, 270);
|
|
File.WriteAllBytes(tFullName, ms.ToArray());
|
|
ms.Dispose();
|
|
|
|
tFullName = String.Format("{0}{1:000000}_2.jpg", 圖檔儲存路徑, 編號);
|
|
ms = PictureProcess.縮圖(fu2.PostedFile.InputStream, 1200, 1200);
|
|
File.WriteAllBytes(tFullName, ms.ToArray());
|
|
ms.Dispose();
|
|
}
|
|
*/
|
|
}
|
|
|
|
protected void cvPhoto1_ServerValidate(object source, ServerValidateEventArgs args)
|
|
{
|
|
FileUpload fu = FindControl<FileUpload>(Form_View, "fuPhoto1");
|
|
args.IsValid = CheckPhoto(fu, out fileOK);
|
|
}
|
|
|
|
protected void cvPhoto2_ServerValidate(object source, ServerValidateEventArgs args)
|
|
{
|
|
FileUpload fu = FindControl<FileUpload>(Form_View, "fuPhoto2");
|
|
args.IsValid = CheckPhoto(fu, out fileOK);
|
|
}
|
|
|
|
protected bool CheckPhoto(FileUpload fu, out bool fileOK)
|
|
{
|
|
// 處理上傳照片
|
|
string ext = "";
|
|
fileOK = false;
|
|
|
|
if (fu.HasFile && fu.PostedFile.ContentType.ToLower().IndexOf("image") >= 0)
|
|
{
|
|
// 檢查副檔名
|
|
ext = Path.GetExtension(fu.FileName).ToLower();
|
|
String[] allowedExt = { ".gif", ".jpeg", ".jpg", ".png" };
|
|
for (int i = 0; i < allowedExt.Length; i++)
|
|
{
|
|
if (ext == allowedExt[i])
|
|
{
|
|
fileOK = true;
|
|
}
|
|
}
|
|
|
|
// 檢查檔案大小
|
|
if (fileOK && fu.PostedFile.ContentLength < 5242880)
|
|
fileOK = true;
|
|
else
|
|
fileOK = false;
|
|
|
|
return fileOK;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
protected void btnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
Grid_View.PageIndex = 0;
|
|
Grid_View.DataBind();
|
|
}
|
|
|
|
protected void btnClear_Click(object sender, EventArgs e)
|
|
{
|
|
ddl場地地區.SelectedValue = "";
|
|
txt場地價格1.Text = "";
|
|
txt場地價格2.Text = "";
|
|
txt場地人數1.Text = "";
|
|
txt場地人數2.Text = "";
|
|
ddl場地教室類型.SelectedValue = "";
|
|
txt場地滿意度1.Text = "";
|
|
txt場地滿意度2.Text = "";
|
|
}
|
|
|
|
protected void dsForm_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
|
|
{
|
|
e.ObjectInstance = Dao場地;
|
|
}
|
|
}
|
|
}
|