You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/CRM/CRMClientVisitInfo.aspx.cs

443 lines
18 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using DSWeb.DataAccess;
using System.Data.SqlClient;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Web.Script.Serialization;
namespace DSWeb.CRM
{
public partial class CRMClientVisitInfo : System.Web.UI.Page
{
public string strHandleType = String.Empty;
public string sSQL = String.Empty;
public string gvid = String.Empty;
public string strrq = String.Empty;
RangeDA RangeDA = new RangeDA();
public string strUserID;//用户GID
public string strCompanyID;//公司GID
public string strShowName;//用户显示名
public string strDeptName;//部门名称
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString().Trim();
hdUserID.Value = strUserID.Trim();
}
else
{
Server.Transfer("~/Error/FriendError.aspx");
return;
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
//
if (!IsPostBack)
{
if (Request.QueryString["handle"] != null) //if (Request.QueryString["handle"] != null)
{
ViewState["strHandleType"] = Request.QueryString["handle"].ToString();//"edit";
strHandleType = ViewState["strHandleType"].ToString().Trim();
if (Request.QueryString["id"] != null)//if (Request.QueryString["id"] != null)
{
ViewState["GID"] = Request.QueryString["id"].ToString();//"topseaeusername129481962859531250";
this.hdGid.Value = ViewState["GID"].ToString().Trim();
}
if (Request.QueryString["isenabled"] != null)//if (Request.QueryString["id"] != null)
{
ViewState["isenabled"] = Request.QueryString["isenabled"].ToString();
this.hdEnabled.Value = ViewState["isenabled"].ToString().Trim();
}
if (Request.QueryString["LINKID"] != null)//if (Request.QueryString["id"] != null)
{
ViewState["LINKID"] = Request.QueryString["LINKID"].ToString();
this.hd_comboSHORTNAME.Value = Request.QueryString["LINKID"].ToString(); ;
T_ALL_DA T_ALL_DA = new T_ALL_DA();
this.hdLINKID.Value = T_ALL_DA.GetStrSQL("gid", "select GID from crm_info_client where SHORTNAME='" + this.hd_comboSHORTNAME.Value.Trim() + "'");
this.hdISLINKID.Value = this.hdLINKID.Value.Trim() == "" ? "" : "1";
}
//
getddlDataSet();
//
switch (strHandleType)
{
case "add"://新增
getnull();
break;
case "edit"://录入
getnotnull();
//权限可视范围
string strV = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modCRMClientVisitList");
string strO = RangeDA.GetOPERATERANGE(strUserID.Trim(), "modCRMClientVisitList");
string alt = "";
if (strV.Trim().Equals("4"))//全部
{
ibAdd.Enabled = true;
}
else if (strV.Trim().Equals("1"))//分公司
{
if (strO.Trim().Equals("1"))//公司
{
alt = RangeDA.GetCRMClientVisitListCompany(strUserID.Trim(), ViewState["GID"].ToString().Trim());
if (alt == "")
{
getEnabled();
}
}
else if (strO.Trim().Equals("3"))//个人
{
alt = RangeDA.GetCRMClientVisitListPerson(strUserID.Trim(), ViewState["GID"].ToString().Trim());
if (alt == "")
{
getEnabled();
}
}
}
else if (strV.Trim().Equals("3"))
{
if (strO.Trim().Equals("3"))//个人
{
alt = RangeDA.GetCRMClientVisitListPerson(strUserID.Trim(), ViewState["GID"].ToString().Trim());
if (alt == "")
{
getEnabled();
}
}
else if (strO.Trim().Equals("4"))//无
{
getEnabled();
}
}
//
break;
}
//
if (this.hdEnabled.Value.Trim() == "false") {
getEnabled();
}
}
else
{
getnull();
getEnabled();
}
}
//加载下拉框
Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>initComboSHORTNAME();initComboCONTACTNAME();initComboSALE();</script>");
}
protected void getddlDataSet()
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
ddlVISITWAY.Items.Clear();
DataSet ds = T_ALL_DA.GetAllSQL("select KEYVALUE from crm_key_code where KEYTYPE='客户拜访方式' and KEYVALUE<>'' and KEYVALUE is not null");
if (ds != null)
{
ddlVISITWAY.DataSource = ds.Tables[0];
ddlVISITWAY.DataTextField = "KEYVALUE";
ddlVISITWAY.DataValueField = "KEYVALUE";
ddlVISITWAY.DataBind();
}
ddlVISITWAY.Items.Add("");
//
ddlNEXTACTION.Items.Clear();
ds = T_ALL_DA.GetAllSQL("select KEYVALUE from crm_key_code where KEYTYPE='下次客户拜访行动' and KEYVALUE<>'' and KEYVALUE is not null");
if (ds != null)
{
ddlNEXTACTION.DataSource = ds.Tables[0];
ddlNEXTACTION.DataTextField = "KEYVALUE";
ddlNEXTACTION.DataValueField = "KEYVALUE";
ddlNEXTACTION.DataBind();
}
ddlNEXTACTION.Items.Add("");
//
strrq = T_ALL_DA.GetStrSQL("rq", "select convert(char(10),getdate(),20) as rq");
tbVISITDATE.Text = strrq;
tbNEXTDATE.Text = strrq;
this.hd_comboSHORTNAME.Value = T_ALL_DA.GetStrSQL("SHORTNAME", "select top 1 SHORTNAME from crm_info_client where gid='" + ViewState["LINKID"].ToString().Trim() + "'");
}
protected void getnull()
{
ViewState["strHandleType"] = "add";
ViewState["GID"] = "";
this.hdGid.Value = ViewState["GID"].ToString().Trim();
//this.hd_comboSHORTNAME.Value = "";
this.hd_comboCONTACTNAME.Value = "";
this.hd_comboSALE.Value = strShowName;
ddlVISITWAY.Text = "";
//tbVISITDATE.Text = "";
tbVISITCONTENT.Text = "";
ddlNEXTACTION.Text = "";
//tbNEXTDATE.Text = "";
tbNEXTCONTENT.Text = "";
}
protected void getnotnull()
{
ViewState["strHandleType"] = "edit";
this.hdGid.Value = ViewState["GID"].ToString().Trim();
CRMClientVisitDA CRMClientVisitDA = new CRMClientVisitDA();
CRMClientVisitEntity model = new CRMClientVisitEntity();
model = CRMClientVisitDA.GetModel(ViewState["GID"].ToString().Trim());
if (model != null)
{
this.hd_comboSHORTNAME.Value = model.SHORTNAME.ToString().Trim();
T_ALL_DA T_ALL_DA = new T_ALL_DA();
this.hdLINKID.Value = T_ALL_DA.GetStrSQL("gid", "select GID from crm_info_client where SHORTNAME='" + this.hd_comboSHORTNAME.Value.Trim() + "'");
//
this.hd_comboCONTACTNAME.Value = model.CONTACTNAME.ToString().Trim();
this.hd_comboSALE.Value = model.SALE.ToString().Trim();
ddlVISITWAY.Text = model.VISITWAY.ToString().Trim();
tbVISITDATE.Text = model.VISITDATE.ToString("yyyy-MM-dd").Trim();
tbVISITCONTENT.Text = model.VISITCONTENT.ToString().Trim();
ddlNEXTACTION.Text = model.NEXTACTION.ToString().Trim();
tbNEXTDATE.Text = model.NEXTDATE.ToString("yyyy-MM-dd").Trim();
tbNEXTCONTENT.Text = model.NEXTCONTENT.ToString().Trim();
}
else
{
getnull();
}
}
protected void getEnabled()
{
ibAdd.Enabled = false;
ibEnter.Disabled = true;
ibDel.Enabled = false;
this.hdEnabled.Value = "false";
//
//this.hd_comboSHORTNAME.Value = "";
//this.hd_comboCONTACTNAME.Value = "";
//this.hd_comboSALE.Value = "";
ddlVISITWAY.Enabled = false;
tbVISITDATE.Enabled = false;
tbVISITCONTENT.Enabled = false;
ddlNEXTACTION.Enabled = false;
tbNEXTDATE.Enabled = false;
tbNEXTCONTENT.Enabled = false;
}
protected void getEnabledTrue()
{
ibAdd.Enabled = true;
ibEnter.Disabled = false;
ibDel.Enabled = true;
this.hdEnabled.Value = "true";
//
//this.hd_comboSHORTNAME.Value = "";
//this.hd_comboCONTACTNAME.Value = "";
//this.hd_comboSALE.Value = "";
ddlVISITWAY.Enabled = true;
tbVISITDATE.Enabled = true;
tbVISITCONTENT.Enabled = true;
ddlNEXTACTION.Enabled = true;
tbNEXTDATE.Enabled = true;
tbNEXTCONTENT.Enabled = true;
}
protected String getBSNO()
{
string strBSNO = Guid.NewGuid().ToString();
strBSNO = strBSNO.Replace("-", "");
strBSNO = "Vis" + strBSNO;
return strBSNO;
}
protected bool getAdd()
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
CRMClientVisitDA CRMClientVisitDA = new CRMClientVisitDA();
CRMClientVisitEntity model = new CRMClientVisitEntity();
ViewState["GID"] = getBSNO();
this.hdGid.Value = ViewState["GID"].ToString().Trim();
model.GID = ViewState["GID"].ToString().Trim();
model.CLIENTGID = ViewState["LINKID"].ToString().Trim();
if (ViewState["LINKID"].ToString().Trim() == "")
{
model.CLIENTGID = T_ALL_DA.GetStrSQL("gid", "select gid from crm_info_client where SHORTNAME='" + this.hd_comboSHORTNAME.Value.Trim() + "'");
}
model.SHORTNAME = this.hd_comboSHORTNAME.Value.Trim();
model.CONTACTNAME = this.hd_comboCONTACTNAME.Value.Trim();
model.SALE = this.hd_comboSALE.Value.Trim();
model.VISITWAY = ddlVISITWAY.Text.Trim();
model.VISITCONTENT = tbVISITCONTENT.Text.Trim();
//
if (tbVISITDATE.Text.Trim() == "")
{
tbVISITDATE.Text = strrq;
}
model.VISITDATE = DateTime.Parse(tbVISITDATE.Text.Trim());
//
model.NEXTACTION = ddlNEXTACTION.Text.Trim();
model.NEXTCONTENT = tbNEXTCONTENT.Text.Trim();
//
if (tbNEXTDATE.Text.Trim() == "")
{
tbNEXTDATE.Text = strrq;
}
model.NEXTDATE = DateTime.Parse(tbNEXTDATE.Text.Trim());
//
model.CREATEUSER = strUserID;
model.MODIFIEDUSER = strUserID;
model.LOCKUSER = strUserID;
int iResult = CRMClientVisitDA.Add(model);
if (iResult>0)
{
ViewState["strHandleType"] = "edit";
return true;
}
else
{
return false;
}
}
protected bool getEdit()
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
CRMClientVisitDA CRMClientVisitDA = new CRMClientVisitDA();
CRMClientVisitEntity model = new CRMClientVisitEntity();
this.hdGid.Value = ViewState["GID"].ToString().Trim();
model.GID = ViewState["GID"].ToString().Trim();
model.CLIENTGID = ViewState["LINKID"].ToString().Trim();
if (ViewState["LINKID"].ToString().Trim() == "")
{
model.CLIENTGID = T_ALL_DA.GetStrSQL("gid", "select gid from crm_info_client where SHORTNAME='" + this.hd_comboSHORTNAME.Value.Trim() + "'");
}
model.SHORTNAME = this.hd_comboSHORTNAME.Value.Trim();
model.CONTACTNAME = this.hd_comboCONTACTNAME.Value.Trim();
model.SALE = this.hd_comboSALE.Value.Trim();
model.VISITWAY = ddlVISITWAY.Text.Trim();
model.VISITCONTENT = tbVISITCONTENT.Text.Trim();
//
if (tbVISITDATE.Text.Trim() == "")
{
tbVISITDATE.Text = strrq;
}
model.VISITDATE = DateTime.Parse(tbVISITDATE.Text.Trim());
//
model.NEXTACTION = ddlNEXTACTION.Text.Trim();
model.NEXTCONTENT = tbNEXTCONTENT.Text.Trim();
//
if (tbNEXTDATE.Text.Trim() == "")
{
tbNEXTDATE.Text = strrq;
}
model.NEXTDATE = DateTime.Parse(tbNEXTDATE.Text.Trim());
//
model.CREATEUSER = strUserID;
model.MODIFIEDUSER = strUserID;
model.LOCKUSER = strUserID;
int iResult = CRMClientVisitDA.Update(model);
if (iResult > 0)
{
return true;
}
else
{
return false;
}
}
protected void btnEnter_Click(object sender, EventArgs e)
{
if (DateTime.Parse(tbVISITDATE.Text.Trim()) > DateTime.Parse(tbNEXTDATE.Text.Trim()))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('下次拜访时间不能小于本次拜访时间!');</script>");
return;
}
//
bool bl = false;
strHandleType = ViewState["strHandleType"].ToString();
if (strHandleType.Equals("add"))//新增
{
bl = getAdd();
}
else if (strHandleType.Equals("edit"))//录入
{
bl = getEdit();
}
ibDel.Enabled = true;
ibAdd.Enabled = true;
if (bl)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>alert('成功提交!');</script>");
return;
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('出错,请重新填写!');</script>");
return;
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
ViewState["strHandleType"] = "add";
//
getnull();
//
ibDel.Enabled = false;
ibEnter.Disabled = false;
ibAdd.Enabled = true;
}
protected void btnDel_Click(object sender, EventArgs e)
{
CRMClientVisitDA CRMClientVisitDA = new CRMClientVisitDA();
int iResult = CRMClientVisitDA.Delete(ViewState["GID"].ToString().Trim());
if (iResult > 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('删除成功!');window.opener.location.reload();</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key5", "<script>alert('删除失败!');</script>");
return;
}
//
ViewState["strHandleType"] = "edit";
T_ALL_DA T_ALL_DA = new T_ALL_DA();
ViewState["GID"] = T_ALL_DA.GetStrSQL("gid", "select top 1 gid from crm_info_client_visit where CLIENTGID='" + ViewState["LINKID"].ToString().Trim() + "'");
getnotnull();
//
//getnull();
//ibDel.Enabled = false;
//ibAdd.Enabled = false;
return;
}
public bool IsNumeric(string s)
{
bool bReturn = true;
try
{
int inum = int.Parse(s);
}
catch
{
bReturn = false;
}
return bReturn;
}
}
}