422 lines
15 KiB
C#
422 lines
15 KiB
C#
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 Customer_Form : CommonPage
|
||
{
|
||
//所有客户名称
|
||
public string kehumingtishi="";
|
||
//创建一个共用的编码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_kehu kehubll = new Maticsoft.BLL.nr_z_kehu();
|
||
//创建一个共用的客户联系人bll层
|
||
Maticsoft.BLL.nr_z_lianxiren_kh lxrbll = new Maticsoft.BLL.nr_z_lianxiren_kh();
|
||
//创建一个操作记录bll
|
||
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
|
||
//创建一个共用的客户模板
|
||
Maticsoft.Model.nr_z_kehu kehu = new Maticsoft.Model.nr_z_kehu();
|
||
//创建一个操作记录模板
|
||
Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi();
|
||
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
Utility.RegisterTypeForAjax(typeof(Customer_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)
|
||
{
|
||
|
||
string uid=Request.QueryString["uid"].ToString();
|
||
id.Value = uid;
|
||
initdata(uid);
|
||
jialxr();
|
||
pdquanxianbj(user.juese);
|
||
//如果修改就拼出修改的导航
|
||
div_daohang.InnerHtml = "当前位置:<a href='kehu_list.aspx'>选择客户</a>>修改客户";
|
||
}
|
||
else
|
||
{
|
||
|
||
if (Request.QueryString["fid"] != null && Request.QueryString["fid"].ToString().Length > 0)
|
||
{
|
||
string fid = Request.QueryString["fid"].ToString();
|
||
initdata(fid);
|
||
jialxr();
|
||
//如果是复制的就重新赋值等;
|
||
|
||
}
|
||
else
|
||
{
|
||
nowlxr();
|
||
ywy.Text = ((Maticsoft.Model.nr_z_yhzh)Session["user"]).zhanghao;
|
||
}
|
||
pdquanxian(user.juese);
|
||
//添加默认值
|
||
bh.Text = "自动生成";
|
||
riqi.Value = DateTime.Now.ToString("yyyy-MM-dd");
|
||
//添加就拼出添加的导航
|
||
div_daohang.InnerHtml = "当前位置:<a href='kehu_list.aspx'>选择客户</a>>添加客户";
|
||
|
||
}
|
||
//给客户名称赋值
|
||
DataTable dtmingcheng=DBHlper.Execute("select mingcheng from nr_z_kehu where zt='1'").Tables[0];
|
||
foreach (DataRow drt in dtmingcheng.Rows)
|
||
{
|
||
kehumingtishi +="'"+ drt[0].ToString()+"'"+',';
|
||
}
|
||
kehumingtishi= kehumingtishi.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)
|
||
{
|
||
|
||
hangye.DataSource = hy.Tables[0].DefaultView;
|
||
hangye.DataValueField = "id";
|
||
hangye.DataTextField = "mingcheng";
|
||
hangye.DataBind();
|
||
}
|
||
}
|
||
|
||
dr = hylx.Tables[0].Select("leixing='客户性质'");
|
||
if (dr != null&& dr.Length>0)
|
||
{
|
||
DataSet xz = bm.GetList("zhongleiid='" + dr[0]["id"] + "'");
|
||
if (xz != null)
|
||
{
|
||
|
||
xingzhi.DataSource = xz.Tables[0].DefaultView;
|
||
xingzhi.DataValueField = "id";
|
||
xingzhi.DataTextField = "mingcheng";
|
||
xingzhi.DataBind();
|
||
}
|
||
}
|
||
|
||
dr = hylx.Tables[0].Select("leixing='客户来源'");
|
||
if (dr != null&& dr.Length>0)
|
||
{
|
||
DataSet ly = bm.GetList("zhongleiid='" + dr[0]["id"] + "'");
|
||
if (ly != null)
|
||
{
|
||
|
||
laiyuan.DataSource = ly.Tables[0].DefaultView;
|
||
laiyuan.DataValueField = "id";
|
||
laiyuan.DataTextField = "mingcheng";
|
||
laiyuan.DataBind();
|
||
}
|
||
}
|
||
|
||
|
||
dr = hylx.Tables[0].Select("leixing='客户类型'");
|
||
if (dr != null&& dr.Length>0)
|
||
{
|
||
DataSet lx = bm.GetList("zhongleiid='" + dr[0]["id"] + "'");
|
||
if (lx != null)
|
||
{
|
||
|
||
leixing.DataSource = lx.Tables[0].DefaultView;
|
||
leixing.DataValueField = "id";
|
||
leixing.DataTextField = "mingcheng";
|
||
leixing.DataBind();
|
||
}
|
||
}
|
||
|
||
dr = hylx.Tables[0].Select("leixing='客户地区'");
|
||
if(dr!=null)
|
||
{
|
||
DataSet dq = bm.GetList("zhongleiid='" + dr[0]["id"] + "'");
|
||
if (dq != null)
|
||
{
|
||
|
||
diqu.DataSource = dq.Tables[0].DefaultView;
|
||
diqu.DataValueField = "id";
|
||
diqu.DataTextField = "mingcheng";
|
||
diqu.DataBind();
|
||
}
|
||
}
|
||
|
||
dr = hylx.Tables[0].Select("leixing='客户规模'");
|
||
if (dr != null&& dr.Length>0)
|
||
{
|
||
DataSet gm = bm.GetList("zhongleiid='" + dr[0]["id"] + "'");
|
||
if (gm != null)
|
||
{
|
||
|
||
guimo.DataSource = gm.Tables[0].DefaultView;
|
||
guimo.DataValueField = "id";
|
||
guimo.DataTextField = "mingcheng";
|
||
guimo.DataBind();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 修改时获取真正数据值
|
||
private void initdata(string did)
|
||
{
|
||
int idz = Convert.ToInt32(did);
|
||
kehu = kehubll.GetModel(idz);
|
||
if (kehu != null)
|
||
{
|
||
bh.Text = kehu.bianhao;
|
||
mingcheng.Text = kehu.mingcheng;
|
||
youbian.Text = kehu.youbian;
|
||
wangzhi.Text = kehu.wangzhi;
|
||
kaihuhang.Text = kehu.kaihuhang;
|
||
zhanghao.Text = kehu.zhanghao;
|
||
shuihao.Text = kehu.shuihao;
|
||
dianhua.Text = kehu.dianhua;
|
||
chuanzhen.Text = kehu.chuanzhen;
|
||
youjian.Text = kehu.youxiang;
|
||
xyed.Value = kehu.shouxianedu.ToString();
|
||
riqi.Value = DateTime.Parse(kehu.riqi.ToString()).ToString("yyyy-MM-dd");
|
||
hangye.Text = kehu.hangye;
|
||
xingzhi.Text = kehu.xingzhi;
|
||
laiyuan.Text = kehu.laiyuan;
|
||
leixing.Text = kehu.leixing;
|
||
diqu.Text = kehu.diqu;
|
||
guimo.Text = kehu.guimo;
|
||
ywy.Text = kehu.yewuyuan;
|
||
dizhi.Text = kehu.dizhi;
|
||
beizhu.Text = kehu.beizhu;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 获取页面参数赋值model对象
|
||
private void getmd()
|
||
{
|
||
kehu.bianhao = bh.Text;
|
||
kehu.mingcheng = mingcheng.Text;
|
||
kehu.diqu = diqu.Text;
|
||
kehu.dizhi = dizhi.Text;
|
||
kehu.hangye = hangye.Text;
|
||
kehu.guimo = guimo.Text;
|
||
kehu.xingzhi = xingzhi.Text;
|
||
kehu.youbian = youbian.Text;
|
||
kehu.wangzhi = wangzhi.Text;
|
||
kehu.kaihuhang = kaihuhang.Text;
|
||
kehu.zhanghao = zhanghao.Text;
|
||
kehu.shuihao = shuihao.Text;
|
||
kehu.chuanzhen = chuanzhen.Text;
|
||
kehu.laiyuan = laiyuan.Text;
|
||
kehu.leixing = leixing.Text;
|
||
if (riqi.Value == "")
|
||
{
|
||
kehu.riqi = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
kehu.riqi = Convert.ToDateTime(riqi.Value);
|
||
}
|
||
kehu.yewuyuan = ywy.Text;
|
||
kehu.dianhua = dianhua.Text;
|
||
kehu.youxiang = youjian.Text;
|
||
if (xyed.Value != "")
|
||
{
|
||
kehu.shouxianedu = Convert.ToDecimal(xyed.Value);
|
||
}
|
||
kehu.beizhu = beizhu.Text;
|
||
//给日志模板赋值
|
||
rizhi.riqi=DateTime.Now;
|
||
rizhi.leixing = "客户档案";
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 添加时加载时添加联系人
|
||
private void nowlxr()
|
||
{
|
||
DataSet lxrs = lxrbll.GetList("kh_bh='" + bh.Text + "'");
|
||
string pin = "<table width='100%' id='lxjia' border='1' class='bule'>";
|
||
pin += "<tr><td width='25px'> <img src='../Images_Folder/Button/tjltj.png' onclick='add_khlxr()' width='25px' height='25px' /></td>"
|
||
+ "<td width='15%' style='text-align:center'> 联系人</td><td width='20%'><input class='inpittxt' type='text'/></td>"
|
||
+ "<td width='15%' style='text-align:center' >职务</td><td width='20%'><input class='inpittxt' type='text'/></td>"
|
||
+ "<td width='15%' style='text-align:center'>手机</td><td width='20%'><input class='inpittxt' type='text'/></td></tr>";
|
||
lianxiren.InnerHtml = pin + "</table>";
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 编辑时加载联系人数据
|
||
private void jialxr()
|
||
{
|
||
DataSet lxrs = lxrbll.GetList("kh_bh='" + bh.Text + "'");
|
||
|
||
int cs = 1;
|
||
if (lxrs != null && lxrs.Tables[0].Rows.Count > 0)
|
||
{
|
||
string pin = "<table width='100%' id='lxjia' border='1' class='bule'>";
|
||
foreach (DataRow l in lxrs.Tables[0].Rows)
|
||
{
|
||
if (cs == 1)
|
||
{
|
||
pin += "<tr><td width='25px'> <img src='../Images_Folder/Button/tjltj.png' onclick='add_khlxr()' width='25px' height='25px' /></td>"
|
||
+ "<td width='15%' style='text-align:center' >联系人</td><td width='20%'><input class='inpittxt' value='" + l["lianxiren"].ToString() + "' type='text'/></td>"
|
||
+ "<td width='15%' style='text-align:center' >职务</td><td width='20%'><input class='inpittxt' value='" + l["zhiwei"].ToString() + "' type='text'/></td>"
|
||
+ "<td width='15%' style='text-align:center' >手机</td><td width='20%'><input class='inpittxt' value='" + l["shouji"].ToString() + "' type='text'/></td></tr>";
|
||
}
|
||
else
|
||
{
|
||
pin += "<tr><td width='25px'> <img src='../Images_Folder/Button/tjljh.png' onclick='jianhang(this)' width='25px' height='25px' /></td>"
|
||
+ "<td width='15%' style='text-align:center' > 联系人</td><td width='20%'><input class='inpittxt' value='" + l["lianxiren"].ToString() + "' type='text'/></td>"
|
||
+ "<td width='15%' style='text-align:center' >职务</td><td width='20%'><input class='inpittxt' value='" + l["zhiwei"].ToString() + "' type='text'/></td>"
|
||
+ "<td width='15%' style='text-align:center' >手机</td><td width='20%'><input class='inpittxt' value='" + l["shouji"].ToString() + "' type='text'/></td></tr>";
|
||
}
|
||
cs += 1;
|
||
}
|
||
|
||
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_kehu", "添加") == 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_kehu", "编辑个人") == false&&DBHlper.GetPermission(juese, "客户档案", "nr_z_kehu", "编辑全部") == false)
|
||
{
|
||
Response.Redirect("../Common/nopower.htm");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
#endregion
|
||
protected void bt_tj_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if( mingcheng.Text==""||mingcheng.Text==null)
|
||
{
|
||
z_error.Text = "客户名称不能为空!";
|
||
return;
|
||
}
|
||
string caozuo = "添加";
|
||
getmd();
|
||
//接收成功参数值
|
||
int rtx=0;
|
||
//判断uid是否存在值,有值为修改,无值为添加
|
||
if (id.Value != null && id.Value != "")
|
||
{
|
||
kehu.id = Convert.ToInt32(id.Value);
|
||
if (kehubll.Update(kehu))
|
||
{
|
||
rtx = Convert.ToInt32(id.Value);
|
||
caozuo = "修改";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
|
||
kehu.bianhao = DBHlper.getbh("KH-", "nr_z_kehu", "bianhao", 4);
|
||
bh.Text = kehu.bianhao;
|
||
rtx = kehubll.Add(kehu);
|
||
|
||
}
|
||
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+ "了客户档案,档案编号为:" + bh.Text.Trim();
|
||
rizhibll.Add(rizhi);
|
||
|
||
lxrbll.DeleteListwhere("kh_bh='" + bh.Text + "'");
|
||
List<Maticsoft.Model.nr_z_lianxiren_kh> lxrmds = new List<Maticsoft.Model.nr_z_lianxiren_kh>();
|
||
lxrmds = DBHlper.ConvertJsonToEntityListEntity<Maticsoft.Model.nr_z_lianxiren_kh>(lxr.Value);
|
||
foreach (Maticsoft.Model.nr_z_lianxiren_kh k in lxrmds)
|
||
{
|
||
k.kh_bh = bh.Text;
|
||
lxrbll.Add(k);
|
||
}
|
||
|
||
Response.Redirect("kehu_list.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_kehu where mingcheng='{0}' and zt='1'", str.Replace(" ", ""));
|
||
int count= DBHlper.getcount(cmd);
|
||
return count;
|
||
}
|
||
|
||
|
||
} |