CeramicProject/newyt/Module_data/Supplier_Form.aspx.cs

308 lines
10 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 System.Data;
using Ajax;
public partial class Supplier_Form : CommonPage
{
public string gysmingtishi = "";
//创建一个共用的编码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_gyshang gysbll = new Maticsoft.BLL.nr_z_gyshang();
//创建一个共用的供应商联系人bll层
Maticsoft.BLL.nr_z_lianxiren_gys lxrbll = new Maticsoft.BLL.nr_z_lianxiren_gys();
//创建一个操作记录bll
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
//创建一个共用的供应商模板
Maticsoft.Model.nr_z_gyshang gys = new Maticsoft.Model.nr_z_gyshang();
//创建一个操作记录模板
Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi();
protected void Page_Load(object sender, EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(Supplier_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);
jialxr();
}
else
{
pdquanxian(user.juese);
if (Request.QueryString["fid"] != null && Request.QueryString["fid"].ToString().Length > 0)
{
string fid = Request.QueryString["fid"].ToString();
initdata(fid);
jialxr();
}
else
{
nowlxr();
}
//赋值默认值
bh.Text = "自动生成";
riqi.Value = DateTime.Now.ToString("yyyy-MM-dd");
}
//给供应商名称赋值
DataTable dtmingcheng = DBHlper.Execute("select mingcheng from nr_z_gyshang where zt='1'").Tables[0];
foreach (DataRow drt in dtmingcheng.Rows)
{
gysmingtishi += "'" + drt[0].ToString() + "'" + ',';
}
gysmingtishi= gysmingtishi.TrimEnd(',');
}
}
#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)
{
leixing.DataSource = hy.Tables[0].DefaultView;
leixing.DataValueField = "id";
leixing.DataTextField = "mingcheng";
leixing.DataBind();
}
}
}
#endregion
#region
private void initdata(string did)
{
int idz = Convert.ToInt32(did);
gys = gysbll.GetModel(idz);
if (gys != null)
{
bh.Text = gys.bianhao.ToString();
mingcheng.Text = gys.mingcheng.ToString();
youbian.Text = gys.youbian.ToString();
wangzhi.Text = gys.wangzhi.ToString();
kaihuhang.Text = gys.kaihuhang.ToString();
zhanghao.Text = gys.zhanghao.ToString();
shuihao.Text = gys.shuihao.ToString();
dianhua.Text = gys.dianhua.ToString();
chuanzhen.Text = gys.chuanzhen.ToString();
youjian.Text = gys.youjian.ToString();
leixing.Text = gys.leixing.ToString();
riqi.Value = DateTime.Parse(gys.riqi.ToString()).ToString("yyyy-MM-dd");
dizhi.Text = gys.dizhi.ToString();
beizhu.Text = gys.beizhu.ToString();
}
}
#endregion
#region model对象
private void getmd()
{
gys.bianhao = bh.Text;
gys.mingcheng = mingcheng.Text;
gys.youbian = youbian.Text;
gys.wangzhi = wangzhi.Text;
gys.kaihuhang = kaihuhang.Text;
gys.zhanghao = zhanghao.Text;
gys.shuihao = shuihao.Text;
gys.dianhua = dianhua.Text;
gys.chuanzhen = chuanzhen.Text;
gys.youjian = youjian.Text;
gys.leixing = leixing.Text;
if (riqi.Value == "")
{
gys.riqi = DateTime.Now;
}
else
{
gys.riqi = Convert.ToDateTime(riqi.Value);
}
gys.dizhi = dizhi.Text;
gys.beizhu = beizhu.Text;
//给日志模板赋值
rizhi.riqi = DateTime.Now;
rizhi.leixing = "供应商档案";
}
#endregion
#region
private void nowlxr()
{
DataSet lxrs = lxrbll.GetList("gys_bh='" + bh.Text + "'");
string pin = "<table width='100%' class='bule'> <tr class='tdlietou'><td colspan='4'><h4>联系人信息</h4></td></tr></table><table id='lxjia' class='bule'>";
pin += "<tr class='tbtilt'><td width='25px'> <img src='../Images_Folder/Button/tjltj.png' onclick='add_khlxr()' width='25px' height='25px' /></td>"
+ "<td ><span> 联系人</span></td><td ><span>职务</span></td><td><span>联系方式</span></td></tr>";
lianxiren.InnerHtml = pin + "</table>";
}
#endregion
#region
private void jialxr()
{
string pin = "<table width='100%' class='bule'> <tr class='tdlietou'><td colspan='4'><h4>联系人信息</h4></td></tr></table><table id='lxjia' class='bule'>"
+ "<tr class='tbtilt'><td width='25px'> <img src='../Images_Folder/Button/tjltj.png' onclick='add_khlxr()' width='25px' height='25px' /></td><td><span> 联系人</span></td><td ><span>职务</span></td><td><span>联系方式</span></td></tr>";
DataSet lxrs = lxrbll.GetList("gys_bh='" + bh.Text + "'");
if (lxrs != null && lxrs.Tables[0].Rows.Count > 0)
{
foreach (DataRow l in lxrs.Tables[0].Rows)
{
pin += "<tr><td width='25px'> <img src='../Images_Folder/Button/tjljh.png' onclick='jianhang(this)' width='25px' height='25px' /></td>"
+ "<td><input class='inpittxt' value='" + l["lxr_name"].ToString() + "' type='text'/></td>"
+ "<td><input class='inpittxt' value='" + l["zhiwei"].ToString() + "' type='text'/></td>"
+ "<td><input class='inpittxt' value='" + l["dianhua"].ToString() + "' type='text'/></td></tr>";
}
lianxiren.InnerHtml = pin + "</table>";
}
else
{
//如果没有联系人的存在就调用添加时的新建方法
nowlxr();
}
}
#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_gyshang", "添加") == 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_gyshang", "编辑") == 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 != "")
{
gys.id = Convert.ToInt32(id.Value);
if (gysbll.Update(gys))
{
rtx = Convert.ToInt32(id.Value);
caozuo = "修改";
}
}
else
{
gys.bianhao= DBHlper.getbh("GYS-", "nr_z_gyshang", "bianhao", 4);
bh.Text = gys.bianhao;
rtx = gysbll.Add(gys);
}
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);
lxrbll.DeleteListwhere("gys_bh='" + bh.Text + "'");
List<Maticsoft.Model.nr_z_lianxiren_gys> lxrmds = new List<Maticsoft.Model.nr_z_lianxiren_gys>();
lxrmds = DBHlper.ConvertJsonToEntityListEntity<Maticsoft.Model.nr_z_lianxiren_gys>(lxr.Value);
foreach (Maticsoft.Model.nr_z_lianxiren_gys k in lxrmds)
{
k.gys_bh = bh.Text;
lxrbll.Add(k);
}
Response.Redirect("Supplier_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_gyshang where mingcheng='{0}' and zt='1'", str.Replace(" ", ""));
int count = DBHlper.getcount(cmd);
return count;
}
}