CeramicProject/newyt/Module_data/Development_Form.aspx.cs

295 lines
10 KiB
C#
Raw Normal View History

2024-05-18 15:28:29 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using Maticsoft.Model;
public partial class Development_Form: System.Web.UI.Page
{
//创建一个操作记录bll
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
//创建一个共用的产品开发模板
Maticsoft.Model.nr_z_cpkf cpkfmodel = new Maticsoft.Model.nr_z_cpkf();
//创建一个共同的产品开发bll
Maticsoft.BLL.nr_z_cpkf cpkfbll = new Maticsoft.BLL.nr_z_cpkf();
//创建一个操作记录模板
Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi();
//创建一个共用的编码bll层
Maticsoft.BLL.nr_sys_bianma bm = new Maticsoft.BLL.nr_sys_bianma();
//创建一个共用的类型BLL层
Maticsoft.BLL.nr_sys_leixing bmlx = new Maticsoft.BLL.nr_sys_leixing();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["user"] == null)
{
Response.Redirect("../index.aspx");
}
//获取角色权限
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
binddata();
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
{
string uid = Request.QueryString["uid"].ToString();
id.Value = uid;
initdata(Convert.ToInt32(uid));
pdquanxianbj(user.juese);
}
else
{
pdquanxian(user.juese);
}
}
}
#region
private void initdata(int did)
{
DataTable dt = DBHlper.Execute("select * from nr_z_cpkf where id=" + did).Tables[0];
if (dt.Rows.Count > 0)
{
kfbh.Text = dt.Rows[0]["kfbh"].ToString();
sjly.Value = dt.Rows[0]["sjly"].ToString();
xlh.Value = dt.Rows[0]["xlh"].ToString();
zhqx.Value = Convert.ToDateTime(dt.Rows[0]["zhqx"]).ToString("yyyy-MM-dd");
riqi.Value = Convert.ToDateTime(dt.Rows[0]["riqi"]).ToString("yyyy-MM-dd");
zwsjmc.Value = dt.Rows[0]["zwsjmc"].ToString();
ywsjmc.Value = dt.Rows[0]["ywsjmc"].ToString();
ydrq.Value = Convert.ToDateTime(dt.Rows[0]["ydrq"]).ToString("yyyy-MM-dd");
dyrq.Value = Convert.ToDateTime(dt.Rows[0]["dyrq"]).ToString("yyyy-MM-dd");
ydksrq.Value = Convert.ToDateTime(dt.Rows[0]["ydksrq"]).ToString("yyyy-MM-dd");
ydjsrq.Value = Convert.ToDateTime(dt.Rows[0]["ydjsrq"]).ToString("yyyy-MM-dd");
sjnr.Text = dt.Rows[0]["sjnr"].ToString();
rwgx.Text = dt.Rows[0]["rwgx"].ToString();
beizhu.Text = dt.Rows[0]["beizhu"].ToString();
}
}
#endregion
#region
private void binddata()
{
zhqx.Value = DateTime.Now.ToString("yyyy-MM-dd");
riqi.Value = DateTime.Now.ToString("yyyy-MM-dd");
ydrq.Value = DateTime.Now.ToString("yyyy-MM-dd");
dyrq.Value = DateTime.Now.ToString("yyyy-MM-dd");
ydksrq.Value = DateTime.Now.ToString("yyyy-MM-dd");
ydjsrq.Value = DateTime.Now.ToString("yyyy-MM-dd");
}
#endregion
#region
void pdquanxian(int juese)
{
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
if (DBHlper.getzt(user.id) != 1)
{
Response.Redirect("../index.aspx");
}
if (DBHlper.getqx(juese, "产品开发", "nr_z_cpkf", "添加") == false)
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
#region
void pdquanxianbj(int juese)
{
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
if (DBHlper.getzt(user.id) != 1)
{
Response.Redirect("../index.aspx");
}
if (DBHlper.getqx(juese, "产品开发", "nr_z_cpkf", "编辑全部") == false)
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
#region model对象
private void getmd()
{
cpkfmodel.kfbh = kfbh.Text;
cpkfmodel.sjly = sjly.Value;
cpkfmodel.xlh = xlh.Value;
cpkfmodel.zhqx = Convert.ToDateTime(zhqx.Value);
cpkfmodel.riqi = Convert.ToDateTime(riqi.Value);
cpkfmodel.zwsjmc = zwsjmc.Value;
cpkfmodel.ywsjmc = ywsjmc.Value;
cpkfmodel.ydrq = Convert.ToDateTime(ydrq.Value);
cpkfmodel.dyrq = Convert.ToDateTime(dyrq.Value);
cpkfmodel.ydksrq = Convert.ToDateTime(ydksrq.Value);
cpkfmodel.ydjsrq = Convert.ToDateTime(ydjsrq.Value);
cpkfmodel.sjnr = sjnr.Text;
cpkfmodel.rwgx = rwgx.Text;
cpkfmodel.beizhu = beizhu.Text;
if (tp.FileContent.Length > 0)
{
FileUpLoadzm();
cpkfmodel.tp = tpName;
}
else
{
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
{
int idz = Convert.ToInt32(id.Value);
nr_z_cpkf cpmodel = cpkfbll.GetModel(idz);
cpkfmodel.tp = cpmodel.tp;
}
}
if (wj.FileContent.Length > 0)
{
FileUpLoadwj();
cpkfmodel.wj = wjName;
}
else
{
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
{
int idz = Convert.ToInt32(id.Value);
nr_z_cpkf cpmodel = cpkfbll.GetModel(idz);
cpkfmodel.wj = cpmodel.wj;
}
}
//给日志模板赋值
rizhi.riqi = DateTime.Now;
rizhi.leixing = "产品开发";
}
#endregion
protected void bt_tj_Click(object sender, EventArgs e)
{
try
{
string caozuo = "添加";
getmd();
//接收成功参数值
int rtx = 0;
//判断uid是否存在值有值为修改无值为添加
if (id.Value != null && id.Value != "")
{
cpkfmodel.id = Convert.ToInt32(id.Value);
if (cpkfbll.Update(cpkfmodel))
{
rtx = Convert.ToInt32(id.Value);
caozuo = "修改";
}
}
else
{
cpkfmodel.kfbh = DBHlper.getbh("KF-", "nr_z_cpkf", "kfbh", 4);
kfbh.Text = cpkfmodel.kfbh;
rtx = cpkfbll.Add(cpkfmodel);
}
if (rtx > 0)
{
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
rizhi.yonghuming = zh.zhanghao;
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + caozuo + "了产品开发,编号为:" + kfbh.Text.Trim();
rizhibll.Add(rizhi);
Response.Redirect("Development_browse.aspx?uid=" + rtx, false);
}
else
{
Response.Redirect("../Common/error.aspx");
}
}
catch (Exception)
{
Response.Redirect("../Common/error.aspx");
}
}
string tpName = "";
public void FileUpLoadzm()
{
try
{
if (!tp.HasFile && !tp.HasFile)
{
Response.Write("<script>alert('请选择要上传的文件')</script>");
return;
}
if (!tp.HasFile) { }
else
{
string directoyPath = System.Web.HttpContext.Current.Server.MapPath("~/Client_Folder/");
if (!System.IO.Directory.Exists(directoyPath))
{
System.IO.Directory.CreateDirectory(directoyPath);
}
tpName = "CPKFTP" + DateTime.Now.ToString("yyyy-MM-dd") + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "-" + zwsjmc.Value + "." + tp.PostedFile.FileName.Substring(tp.PostedFile.FileName.LastIndexOf(".") + 1);
string path = "~/Client_Folder/" + tpName;
if (File.Exists(path))
{
Response.Write("<script language='javascript'>alert('服务器上已经有了你正在上传的文件:" + tpName + "');</script>");
return;
}
tp.PostedFile.SaveAs(Server.MapPath(path));
}
}
catch
{ Response.Write("<script>alert('上传失败!')</script>"); }
}
string wjName = "";
public void FileUpLoadwj()
{
try
{
if (!wj.HasFile && !wj.HasFile)
{
Response.Write("<script>alert('请选择要上传的文件')</script>");
return;
}
if (!wj.HasFile) { }
else
{
string directoyPath = System.Web.HttpContext.Current.Server.MapPath("~/Client_Folder/");
if (!System.IO.Directory.Exists(directoyPath))
{
System.IO.Directory.CreateDirectory(directoyPath);
}
wjName = "CPKFWJ" + DateTime.Now.ToString("yyyy-MM-dd") + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "-" + zwsjmc.Value + "." + wj.PostedFile.FileName.Substring(wj.PostedFile.FileName.LastIndexOf(".") + 1);
string path = "~/Client_Folder/" + wjName;
if (File.Exists(path))
{
Response.Write("<script language='javascript'>alert('服务器上已经有了你正在上传的文件:" + wjName + "');</script>");
return;
}
wj.PostedFile.SaveAs(Server.MapPath(path));
}
}
catch
{ Response.Write("<script>alert('上传失败!')</script>"); }
}
}