498 lines
17 KiB
C#
498 lines
17 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;
|
||
using System.IO;
|
||
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);
|
||
}
|
||
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");
|
||
}
|
||
//给客户名称赋值
|
||
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;
|
||
khjc.Text = kehu.khjc;
|
||
mingcheng.Text = kehu.mingcheng;
|
||
//mingchengyw.Text = kehu.mingchengyw;
|
||
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;
|
||
//dizhiyw.Text = kehu.dizhiyw;
|
||
beizhu.Text = kehu.beizhu;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 获取页面参数赋值model对象
|
||
private void getmd()
|
||
{
|
||
kehu.bianhao = bh.Text;
|
||
kehu.khjc = khjc.Text;
|
||
kehu.mingcheng = mingcheng.Text;
|
||
//kehu.mingchengyw = mingchengyw.Text;
|
||
kehu.diqu = diqu.Text;
|
||
kehu.dizhi = dizhi.Text;
|
||
//kehu.dizhiyw = dizhiyw.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;
|
||
//if (zhaopian.FileContent.Length > 0)
|
||
//{
|
||
// FileUpLoazp();
|
||
//kehu.zhaopian = tpName;
|
||
// }
|
||
else
|
||
{
|
||
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
|
||
{
|
||
int idz = Convert.ToInt32(id.Value);
|
||
Maticsoft.Model.nr_z_kehu kmdel = kehubll.GetModel(idz);
|
||
kehu.zhaopian = kmdel.zhaopian;
|
||
}
|
||
|
||
}
|
||
|
||
//if (mingpian.FileContent.Length > 0)
|
||
//{
|
||
//FileUpLoamingpian();
|
||
//kehu.mingpian = mpName;
|
||
//}
|
||
|
||
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
|
||
{
|
||
int idz = Convert.ToInt32(id.Value);
|
||
Maticsoft.Model.nr_z_kehu kmdel = kehubll.GetModel(idz);
|
||
kehu.mingpian = kmdel.mingpian;
|
||
}
|
||
|
||
|
||
//给日志模板赋值
|
||
rizhi.riqi=DateTime.Now;
|
||
rizhi.leixing = "客户档案";
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 添加时加载时添加联系人
|
||
private void nowlxr()
|
||
{
|
||
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><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><td><span>备注</span></td></tr>";
|
||
DataSet lxrs = lxrbll.GetList("kh_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["lianxiren"].ToString() + "' type='text'/></td>"
|
||
+ " <td ><input class='inpittxt' value='" + l["zhiwei"].ToString() + "' type='text'/></td>"
|
||
+ " <td ><input class='inpittxt' value='" + l["shouji"].ToString() + "' type='text'/></td>"
|
||
+ " <td ><input class='inpittxt' value='" + l["beizhu"].ToString() + "' type='text'/></td></tr>";
|
||
|
||
}
|
||
}
|
||
lianxiren.InnerHtml = pin + "</table>";
|
||
}
|
||
#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("Customer_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_kehu where mingcheng='{0}' and zt='1'", str.Replace(" ", ""));
|
||
int count= DBHlper.getcount(cmd);
|
||
return count;
|
||
}
|
||
|
||
string tpName = "";
|
||
/*public void FileUpLoazp()
|
||
{
|
||
try
|
||
{
|
||
if (!zhaopian.HasFile && !zhaopian.HasFile)
|
||
{
|
||
Response.Write("<script>alert('请选择要上传的文件')</script>");
|
||
return;
|
||
}
|
||
if (!zhaopian.HasFile) { }
|
||
else
|
||
{
|
||
string directoyPath = System.Web.HttpContext.Current.Server.MapPath("~/Client_Folder/");
|
||
if (!System.IO.Directory.Exists(directoyPath))
|
||
{
|
||
System.IO.Directory.CreateDirectory(directoyPath);
|
||
}
|
||
tpName = "KHZP" + DateTime.Now.ToString("yyyy-MM-dd") + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "-" + mingcheng.Text + "." +zhaopian.PostedFile.FileName.Substring(zhaopian.PostedFile.FileName.LastIndexOf(".") + 1);
|
||
string path = "~/Client_Folder/" + tpName;
|
||
if (File.Exists(path))
|
||
{
|
||
Response.Write("<script language='javascript'>alert('服务器上已经有了你正在上传的文件:" + tpName + "!');</script>");
|
||
return;
|
||
}
|
||
zhaopian.PostedFile.SaveAs(Server.MapPath(path));
|
||
|
||
}
|
||
}
|
||
catch
|
||
{ Response.Write("<script>alert('上传失败!')</script>"); }
|
||
}
|
||
|
||
string mpName = "";
|
||
public void FileUpLoamingpian()
|
||
{
|
||
|
||
try
|
||
{
|
||
if (!mingpian.HasFile && !mingpian.HasFile)
|
||
{
|
||
Response.Write("<script>alert('请选择要上传的文件')</script>");
|
||
return;
|
||
}
|
||
if (!mingpian.HasFile) { }
|
||
else
|
||
{
|
||
string directoyPath = System.Web.HttpContext.Current.Server.MapPath("~/Client_Folder/");
|
||
if (!System.IO.Directory.Exists(directoyPath))
|
||
{
|
||
System.IO.Directory.CreateDirectory(directoyPath);
|
||
}
|
||
mpName = "KHWJ" + DateTime.Now.ToString("yyyy-MM-dd") + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second+"-" +mingcheng.Text+ "." + mingpian.PostedFile.FileName.Substring(mingpian.PostedFile.FileName.LastIndexOf(".") + 1);
|
||
string path = "~/Client_Folder/" + mpName;
|
||
if (File.Exists(path))
|
||
{
|
||
Response.Write("<script language='javascript'>alert('服务器上已经有了你正在上传的文件:" + mpName + "!');</script>");
|
||
return;
|
||
}
|
||
mingpian.PostedFile.SaveAs(Server.MapPath(path));
|
||
|
||
}
|
||
}
|
||
catch
|
||
{ Response.Write("<script>alert('上传失败!')</script>"); }
|
||
}*/
|
||
} |