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 Product_Formt : System.Web.UI.Page
{
//创建一个操作记录bll
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
//创建一个共用的申购单模板
Maticsoft.Model.nr_z_cpkc cpkcmodel = new Maticsoft.Model.nr_z_cpkc();
//创建一个共同的申购单bll
Maticsoft.BLL.nr_z_cpkc cpkcbll = new Maticsoft.BLL.nr_z_cpkc();
//创建一个操作记录模板
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();
//创建一个共同的产品物料bll
Maticsoft.BLL.nr_z_cpkc_wlxq cpwlbll = new Maticsoft.BLL.nr_z_cpkc_wlxq();
//创建一个共同的水彩用料bll
Maticsoft.BLL.nr_z_cpkc_scyl scylbll = new Maticsoft.BLL.nr_z_cpkc_scyl();
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);
//getbjscyl();
setxmxq(id.Value);
}
else
{
pdquanxian(user.juese);
jsr.Value = user.zhanghao;
}
}
}
#region 修改时获取真正数据值
private void initdata(int did)
{
DataTable dt = DBHlper.Execute("select * from view_nr_z_cpkc where id=" + did).Tables[0];
if (dt.Rows.Count > 0)
{
cpbh.Text = dt.Rows[0]["cpbh"].ToString();
cpmc.Value = dt.Rows[0]["cpmc"].ToString();
riqi.Value = Convert.ToDateTime(dt.Rows[0]["riqi"]).ToString("yyyy-MM-dd");
gg.Value = dt.Rows[0]["gg"].ToString();
//zhongliang.Value = dt.Rows[0]["zhongliang"].ToString();
//tiji.Value = dt.Rows[0]["tiji"].ToString();
string danwei = dt.Rows[0]["dw"].ToString();
for (int i = 0; i < dw.Items.Count; i++)
{
if (dw.Items[i].Text == danwei)
{
dw.Items[i].Selected = true;
}
}
/*string zhonglei = dt.Rows[0]["zl"].ToString();
for (int i = 0; i < zl.Items.Count; i++)
{
if (zl.Items[i].Text == zhonglei)
{
zl.Items[i].Selected = true;
}
}*/
dj.Value = dt.Rows[0]["dj"].ToString();
jsr.Value = dt.Rows[0]["jsr"].ToString();
bz.Text = dt.Rows[0]["bz"].ToString();
}
}
#endregion
#region 用来初始化绑定下拉框等值
private void binddata()
{
riqi.Value = DateTime.Now.ToString("yyyy-MM-dd");
dj.Value = "0";
DataSet hylx = bmlx.GetAllList();
DataRow[] dr = hylx.Tables[0].Select("leixing='单位'");
if (dr != null && dr.Length > 0)
{
DataSet ly = bm.GetList("zhongleiid='" + dr[0]["id"] + "' and zt='1'");
if (ly != null)
{
dw.DataSource = ly.Tables[0].DefaultView;
dw.DataValueField = "id";
dw.DataTextField = "mingcheng";
dw.DataBind();
}
}
/*dr = hylx.Tables[0].Select("leixing='产品种类'");
if (dr != null && dr.Length > 0)
{
DataSet ly = bm.GetList("zhongleiid='" + dr[0]["id"] + "' and zt='1'");
if (ly != null)
{
zl.DataSource = ly.Tables[0].DefaultView;
zl.DataValueField = "id";
zl.DataTextField = "mingcheng";
zl.DataBind();
}
}*/
}
#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.GetPermission(juese, "产品档案", "nr_z_cpkc", "添加") == 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.GetPermission(juese, "产品档案", "nr_z_cpkc", "编辑全部") == false)
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
#region 获取页面参数赋值model对象
private void getmd()
{
cpkcmodel.cpbh = cpbh.Text;
cpkcmodel.cpmc = cpmc.Value;
cpkcmodel.riqi = Convert.ToDateTime(riqi.Value);
cpkcmodel.gg = gg.Value;
//cpkcmodel.zhongliang = Convert.ToDecimal(zhongliang.Value);
//cpkcmodel.zl = zl.SelectedItem.Value;
//cpkcmodel.tiji = tiji.Value;
cpkcmodel.dw = dw.SelectedItem.Value;
cpkcmodel.dj = Convert.ToDecimal(dj.Value);
cpkcmodel.jsr = jsr.Value;
cpkcmodel.bz = bz.Text;
if (tp.FileContent.Length > 0)
{
FileUpLoadzm();
cpkcmodel.tp = tpName;
}
else
{
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
{
int idz = Convert.ToInt32(id.Value);
nr_z_cpkc cpmodel = cpkcbll.GetModel(idz);
cpkcmodel.tp = cpmodel.tp;
}
}
/*if (wj.FileContent.Length > 0)
{
FileUpLoadwj();
cpkcmodel.wj = wjName;
}
else
{
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
{
int idz = Convert.ToInt32(id.Value);
nr_z_cpkc cpmodel = cpkcbll.GetModel(idz);
cpkcmodel.wj = cpmodel.wj;
}
}*/
//给日志模板赋值
rizhi.riqi = DateTime.Now;
rizhi.leixing = "产品档案";
}
#endregion
#region 获取项目需求
private void setxmxq(string cpid)
{
//加载前段项目
string qdgjstring = "
";
}
#endregion
#region 编辑加载水彩信息
/*private void getbjscyl()
{
//加载前段工价
string getgjsql = "select * from view_nr_z_cpkc_scyl where cpid='" + id.Value + "'";
string cltable = "";
scylxxdiv.InnerHtml = cltable;
}*/
#endregion
protected void bt_tj_Click(object sender, EventArgs e)
{
try
{
string caozuo = "添加";
getmd();
//接收成功参数值
int rtx = 0;
//判断uid是否存在值,有值为修改,无值为添加
if (id.Value != null && id.Value != "")
{
cpkcmodel.id = Convert.ToInt32(id.Value);
if (cpkcbll.Update(cpkcmodel))
{
rtx = Convert.ToInt32(id.Value);
caozuo = "修改";
}
}
else
{
cpkcmodel.cpbh = DBHlper.getbh("CP-", "nr_z_cpkc", "cpbh", 4);
cpbh.Text = cpkcmodel.cpbh;
rtx = cpkcbll.Add(cpkcmodel);
}
if (rtx > 0)
{
string gjscsl = "delete nr_z_cpkc_wlxq where cpid='" + rtx + "'";
DBHlper.excutecmd(gjscsl);
List cpwlds = new List();
cpwlds = DBHlper.ConvertJsonToEntityListEntity(wlxmhd.Value);
foreach (Maticsoft.Model.nr_z_cpkc_wlxq gjx in cpwlds)
{
gjx.cpid = rtx;
cpwlbll.Add(gjx);
}
gjscsl = "delete nr_z_cpkc_scyl where cpid='" + rtx + "'";
DBHlper.excutecmd(gjscsl);
List scylds = new List();
scylds = DBHlper.ConvertJsonToEntityListEntity(scylhd.Value);
foreach (Maticsoft.Model.nr_z_cpkc_scyl scyl in scylds)
{
scyl.cpid = rtx;
scylbll.Add(scyl);
}
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
rizhi.yonghuming = zh.zhanghao;
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + caozuo + "了产品档案,编号为:" + cpbh.Text.Trim();
rizhibll.Add(rizhi);
Response.Redirect("Product_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("");
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 = "CPTP" + DateTime.Now.ToString("yyyy-MM-dd") + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "-" + cpmc.Value + "." + tp.PostedFile.FileName.Substring(tp.PostedFile.FileName.LastIndexOf(".") + 1);
string path = "~/Client_Folder/" + tpName;
if (File.Exists(path))
{
Response.Write("");
return;
}
tp.PostedFile.SaveAs(Server.MapPath(path));
}
}
catch
{ Response.Write(""); }
}
string wjName = "";
/* public void FileUpLoadwj()
{
try
{
if (!wj.HasFile && !wj.HasFile)
{
Response.Write("");
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 ="CPWJ" + DateTime.Now.ToString("yyyy-MM-dd") + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "-" + cpmc.Value + "." + wj.PostedFile.FileName.Substring(wj.PostedFile.FileName.LastIndexOf(".") + 1);
string path = "~/Client_Folder/" + wjName;
if (File.Exists(path))
{
Response.Write("");
return;
}
wj.PostedFile.SaveAs(Server.MapPath(path));
}
}
catch
{ Response.Write(""); }
}
*/
}