码迷,mamicode.com
首页 > 其他好文 > 详细

ERP渠道管理添加验证和查询(二)

时间:2017-05-14 21:41:05      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:address   arch   creat   rem   result   GridView   opd   电话   element   

添加联系人的后台代码:

 protected void btnSubmit_Click(object sender, EventArgs e)
        {
            BioErpCrmManageChannel channel = new BioErpCrmManageChannel()
            {
                ChannelName = this.txtChannelName.Text,
                AccountName = this.txtBank.Text,
                Accounts = this.txtAccounts.Text,
                Address = this.txtAddress.Text,
                Areal = this.ddlArea.SelectedItem.Text,
                ChannelLevel = this.ddlLevel.Text,
                ChannelSize = this.ddlChannelSize.SelectedItem.Text,
                ChannelType = this.ddlType.Text,
                City = this.ddlCity.SelectedItem.Text,
                Province = this.ddlProvince.SelectedItem.Text,
                CoreOperttion = this.txtCoreOperttion.Text,
                Tel1 = this.txtTel1.Text,
                Tel2 = this.txtTel2.Text,
                TaxNumber = this.txtTaxNumber.Text,
                CoSummary = this.txtCoSummary.Text,
                Email = this.txtEmail.Text,
                Fax = this.txtFax.Text,
                NetAddress = this.txtNextTime.Text,
                Vocation = this.ddlVocation.SelectedItem.Text,
                SuperiorChannel = this.txtSuperChannelID.Text == "" ? 0 : int.Parse(this.txtSuperChannelID.Text),
                UserID = int.Parse(this.txtUserName.Text),
                NextContactTime = Convert.ToDateTime(this.txtNextTime.Text),
                Status = this.ddlState.SelectedItem.Text,
                CreditStanding = this.txtCredit.Text,
                EnrollTime = Convert.ToDateTime(this.txtRegisterTime.Text)
            };
            BioErpCrmManageChannelBLL channelbll = new BioErpCrmManageChannelBLL();
            BioErpCrmChannelLinkManBLL linkmanbll = new BioErpCrmChannelLinkManBLL();
            int channelid = channelbll.BioErpCrmManageChannelAdd(channel);
            //渠道基本信息添加成功,才能添加联系人基本信息
            if (channelid != 0)
            {
                string linkman = Request["txtLinkMan1"].ToString();
                string ddlSex = Request["ddlSex1"].ToString();
                string Birthday = Request["txtBirthday1"].ToString();
                string MainLink = Request["ddlMainLink1"].ToString();
                string OfficePhone = Request["txtOfficePhone"].ToString();
                string Mobile = Request["txtOfficePhone"].ToString();
                string Email = Request["txtEmail11"].ToString();
                string Address = Request["txtAddress1"].ToString();
                string QQ = Request["txtQQ1"].ToString();
                string Remark = Request["txtRemark1"].ToString();

                string[] linkmans = linkman.Split(‘,‘);
                string[] ddlSexs = ddlSex.Split(‘,‘);
                string[] Birthdays = Birthday.Split(‘,‘);
                string[] MainLinks = MainLink.Split(‘,‘);
                string[] OfficePhones = OfficePhone.Split(‘,‘);
                string[] Mobiles = Mobile.Split(‘,‘);
                string[] Emails = Email.Split(‘,‘);
                string[] Addresses = Address.Split(‘,‘);
                string[] QQs = QQ.Split(‘,‘);
                string[] Remarks = Remark.Split(‘,‘);

                BioErpCrmChannelLinkMan linkmanobj = null;
                for (int i = 0; i < linkmans.Length; i++)
                {
                    linkmanobj = new BioErpCrmChannelLinkMan()
                    {
                        LinkmanName = linkmans[i],
                        Address = Addresses[i],
                        Email = Emails[i],
                        Remark = Remarks[i],
                        Sex = ddlSexs[i] == "0" ? false : true,
                        QQ = QQs[i].ToString(),
                        OfficialPhone = OfficePhones[i],
                        MobilePhone = Mobiles[i],
                        Birthday = Convert.ToDateTime(Birthdays[i]),
                        ChannelID = channelid,
                        IsMainLinkman = MainLinks[i] == "0" ? false : true
                    };
                    linkmanbll.BioErpCrmChannelLinkManADD(linkmanobj);
                }
            }
        }

  添加的时候字符串的验证:

1.验证的js代码:

// 字符验证 
jQuery.validator.addMethod("stringCheck", function(value, element) { 
return this.optional(element) || /^[\u0391-\uFFE5\w]+$/.test(value); 
}, "只能包括中文字、英文字母、数字和下划线"); 
// 中文字两个字节 
jQuery.validator.addMethod("byteRangeLength", function(value, element, param) { 
var length = value.length; 
for(var i = 0; i < value.length; i++){ 
if(value.charCodeAt(i) > 127){ 
length++; 
} 
} 
return this.optional(element) || ( length >= param[0] && length <= param[1] ); 
}, "请确保输入的值在3-15个字节之间(一个中文字算2个字节)"); 
// 身份证号码验证 
jQuery.validator.addMethod("isIdCardNo", function(value, element) { 
return this.optional(element) || isIdCardNo(value); 
}, "请正确输入您的身份证号码"); 
// 手机号码验证 
jQuery.validator.addMethod("isMobile", function(value, element) { 
var length = value.length; 
var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/; 
return this.optional(element) || (length == 11 && mobile.test(value)); 
}, "请正确填写您的手机号码"); 
// 电话号码验证 
jQuery.validator.addMethod("isTel", function(value, element) { 
var tel = /^\d{3,4}-?\d{7,9}$/; //电话号码格式010-12345678 
return this.optional(element) || (tel.test(value)); 
}, "请正确填写您的电话号码"); 
// 联系电话(手机/电话皆可)验证 
jQuery.validator.addMethod("isPhone", function(value,element) { 
var length = value.length; 
var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/; 
var tel = /^\d{3,4}-?\d{7,9}$/; 
return this.optional(element) || (tel.test(value) || mobile.test(value)); 
}, "请正确填写您的联系电话"); 
// 邮政编码验证 
jQuery.validator.addMethod("isZipCode", function(value, element) { 
var tel = /^[0-9]{6}$/; 
return this.optional(element) || (tel.test(value)); 
}, "请正确填写您的邮政编码"); 

 2.样式代码:

*{ 
font-size: 96%; 
} 
label{ 
width: 10em; 
float: left; 
} 
label.error{ 
float: none; 
color: red; 
padding-left: .5em; 
vertical-align: top; 
} 
p{ 
clear: both; 
} 
.submit { 
margin-left: 12em; 
} 
em{ 
font-weight: bold; 
padding-right: 1em; 
vertical-align: top; 
} 

 显示的信息:

jQuery.extend(
jQuery.validator.messages, {
required: "必选字段",
remote: "请修正该字段",
email: "请输入正确格式的电子邮件",
url: "请输入合法的网址",
date: "请输入合法的日期",
dateISO: "请输入合法的日期 (如:2011-11-02).",
number: "请输入合法的数字",
digits: "只能输入整数",
creditcard: "请输入合法的信用卡号",
equalTo: "请再次输入相同的值",
accept: "请输入拥有合法后缀名的字符串",
maxlength: $.validator.format("请输入一个长度最多是 {0} 的字符串"),
minlength: $.validator.format("请输入一个长度最少是 {0} 的字符串"),
rangelength: $.validator.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"),
range: $.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
max: $.validator.format("请输入一个最大为 {0} 的值"),
min: $.validator.format("请输入一个最小为 {0} 的值")
});

 在前端js中调用:

 <script type="text/javascript">
           $(document).ready(function () {

               $("#form1").validate();
               var i = 0;
               jQuery("#btnAddNew").click(function () {
                   i++;
                   tr = ‘‘;
                   tr = tr + ‘ <tr id="tr‘ + i + ‘">‘;
                   tr = tr + ‘  <td><input  name="txtLinkMan1"  MaxLength="10"></input></td>‘;
                   tr = tr + ‘  <td>‘;
                   tr = tr + ‘    <select  name="ddlSex1" > <option Value="0">男</option> <option Value="1">女</option></select>‘;
                   tr = tr + ‘    </td>‘;
                   tr = tr + ‘   <td>‘;
                   tr = tr + ‘    <input  name="txtBirthday1" onfocus="setday(this)" onclick="setday(this)"  MaxLength="20"></input></td>‘;
                   tr = tr + ‘  <td><select  name="ddlMainLink1"> <option Value="1">是</option> <option Value="0">否</option> </select></td>‘;
                   tr = tr + ‘ <td>   <input  name="txtOfficePhone"  MaxLength="20" ></input></td>‘;
                   tr = tr + ‘  <td> <input  name="txtMobile1"  MaxLength="20" ></input></td>‘;
                   tr = tr + ‘  <td> <input name="txtEmail11"  MaxLength="20"></input></td>‘;
                   tr = tr + ‘ <td> <input name="txtAddress1"  MaxLength="50" ></input></td>‘;
                   tr = tr + ‘ <td> <input  name="txtQQ1"  MaxLength="15"></input></td>‘;
                   tr = tr + ‘ <td> <input name="txtRemark1"  MaxLength="200"></input></td>‘;
                   tr = tr + ‘ </tr>‘;

                   $("#caption").before(tr);

               });

               jQuery("#btnDelete").click(function () {
                   $("#tr" + i).remove();
                   i--;
               });

           });
    
    </script>

 验证的时候添加:

 <td>渠道名</td><td><asp:TextBox ID="txtChannelName" CssClass="required" runat="server"></asp:TextBox></td>

 查询的代码:

在数据库中定义视图:

CREATE VIEW [dbo].[View_CRMChannelInfo]
AS

SELECT ChannelID, ChannelName,SuperiorChannelID=SuperiorChannel,
SuperiorChannel=ISNULL(dbo.getFatherChannelNamebyFatherID(SuperiorChannel),‘一级渠道‘)
,Tel1,Tel2,Email,Fax,NextContactTime=ISNULL(NextContactTime,‘1970-1-1‘),LinkMans=dbo.GetUserListByChannelID(ChannelID),
UserID,DeleteState,UserName=dbo.getUserNameByUserID(UserID),
Address,ChannelLevel,NetAddress,CreditStanding,EnrollTime= ISNULL(EnrollTime,‘1970-1-1‘),
ChannelSize,Vocation,ChannelType,Status,Areal,Province,City,
TaxNumber,AccountName,Accounts,CoSummary,CoreOperttion

 FROM dbo.BioErpCrmManageChannel

 SELECT CONVERT(nvarchar(10),getdate(),102)

 自定义函数的定义:

-- =============================================
-- Description:    根据渠道编号获取渠道联系人姓名
-- =============================================
ALTER FUNCTION [dbo].[GetUserListByChannelID]
(
    @ChannelID int
)
RETURNS  nvarchar(200)
AS
BEGIN
    
    declare cur cursor for 
    SELECT LinkmanName FROM BioErpCrmChannelLinkMan WHERE ChannelID =@ChannelID
    open cur
    DECLARE @name nvarchar(20)
    DECLARE @names nvarchar(1000)
    SET @names=‘‘
    FETCH next FROM cur INTO @name
    WHILE @@FETCH_STATUS =0
    BEGIN
        SET @names=@names+@name+‘,‘
        FETCH next FROM cur INTO @name
    END
    CLOSE cur
     DEALLOCATE cur     
     RETURN @names
     
END

 

   自定义函数:

-- =============================================
-- Description:根据上级渠道编号查询对应上级渠道名称
-- =============================================
ALTER FUNCTION [dbo].[getFatherChannelNamebyFatherID]
(
	@FatherID int 
)
RETURNS nvarchar(20)
AS
BEGIN
	-- Declare the return variable here
	DECLARE @fatherChannelName nvarchar(20)
	-- Add the T-SQL statements to compute the return value here
	SELECT @fatherChannelName=ChannelName FROM dbo.BioErpCrmManageChannel
	WHERE ChannelID=@FatherID
	-- Return the result of the function
    RETURN	@fatherChannelName
END

 前端代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChannelListShow.aspx.cs" Inherits="BioErpWeb.CRMSystem.CrmChannel.ChannelListShow" %>

<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>

<%@ Register src="../../UserControl/CRMChannelMenuBar.ascx" tagname="CRMChannelMenuBar" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../Styles/ERPBaseStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/AspNetPagerStyle.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    td{ text-align:center;}
    .tdsearch{ line-height:30px;}
    .menubar{ background:url(../Web/images/block_hd_bg.png); height:25px; width:100%;}
    .menubar ul{ margin:0px; padding:0px; list-style:none;}
    .menubar ul li{ display:inline; line-height:25px;}
    .menubar ul li a{display:inline-block;  text-align:center; width:100px; color:#0066CC; text-decoration:none;}

    </style>
</head>
<body>
    <form id="form1" runat="server">
    
   <div>
   <uc1:CRMChannelMenuBar ID="CRMChannelMenuBar1" runat="server" />

   
   </div>
    <div>
         <table class="maintable" style=" width:900px;">
             <tr>
                 <td colspan="5" class="titlebar">
                     <span>渠道基本信息管理</span>
                 </td>
             </tr>
             <tr>
                 <td class="tdsearch">
                     <asp:Label ID="Label1" runat="server" Text="渠道名称:"></asp:Label>
                     <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                 </td>
                 <td class="tdsearch">
                     <asp:Label ID="Label2" runat="server" Text="渠道等级"></asp:Label>
                         <asp:DropDownList ID="ddlCustomerLevel" runat="server">
                              <asp:ListItem>一级</asp:ListItem>
                              <asp:ListItem>二级</asp:ListItem>
                              <asp:ListItem>三级</asp:ListItem>
                              <asp:ListItem>四级</asp:ListItem>
                          </asp:DropDownList>
              </td>
                 <td class="tdsearch">
                     <asp:Label ID="Label3" runat="server" Text="渠道是否删除"></asp:Label>
                     <asp:DropDownList ID="ddlState" runat="server">
                         <asp:ListItem Value="0">否</asp:ListItem>
                         <asp:ListItem Value="1">是</asp:ListItem>
                     </asp:DropDownList>
                 </td>
                   <td class="tdsearch">
                     <asp:Label ID="Label11" runat="server" Text="省份"></asp:Label>
                           <asp:DropDownList ID="ddlProvince" runat="server" Width="150px">
                                                     </asp:DropDownList>
                 </td>
                 <td class="tdsearch">
                     <asp:ImageButton ID="imgbutnSearch" Width="60" Height="22" runat="server" 
                         ImageUrl="~/Web/images/Btnsearch.gif" onclick="imgbutnSearch_Click" /> 
                     <asp:ImageButton ID="imgbtnNew" runat="server"  Width="60" Height="22" 
                         ImageUrl="~/Web/images/btnadd.gif" onclick="imgbtnNew_Click"/>
                 </td>
             </tr>
             <tr>
                 <td colspan="5" class="bottomtd">
                     <asp:GridView ID="GridView1" Width="100%"  runat="server"  AutoGenerateColumns="False" DataKeyNames="ChannelID">
                         <Columns>                   
                             <asp:TemplateField HeaderText="渠道编号" HeaderStyle-HorizontalAlign="Center">
                                 <ItemTemplate>
                                 
                                     <asp:Label ID="Label4" runat="server" Text=‘<%# Eval("ChannelID") %>‘></asp:Label>
                                 </ItemTemplate>

<HeaderStyle HorizontalAlign="Center"></HeaderStyle>

                                 <ItemStyle HorizontalAlign="Center" />
                             </asp:TemplateField>
                             <asp:TemplateField HeaderText="渠道名称" HeaderStyle-HorizontalAlign="Center">
                                 <ItemTemplate>
                                     <asp:Label ID="Label5" runat="server" Text=‘<%# Eval("ChannelName") %>‘></asp:Label>
                                 </ItemTemplate>
                                 <ItemStyle Width="120px" HorizontalAlign="Center" />

<HeaderStyle HorizontalAlign="Center"></HeaderStyle>

                                 <ItemStyle HorizontalAlign="Center" />
                             </asp:TemplateField>
                              <asp:TemplateField HeaderText="上级渠道" HeaderStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                      <asp:Label ID="Label9" runat="server" Text=‘<%# Eval("SuperiorChannel") %>‘></asp:Label>
                                 </ItemTemplate>   
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                 <ItemStyle HorizontalAlign="Center" />                          
                             </asp:TemplateField>
                             <asp:TemplateField HeaderText="渠道联系人" HeaderStyle-HorizontalAlign="Center">
                                 <ItemTemplate>
                                      <asp:Label ID="Label6" runat="server" Text=‘<%# Eval("LinkMans") %>‘></asp:Label>
                                 </ItemTemplate>

<HeaderStyle HorizontalAlign="Center"></HeaderStyle>

                                 <ItemStyle HorizontalAlign="Center" />
                             </asp:TemplateField>
                             <asp:TemplateField HeaderText="电话号码" HeaderStyle-HorizontalAlign="Center">
                                 <ItemTemplate>
                                      <asp:Label ID="Label7" runat="server" Text=‘<%# Eval("Tel1")+" "+Eval("Tel2") %>‘></asp:Label>
                                 </ItemTemplate>

<HeaderStyle HorizontalAlign="Center"></HeaderStyle>

                                 <ItemStyle HorizontalAlign="Center" />
                             </asp:TemplateField>
                             <asp:TemplateField HeaderText="Email" HeaderStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                      <asp:Label ID="Label8" runat="server" Text=‘<%# Eval("Email") %>‘></asp:Label>
                                 </ItemTemplate>

<HeaderStyle HorizontalAlign="Center"></HeaderStyle>

                                 <ItemStyle HorizontalAlign="Center" />
                             </asp:TemplateField>
                             <asp:TemplateField HeaderText="传真" HeaderStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                      <asp:Label ID="Label9" runat="server" Text=‘<%# Eval("Fax") %>‘></asp:Label>
                                 </ItemTemplate>   
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                 <ItemStyle HorizontalAlign="Center" />                          
                             </asp:TemplateField>
                             
                             <asp:TemplateField HeaderText="下次联系时间" HeaderStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                      <asp:Label ID="Label10" runat="server" Text=‘<%# Convert.ToDateTime(Eval("NextContactTime")).ToString("yyyy/MM/dd") %>‘></asp:Label>
                                 </ItemTemplate>

<HeaderStyle HorizontalAlign="Center"></HeaderStyle>

                                 <ItemStyle HorizontalAlign="Center" />
                             </asp:TemplateField>                      
                             <asp:HyperLinkField DataNavigateUrlFields="ChannelID" 
                                 DataNavigateUrlFormatString="CustomerUpdate.aspx?ID={0}" HeaderText="操作" 
                                 Text="查看并修改客户信息">
                             <HeaderStyle HorizontalAlign="Center" />
                             <ItemStyle HorizontalAlign="Center" />
                             </asp:HyperLinkField>
                         </Columns>
                     </asp:GridView>
                 </td>
             </tr>
             <tr>
              <td  colspan="5">
                  <webdiyer:AspNetPager ID="AspNetPager1" runat="server"   CssClass="paginator" CurrentPageButtonClass="cpb"
                      onpagechanged="AspNetPager1_PageChanged">
                  </webdiyer:AspNetPager>
                 </td>
             </tr>

     </table>

    </div>
    </form>
</body>
</html>

 后台代码:

   public static int pageindex = 0;
        public static int pagesize = 10;
        public static string condition = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (UserLogin.user.RoleId != 6 && UserLogin.user.RoleId != 7)
            //{
            //    Response.Write("<script>window.history.back()</script>");
            //     //Response.Redirect("../Web/Desk.aspx");
            //    //Server.Transfer("../Web/Desk.aspx");
            //    return;     
            //}
            Session["Userid"] = "29";
            if (!IsPostBack)
            {

                ddlProvinceBind();
                getallCustomerList();
            }
        }

        /// <summary>
        /// 绑定省份
        /// </summary>
        public void ddlProvinceBind()
        {
            this.ddlProvince.DataSource = SqlComm.getProvinceInfoList();
            this.ddlProvince.DataTextField = "ProvinceInfoName";
            this.ddlProvince.DataValueField = "ProvinceInfoID";
            this.ddlProvince.DataBind();
            this.ddlProvince.Items.Add(new ListItem("--请选择省份--", "0"));
            this.ddlProvince.SelectedValue = "0";
        }


        /// <summary>
        /// 查询所有员工信息
        /// </summary>
        private void getallCustomerList()
        {
            //如果是市场部经理,或客服部经理可以查看所有
            if (UserLogin.user.RoleId == 6 || UserLogin.user.RoleId == 7)
            {
                this.AspNetPager1.RecordCount = SqlComm.getDataCountByCondition("dbo.View_CRMChannelInfo", condition);
                this.AspNetPager1.PageSize = pagesize;
                this.GridView1.DataSource = SqlComm.getDataByPageIndex("dbo.View_CRMChannelInfo", "*", "ChannelID", condition, pageindex, pagesize);
                this.GridView1.DataBind();
            }
            else //员工只能看自己的客户信息
            {
                condition = condition + " and userid=" + Session["Userid"].ToString();
                this.AspNetPager1.RecordCount = SqlComm.getDataCountByCondition("dbo.View_CRMChannelInfo", condition);
                this.AspNetPager1.PageSize = pagesize;
                this.GridView1.DataSource = SqlComm.getDataByPageIndex("dbo.View_CRMChannelInfo", "*", "ChannelID", condition, pageindex, pagesize);
                this.GridView1.DataBind();
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            pageindex = this.AspNetPager1.CurrentPageIndex - 1;
            getallCustomerList();
        }

        protected void imgbutnSearch_Click(object sender, ImageClickEventArgs e)
        {
            pageindex = 0;
            condition = "";
            if (txtName.Text.Trim() != null && this.txtName.Text.Trim().Length != 0)
            {
                condition = condition + " and CustomerName like ‘" + txtName.Text + "%‘";
            }
                     

          
            if (this.ddlState.SelectedValue == "1")
            {
                condition = condition + " and DeleteState =‘True‘";
            }
            else
            {
                condition = condition + " and DeleteState =‘False‘";
            }

             condition = condition + " and CustomerLevel=‘" + this.ddlCustomerLevel.SelectedItem.Text+"‘ ";

            if (this.ddlProvince.SelectedValue != "0")
            {
                condition = condition +" and Province=‘"+ this.ddlProvince.SelectedItem.Text+"‘";
            }
      
            getallCustomerList();

        }


        protected void imgbtnNew_Click(object sender, ImageClickEventArgs e)
        {
            Server.Transfer("CustomerAdd.aspx");
        }

 

ERP渠道管理添加验证和查询(二)

标签:address   arch   creat   rem   result   GridView   opd   电话   element   

原文地址:http://www.cnblogs.com/sunliyuan/p/6853710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!