CeramicProject/newyt/Module_data/Mould_Form.aspx.cs

229 lines
7.1 KiB
C#
Raw Permalink 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.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.BLL;
using System.Data;
using System.Data.SqlClient;
using Ajax;
public partial class Mould_Form : CommonPage
{
//所有外协名称
public string mjdamdmingtishi = "";
//创建一个共用的编码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_mjda mjdabll = new Maticsoft.BLL.nr_z_mjda();
//创建一个共用的模具档案
Maticsoft.Model.nr_z_mjda mjdamd = new Maticsoft.Model.nr_z_mjda();
//创建一个操作记录bll
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
//创建一个操作记录模板
Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi();
protected void Page_Load(object sender, EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(Mould_Form));
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)
{
pdquanxianbj(user.juese);
string uid = Request.QueryString["uid"].ToString();
id.Value = uid;
initdata(uid);
}
else
{
pdquanxian(user.juese);
//赋值默认值
bh.Text = "自动生成";
riqi.Value =DateTime.Now.ToString("yyyy-MM-dd");
}
}
}
#region
private void binddata()
{
DataSet hylx = bmlx.GetAllList();
DataRow[] dr = hylx.Tables[0].Select("leixing='模具类型'");
if (dr != null&& dr.Length>0)
{
DataSet hy = bm.GetList("zhongleiid='" + dr[0]["id"] + "'");
if (hy != null)
{
mjlx.DataSource = hy.Tables[0].DefaultView;
mjlx.DataValueField = "mingcheng";
mjlx.DataTextField = "mingcheng";
mjlx.DataBind();
}
}
dr = hylx.Tables[0].Select("leixing='单位'");
if (dr != null && dr.Length > 0)
{
DataSet ly = bm.GetList("zhongleiid='" + dr[0]["id"] + "'");
if (ly != null)
{
jjdw.DataSource = ly.Tables[0].DefaultView;
jjdw.DataValueField = "mingcheng";
jjdw.DataTextField = "mingcheng";
jjdw.DataBind();
}
}
}
#endregion
#region
private void initdata(string did)
{
int idz = Convert.ToInt32(did);
mjdamd = mjdabll.GetModel(idz);
if (mjdamd != null)
{
bh.Text = mjdamd.mjdm.ToString();
mingcheng.Text = mjdamd.mjmc.ToString();
mjlx.Text = mjdamd.mjzl.ToString();
pianshu.Text = mjdamd.ps.ToString();
sycs.Text = mjdamd.sycs.ToString();
chicun.Text = mjdamd.mjcc.ToString();
zhongliang.Text = mjdamd.zhongliang.ToString();
jjdw.Text = mjdamd.jjdw.ToString();
riqi.Value = mjdamd.riqi.ToString("yyyy-MM-dd");
beizhu.Text = mjdamd.beizhu.ToString();
}
}
#endregion
#region model对象
private void getmd()
{
mjdamd.mjdm = bh.Text;
mjdamd.mjmc = mingcheng.Text;
mjdamd.mjzl =mjlx.Text;
mjdamd.ps = Convert.ToInt32(pianshu.Text);
mjdamd.sycs = Convert.ToInt32(sycs.Text);
mjdamd.mjcc = chicun.Text;
mjdamd.zhongliang = Convert.ToDecimal(zhongliang.Text);
mjdamd.jjdw = jjdw.Text;
mjdamd.riqi = Convert.ToDateTime(riqi.Value);
mjdamd.beizhu = beizhu.Text;
//给日志模板赋值
rizhi.riqi = DateTime.Now;
rizhi.leixing = "模具档案";
}
#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_mjda", "添加") == 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_mjda", "编辑全部") == false)
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
protected void bt_tj_Click(object sender, EventArgs e)
{
try
{
string caozuo = "添加";
getmd();
//接收成功参数值
int rtx = 0;
//判断uid是否存在值有值为修改无值为添加
if (id.Value != null && id.Value != "")
{
mjdamd.id = Convert.ToInt32(id.Value);
if (mjdabll.Update(mjdamd))
{
rtx = Convert.ToInt32(id.Value);
caozuo = "修改";
}
}
else
{
mjdamd.mjdm = DBHlper.getbh("MJ-", "nr_z_mjda", "mjdm", 4);
bh.Text = mjdamd.mjdm;
rtx = mjdabll.Add(mjdamd);
}
if (rtx > 0)
{
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + caozuo + "了模具档案,档案编号为:" + bh.Text.Trim();
rizhi.yonghuming = zh.zhanghao;
rizhibll.Add(rizhi);
Response.Redirect("Mould_browse.aspx?uid=" + rtx, false);
}
else
{
Response.Redirect("../Common/error.aspx");
}
}
catch (Exception)
{
Response.Redirect("../Common/error.aspx");
}
}
//查询模具档案是否重复
[Ajax.AjaxMethod()]
public int serchmingcheng(string str)
{
string cmd = string.Format("select count(*) from nr_z_mjda where mingcheng='{0}'", str.Replace(" ", ""));
int count = DBHlper.getcount(cmd);
return count;
}
}