Files
17168ERP/web/admin/project/update.aspx.cs
2025-08-29 01:27:25 +08:00

189 lines
5.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Globalization;
public partial class admin_project_update : MyWeb.config
{
private Model.ezEntities _db = new Model.ezEntities();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!isStrNull(Request["pro_id"]))
{
if (isStrNull(Request["pnum"]))
{
uptime.Text = DateTime.Now.ToString("yyyy-MM-dd");
}
else
{
int _num = Val(Request["pnum"]);
var qry = _db.project_sub.AsEnumerable();
var prod = qry.Where(q => q.num == _num).FirstOrDefault();
if (prod != null)
{
subject.Text = prod.subject;
word.Text = prod.word;
if (prod.uptime.HasValue)
{
uptime.Text = prod.uptime.Value.ToString("yyyy-MM-dd");
}
if (!string.IsNullOrEmpty(prod.pic1))
{
CheckBox1.Visible = true;
ViewState["pic1"] = prod.pic1;
Image1.Visible = true;
Image1.ImageUrl = "../../App_Script/DisplayCut.ashx?file=" + Model.project.Dir.Replace("~/upload/", "") + "/" + prod.pic1 + "&w=150&h=150";
}
edit.Visible = true;
add.Visible = false;
}
else
{
Response.Redirect("news_reg.aspx?num=" + Request["pro_id"]);
}
}
}
else
{
Response.Redirect("index.aspx");
}
}
}
protected void goback_Click(object sender, EventArgs e)
{
Response.Redirect("news_reg.aspx?num="+ Request["pro_id"] );
}
#region
protected void add_Click(object sender, EventArgs e)
{
if (Page.IsValid) {
L_msg.Text = "";
MyWeb.fileSystem fileSystem = new MyWeb.fileSystem();
string[] pic_name = fileSystem.UploadPhoto(Model.project.Dir, 1200); //縮圖的寬高不得超過800象素如果不是圖片也會傳
Model.project_sub project_sub = new Model.project_sub();//新增
project_sub.subject = subject.Text;
project_sub.word = word.Text;
project_sub.pro_id =Convert.ToInt32(Request["pro_id"]);
if (!isStrNull(uptime.Text)) { project_sub.uptime = ValDate(uptime.Text); }
if (pic_name.Length > 0 && !isStrNull(pic_name[0]))
project_sub.pic1 = pic_name[0];
project_sub.reg_time = DateTime.Now;
try
{
_db.project_sub.Add(project_sub);
_db.SaveChanges();
Response.Redirect("news_reg.aspx?num=" + Request["pro_id"]);
}
catch (Exception ex)
{
L_msg.Text = ex.Message;
L_msg.Type = alert_type.danger;
//L_msg.Text = "操作失敗";
}
}
}
#endregion
#region
protected void edit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
L_msg.Text = "";
MyWeb.fileSystem fileSystem = new MyWeb.fileSystem();
string[] pic_name = fileSystem.UploadPhoto(Model.project.Dir, 1200); //縮圖的寬高不得超過800象素如果不是圖片也會傳
int _num = Val(Request["pnum"]);
Model.project_sub project_sub = _db.project_sub.Where(q => q.num == _num).FirstOrDefault();//修改
if (project_sub != null)
{
project_sub.subject = subject.Text;
project_sub.word = word.Text;
if (!isStrNull(uptime.Text)) { project_sub.uptime = ValDate(uptime.Text); }
project_sub.pro_id = Convert.ToInt32(Request["pro_id"]);
if (pic_name[0] != "" | CheckBox1.Checked)
{
if (pic_name.Length > 0 && !isStrNull(pic_name[0]))
project_sub.pic1 = pic_name[0];
else
project_sub.pic1 = null;
if (!isStrNull(ViewState["pic1"])) // '刪除舊圖
{
fileSystem.Delete(Model.project.Dir + "/" + Convert.ToString(ViewState["pic1"]));
}
}
try
{
_db.SaveChanges();
Response.Redirect("news_reg.aspx?num=" + Request["pro_id"]);
}
catch (Exception ex)
{
L_msg.Type = alert_type.danger;
//L_msg.Text = ex.InnerException.Message;
L_msg.Text = "操作失敗";
}
}
else
{
L_msg.Type = alert_type.danger;
L_msg.Text = "查無資料";
}
}
}
#endregion
}