Exemple #1
0
    /// <summary>
    /// 确定导入
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnImport_Click(object sender, EventArgs e)
    {
        if (HttpContext.Current.Session["DisTable"] != null)
        {
            SqlTransaction Tran = DBUtility.SqlHelper.CreateStoreTranSaction();
            try
            {
                DataTable dt = HttpContext.Current.Session["DisTable"] as DataTable;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["chkstr"].ToString() == "数据正确!")
                    {
                        Hi.Model.BD_Distributor Dis = new Hi.Model.BD_Distributor();
                        //Dis.DisCode = Discode;
                        Dis.CompID       = CompID;
                        Dis.DisName      = dt.Rows[i]["disname"].ToString().Trim();
                        Dis.Province     = dt.Rows[i]["pro"].ToString().Trim();
                        Dis.City         = dt.Rows[i]["city"].ToString().Trim();
                        Dis.Area         = dt.Rows[i]["quxian"].ToString().Trim();
                        Dis.Address      = dt.Rows[i]["address"].ToString().Trim();
                        Dis.Principal    = dt.Rows[i]["principal"].ToString().Trim();
                        Dis.Phone        = dt.Rows[i]["phone"].ToString().Trim();
                        Dis.DisTypeID    = Convert.ToInt32(dt.Rows[i]["distypeid"].ToString().Trim()); //add by 2016.5.9
                        Dis.AreaID       = Convert.ToInt32(dt.Rows[i]["areaid"].ToString().Trim());    //add by 2016.5.10
                        Dis.Remark       = dt.Rows[i]["remark"].ToString().Trim();
                        Dis.IsCheck      = 0;
                        Dis.CreditType   = 0; //不可以赊销
                        Dis.Paypwd       = Util.md5("123456");
                        Dis.IsEnabled    = 1;
                        Dis.AuditState   = 2;
                        Dis.CreateDate   = DateTime.Now;
                        Dis.CreateUserID = UserID;
                        Dis.ts           = DateTime.Now;
                        Dis.modifyuser   = UserID;
                        int disid = 0;
                        if ((disid = new Hi.BLL.BD_Distributor().Add(Dis, Tran)) > 0)
                        {
                            List <Hi.Model.SYS_Role> l = new Hi.BLL.SYS_Role().GetList("", "isnull(dr,0)=0 and isenabled=1 and DisID=" + disid + " and RoleName='企业管理员'", "", Tran);
                            if (l.Count == 0)
                            {
                                //新增角色(企业管理员)
                                Hi.Model.SYS_Role role = new Hi.Model.SYS_Role();
                                role.CompID       = CompID;
                                role.DisID        = disid;
                                role.RoleName     = "企业管理员";
                                role.IsEnabled    = 1;
                                role.SortIndex    = "1";
                                role.CreateDate   = DateTime.Now;
                                role.CreateUserID = UserID;
                                role.ts           = DateTime.Now;
                                role.modifyuser   = UserID;
                                role.dr           = 0;
                                int Roid = new Hi.BLL.SYS_Role().Add(role, Tran);
                                //新增管理员用户和角色
                                Hi.Model.SYS_Users user = new Hi.Model.SYS_Users();
                                user.UserName     = dt.Rows[i]["username"].ToString().Trim();
                                user.Phone        = dt.Rows[i]["phone"].ToString().Trim();
                                user.TrueName     = dt.Rows[i]["principal"].ToString().Trim();
                                user.UserPwd      = Util.md5("123456");
                                user.IsEnabled    = 1;
                                user.AuditState   = 2;
                                user.CreateDate   = DateTime.Now;
                                user.CreateUserID = UserID;
                                user.ts           = DateTime.Now;
                                user.modifyuser   = UserID;
                                int AddUserid = new Hi.BLL.SYS_Users().Add(user, Tran);

                                ///用户明细表
                                Hi.Model.SYS_CompUser CompUser = new Hi.Model.SYS_CompUser();
                                CompUser.CompID       = CompID;
                                CompUser.DisID        = disid;
                                CompUser.CreateDate   = DateTime.Now;
                                CompUser.CreateUserID = UserID;
                                CompUser.modifyuser   = UserID;
                                CompUser.CType        = 2;
                                CompUser.UType        = 5;
                                CompUser.IsEnabled    = 1;
                                CompUser.IsAudit      = 2;
                                CompUser.RoleID       = Roid;
                                CompUser.ts           = DateTime.Now;
                                CompUser.dr           = 0;
                                CompUser.UserID       = AddUserid;
                                new Hi.BLL.SYS_CompUser().Add(CompUser, Tran);
                                //新增角色权限表   //暂时屏蔽下
                                Hi.Model.SYS_RoleSysFun    rolesys = null;
                                List <Hi.Model.SYS_SysFun> funList = new Hi.BLL.SYS_SysFun().GetList("", " Type=2", "", Tran);
                                foreach (Hi.Model.SYS_SysFun sys in funList)
                                {
                                    rolesys              = new Hi.Model.SYS_RoleSysFun();
                                    rolesys.CompID       = CompID;
                                    rolesys.DisID        = disid;
                                    rolesys.RoleID       = Roid;
                                    rolesys.FunCode      = sys.FunCode;
                                    rolesys.FunName      = sys.FunName;
                                    rolesys.IsEnabled    = 1;
                                    rolesys.CreateUserID = UserID;
                                    rolesys.CreateDate   = DateTime.Now;
                                    rolesys.ts           = DateTime.Now;
                                    rolesys.modifyuser   = UserID;
                                    new Hi.BLL.SYS_RoleSysFun().Add(rolesys, Tran);
                                }
                            }

                            Hi.Model.BD_DisAddr addr = new Hi.Model.BD_DisAddr();
                            addr.Province     = dt.Rows[i]["pro"].ToString().Trim();
                            addr.City         = dt.Rows[i]["city"].ToString().Trim();
                            addr.Area         = dt.Rows[i]["quxian"].ToString().Trim();
                            addr.DisID        = disid;
                            addr.Principal    = dt.Rows[i]["principal"].ToString().Trim();
                            addr.Phone        = dt.Rows[i]["phone"].ToString().Trim();
                            addr.Address      = dt.Rows[i]["pro"].ToString().Trim() + dt.Rows[i]["city"].ToString().Trim() + dt.Rows[i]["quxian"].ToString().Trim() + dt.Rows[i]["address"].ToString().Trim();
                            addr.IsDefault    = 1;
                            addr.ts           = DateTime.Now;
                            addr.CreateDate   = DateTime.Now;
                            addr.CreateUserID = UserID;
                            addr.modifyuser   = UserID;
                            new Hi.BLL.BD_DisAddr().Add(addr, Tran);
                        }
                        else
                        {
                            throw new ApplicationException("导入失败,服务器异常请重试。");
                        }
                    }
                }
                Tran.Commit();
                Response.Redirect("ImportDis3.aspx", false);
                //ClientScript.RegisterStartupScript(this.GetType(), "Add", "<script>addlis(" + count + "," + count2 + ",'" + str + "');</script>");
            }
            catch (Exception ex)
            {
                if (Tran != null)
                {
                    if (Tran.Connection != null)
                    {
                        Tran.Rollback();
                    }
                }
                HttpContext.Current.Session["DisTable"] = null;
                JScript.AlertMethod(this, ex.Message, JScript.IconOption.错误, "function(){location.href='ImportDis.aspx'}");
            }
        }
        else
        {
            JScript.AlertMethod(this, "Excel没有数据,请重新导入", JScript.IconOption.错误, "function(){location.href='ImportDis.aspx'}");
        }
    }
Exemple #2
0
    public void btnAddList_Click(object sender, EventArgs e)
    {
        string         path  = "";
        int            count = 0;
        int            index = 0;
        SqlTransaction Tran  = null;

        try
        {
            if (FileUpload1.HasFile == false)//HasFile用来检查FileUpload是否有指定文件
            {
                JScript.AlertMsgOne(this, "请您选择代理商Excel模板文件", JScript.IconOption.错误);
                return;                                                                            //当无文件时,返回
            }
            string IsXls = System.IO.Path.GetExtension(FileUpload1.FileName).ToString().ToLower(); //System.IO.Path.GetExtension获得文件的扩展名
            if (IsXls != ".xls" && IsXls != ".xlsx")
            {
                JScript.AlertMsgOne(this, "请您选择代理商Excel模板文件", JScript.IconOption.错误);
                return;//当选择的不是Excel文件时,返回
            }
            if (!Directory.Exists(Server.MapPath("TemplateFile")))
            {
                Directory.CreateDirectory(Server.MapPath("TemplateFile"));
            }
            string filename = FileUpload1.FileName;
            string name     = filename.Replace(IsXls, "");
            path = Server.MapPath("TemplateFile/") + name + "-" + DateTime.Now.ToString("yyyyMMddhhmmssffff") + IsXls;
            FileUpload1.SaveAs(path);
            DataTable dt = Common.ExcelToDataTable(path, TitleIndex);
            if (dt == null)
            {
                throw new Exception("Excel表中无数据");
            }
            if (dt.Rows.Count == 0)
            {
                throw new Exception("Excel表中无数据");
            }
            string    Discode     = string.Empty;
            string    DisName     = string.Empty;
            string    DisUserName = string.Empty;
            string    DisAddrees  = string.Empty;
            string    DisPerson   = string.Empty;
            string    DisPhone    = string.Empty;
            string    DisRemark   = string.Empty;
            string    Provice     = string.Empty;
            string    City        = string.Empty;
            string    Area        = string.Empty;
            string    DisCategory = string.Empty;
            string    DisLevel    = string.Empty;
            DataRow[] rows        = dt.Select();
            Tran       = DBUtility.SqlHelper.CreateStoreTranSaction();
            Eroor      = false;
            TitleError = string.Empty;
            foreach (DataRow row in rows)
            {
                int typeID = 0;
                int AreaID = 0;
                try
                {
                    //这个判断有bug呀,是遇到空行就停止的意思吗?
                    if (row["代理商名称 *\n(2-20个汉字或字母,推荐使用中文名称)"].ToString().Trim() == "" && row["管理员姓名 *\n(请填写真实姓名,以便更好地为您服务)"].ToString().Trim() == "" && row["详细地址 *\n(常用收货地址)"].ToString().Trim() == "")
                    {
                        break;
                    }
                    index++;
                    if (row["代理商名称 *\n(2-20个汉字或字母,推荐使用中文名称)"].ToString().Trim() == "示例代理商名称1" || row["代理商名称 *\n(2-20个汉字或字母,推荐使用中文名称)"].ToString().Trim() == "示例代理商名称2" || row["代理商名称 *\n(2-20个汉字或字母,推荐使用中文名称)"].ToString().Trim() == "示例代理商名称3")
                    {
                        continue;
                    }
                    DisName     = DisExistsAttribute("DisName", CheckDisLen(CheckVal(row["代理商名称 *\n(2-20个汉字或字母,推荐使用中文名称)"].ToString().Trim(), "代理商名称", index), index), "代理商名称", index, Tran);
                    DisPerson   = CheckVal(row["管理员姓名 *\n(请填写真实姓名,以便更好地为您服务)"].ToString().Trim(), "管理员姓名", index);
                    DisUserName = UserExistsAttribute("username", CheckVal(row["管理员登录帐号 *\n(2-20个文字、字母、数字,可以录入代理商姓名、简称等,一经设定无法更改,将来可用手机号进行登录)"].ToString().Trim(), "管理员登录帐号", index), "管理员登录帐号", index, Tran);
                    DisPhone    = CheckPhone(CheckVal(row["管理员手机 *\n(登录、发送验证短信)"].ToString().Trim(), "管理员手机", index), "管理员手机", index, Tran);
                    Provice     = CheckVal(row["所在省*"].ToString().Trim(), "省", index);
                    City        = CheckVal(row["所在市*"].ToString().Trim(), "市", index);
                    if (City.IndexOf("_") > 0)
                    {
                        City = City.Substring(City.IndexOf("_") + 1, City.Length - City.IndexOf("_") - 1);
                    }
                    Area        = CheckVal(row["所在区*"].ToString().Trim(), "区", index);
                    DisAddrees  = CheckVal(row["详细地址 *\n(常用收货地址)"].ToString().Trim(), "详细地址(常用收货地址)", index);
                    DisCategory = row["代理商分类"].ToString().Trim();
                    DisLevel    = row["代理商区域"].ToString().Trim();
                    bool disType = true;
                    if (!string.IsNullOrEmpty(DisCategory))
                    {
                        disType = CheckDisCategory(DisCategory, index, out typeID);
                    }
                    if (!string.IsNullOrEmpty(DisLevel))
                    {
                        CheckDisLevel(DisLevel, index, out AreaID);
                    }
                    DisRemark = row["备注"].ToString().Trim();
                    if (Eroor)
                    {
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    if (ex is ApplicationException)
                    {
                        Eroor       = true;
                        TitleError += ex.Message;
                        continue;
                    }
                    else
                    {
                        throw new Exception("代理商Excel模版格式错误,请重新下载模版填入数据后导入。");
                    }
                }

                Hi.Model.BD_Distributor Dis = new Hi.Model.BD_Distributor();
                //Dis.DisCode = Discode;
                Dis.CompID       = CompID;
                Dis.DisName      = DisName;
                Dis.Province     = Provice;
                Dis.City         = City;
                Dis.Area         = Area;
                Dis.Address      = DisAddrees;
                Dis.Principal    = DisPerson;
                Dis.Phone        = DisPhone;
                Dis.DisTypeID    = typeID; //add by 2016.5.9
                Dis.AreaID       = AreaID; //add by 2016.5.10
                Dis.Remark       = DisRemark;
                Dis.IsCheck      = 0;
                Dis.CreditType   = 0; //不可以赊销
                Dis.Paypwd       = Util.md5("123456");
                Dis.IsEnabled    = 1;
                Dis.AuditState   = 2;
                Dis.CreateDate   = DateTime.Now;
                Dis.CreateUserID = UserID;
                Dis.ts           = DateTime.Now;
                Dis.modifyuser   = UserID;
                int disid = 0;
                if ((disid = new Hi.BLL.BD_Distributor().Add(Dis, Tran)) > 0)
                {
                    List <Hi.Model.SYS_Role> l = new Hi.BLL.SYS_Role().GetList("", "isnull(dr,0)=0 and isenabled=1 and DisID=" + disid + " and RoleName='企业管理员'", "", Tran);
                    if (l.Count == 0)
                    {
                        //新增角色(企业管理员)
                        Hi.Model.SYS_Role role = new Hi.Model.SYS_Role();
                        role.CompID       = CompID;
                        role.DisID        = disid;
                        role.RoleName     = "企业管理员";
                        role.IsEnabled    = 1;
                        role.SortIndex    = "1";
                        role.CreateDate   = DateTime.Now;
                        role.CreateUserID = UserID;
                        role.ts           = DateTime.Now;
                        role.modifyuser   = UserID;
                        role.dr           = 0;
                        int Roid = new Hi.BLL.SYS_Role().Add(role, Tran);
                        //新增管理员用户和角色
                        Hi.Model.SYS_Users user = new Hi.Model.SYS_Users();
                        user.UserName     = DisUserName;
                        user.Phone        = DisPhone;
                        user.TrueName     = DisPerson;
                        user.UserPwd      = Util.md5("123456");
                        user.IsEnabled    = 1;
                        user.AuditState   = 2;
                        user.CreateDate   = DateTime.Now;
                        user.CreateUserID = UserID;
                        user.ts           = DateTime.Now;
                        user.modifyuser   = UserID;
                        int AddUserid = new Hi.BLL.SYS_Users().Add(user, Tran);

                        ///用户明细表
                        Hi.Model.SYS_CompUser CompUser = new Hi.Model.SYS_CompUser();
                        CompUser.CompID       = CompID;
                        CompUser.DisID        = disid;
                        CompUser.CreateDate   = DateTime.Now;
                        CompUser.CreateUserID = UserID;
                        CompUser.modifyuser   = UserID;
                        CompUser.CType        = 2;
                        CompUser.UType        = 5;
                        CompUser.IsEnabled    = 1;
                        CompUser.IsAudit      = 2;
                        CompUser.RoleID       = Roid;
                        CompUser.ts           = DateTime.Now;
                        CompUser.dr           = 0;
                        CompUser.UserID       = AddUserid;
                        new Hi.BLL.SYS_CompUser().Add(CompUser, Tran);
                        //新增角色权限表   //暂时屏蔽下
                        Hi.Model.SYS_RoleSysFun    rolesys = null;
                        List <Hi.Model.SYS_SysFun> funList = new Hi.BLL.SYS_SysFun().GetList("", " Type=2", "", Tran);
                        foreach (Hi.Model.SYS_SysFun sys in funList)
                        {
                            rolesys              = new Hi.Model.SYS_RoleSysFun();
                            rolesys.CompID       = CompID;
                            rolesys.DisID        = disid;
                            rolesys.RoleID       = Roid;
                            rolesys.FunCode      = sys.FunCode;
                            rolesys.FunName      = sys.FunName;
                            rolesys.IsEnabled    = 1;
                            rolesys.CreateUserID = UserID;
                            rolesys.CreateDate   = DateTime.Now;
                            rolesys.ts           = DateTime.Now;
                            rolesys.modifyuser   = UserID;
                            new Hi.BLL.SYS_RoleSysFun().Add(rolesys, Tran);
                        }
                    }

                    Hi.Model.BD_DisAddr addr = new Hi.Model.BD_DisAddr();
                    addr.Province     = Provice;
                    addr.City         = City;
                    addr.Area         = Area;
                    addr.DisID        = disid;
                    addr.Principal    = DisPerson;
                    addr.Phone        = DisPhone;
                    addr.Address      = Provice + City + Area + DisAddrees;
                    addr.IsDefault    = 1;
                    addr.ts           = DateTime.Now;
                    addr.CreateDate   = DateTime.Now;
                    addr.CreateUserID = UserID;
                    addr.modifyuser   = UserID;
                    new Hi.BLL.BD_DisAddr().Add(addr, Tran);
                }
                else
                {
                    throw new ApplicationException("导入失败,服务器异常请重试。");
                }
                count++;
            }
            if (!Eroor)
            {
                Tran.Commit();
                if (Request["nextstep"] + "" == "1")
                {
                    JScript.AlertMethod(this, "导入成功,共导入" + count + "条代理商", JScript.IconOption.笑脸, "function(){  window.location.href=window.location.href+'?nextstep=1'; /* $(window.parent.leftFrame.document).find('.menuson li.active').removeClass('active');window.parent.leftFrame.document.getElementById('ktxzjxs').className = 'active';*/}");
                }
                else
                {
                    JScript.AlertMethod(this, "导入成功,共导入" + count + "条代理商", JScript.IconOption.笑脸, "function(){  window.location.href=window.location.href; }");
                }
            }
            else
            {
                Tran.Rollback();
                JScript.AlertMethod(this, TitleError, JScript.IconOption.错误, "function(){ addList(); }");
            }
        }
        catch (Exception ex)
        {
            if (Tran != null)
            {
                if (Tran.Connection != null)
                {
                    Tran.Rollback();
                }
            }
            JScript.AlertMethod(this, ex.Message, JScript.IconOption.错误, "function(){ $('a.bulk').trigger('click'); }");
        }
        finally
        {
            if (!string.IsNullOrEmpty(path))
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }
    }
Exemple #3
0
    public EditResult AddResellerShippingAddressList(string JSon)
    {
        string UserID    = string.Empty;
        string disID     = string.Empty;
        string Principal = string.Empty;
        string Phone     = string.Empty;
        string Province  = string.Empty;
        string City      = string.Empty;
        string Area      = string.Empty;
        string Address   = string.Empty;
        string IsDefault = string.Empty;

        try
        {
            #region JSon取值
            JsonData JInfo = JsonMapper.ToObject(JSon);
            if (JInfo.Count <= 0 || JInfo["UserID"].ToString() == "" || JInfo["ResellerID"].ToString() == "" ||
                JInfo["Province"].ToString() == "" || JInfo["City"].ToString() == "" ||
                JInfo["Area"].ToString() == "" || JInfo["IsDefault"].ToString() == "")
            {
                return new EditResult()
                       {
                           Result = "F", Description = "参数异常"
                       }
            }
            ;
            UserID    = JInfo["UserID"].ToString();
            disID     = JInfo["ResellerID"].ToString();
            Province  = JInfo["Province"].ToString();
            City      = JInfo["City"].ToString();
            Area      = JInfo["Area"].ToString();
            IsDefault = JInfo["IsDefault"].ToString();
            if (JInfo["Principal"].ToString() == "")
            {
                return new EditResult()
                       {
                           Result = "F", Description = "联系人不能为空"
                       }
            }
            ;
            if (JInfo["Phone"].ToString() == "")
            {
                return new EditResult()
                       {
                           Result = "F", Description = "联系电话不能为空"
                       }
            }
            ;
            if (JInfo["Address"].ToString() == "")
            {
                return new EditResult()
                       {
                           Result = "F", Description = "详细地址不能为空"
                       }
            }
            ;
            Principal = JInfo["Principal"].ToString();
            Phone     = JInfo["Phone"].ToString();
            Address   = JInfo["Address"].ToString();
            #endregion
            //判断登录信息是否正确
            Hi.Model.SYS_Users one = new Hi.Model.SYS_Users();
            if (!new Common().IsLegitUser(Int32.Parse(UserID), out one, 0, Int32.Parse(disID == "" ? "0" : disID)))
            {
                return(new EditResult()
                {
                    Result = "F", Description = "登录信息异常"
                });
            }

            Hi.Model.BD_DisAddr disaddr = new Hi.Model.BD_DisAddr();
            disaddr.DisID        = Int32.Parse(disID);
            disaddr.Principal    = Principal;
            disaddr.Phone        = Phone;
            disaddr.Province     = Province;
            disaddr.City         = City;
            disaddr.Area         = Area;
            disaddr.Address      = Address;
            disaddr.IsDefault    = IsDefault == "0" ? 0 : 1;
            disaddr.CreateUserID = one.ID;
            disaddr.CreateDate   = DateTime.Now;
            disaddr.ts           = DateTime.Now;
            disaddr.dr           = 0;
            disaddr.modifyuser   = one.ID;
            List <Hi.Model.BD_DisAddr> list_addr = null;
            if (IsDefault != "0")
            {
                list_addr = new Hi.BLL.BD_DisAddr().GetList("", "DisID=" + disID + " and isnull(IsDefault,0) =1 and isnull(dr,0) = 0", "");
            }
            SqlConnection conn = new SqlConnection(SqlHelper.LocalSqlServer);
            conn.Open();
            SqlTransaction mytran = conn.BeginTransaction();
            try
            {
                if (new Hi.BLL.BD_DisAddr().Add(disaddr, mytran) <= 0)
                {
                    mytran.Rollback();
                    return(new EditResult()
                    {
                        Result = "F", Description = "新增失败"
                    });
                }
                if (list_addr != null && list_addr.Count > 0)
                {
                    foreach (Hi.Model.BD_DisAddr addr in list_addr)
                    {
                        addr.IsDefault = 0;
                        if (!new Hi.BLL.BD_DisAddr().Update(addr, mytran))
                        {
                            mytran.Rollback();
                            return(new EditResult()
                            {
                                Result = "F", Description = "新增失败"
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                mytran.Rollback();
                conn.Close();
                Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "AddResellerShippingAddressList:" + JSon);
                return(new EditResult()
                {
                    Result = "F", Description = "新增失败"
                });
            }
            mytran.Commit();
            return(new EditResult()
            {
                Result = "T", Description = "新增成功"
            });
        }
        catch (Exception ex)
        {
            Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "AddResellerShippingAddressList:" + JSon);
            return(new EditResult()
            {
                Result = "F", Description = "新增失败"
            });
        }
    }
Exemple #4
0
    public ResultAddrAdd ResellerAddrAdd(string JSon)
    {
        try
        {
            #region JSon取值

            string userID      = string.Empty;
            string disID       = string.Empty;
            string phoneCodeID = string.Empty;
            string MessageCode = string.Empty;
            string Principal   = string.Empty;
            string Phone       = string.Empty;
            string Province    = string.Empty;
            string City        = string.Empty;
            string Area        = string.Empty;
            string Address     = string.Empty;

            JsonData JInfo = JsonMapper.ToObject(JSon);
            if (JInfo.Count > 0 && JInfo["UserID"].ToString() != "" && JInfo["ResellerID"].ToString() != "" &&
                JInfo["ChangePasswordID"].ToString() != "" && JInfo["MessageCode"].ToString() != "" &&
                JInfo["Phone"].ToString() != "" && JInfo["Principal"].ToString() != "" &&
                JInfo["Province"].ToString() != "" && JInfo["City"].ToString() != "" &&
                JInfo["Area"].ToString() != "" && JInfo["Address"].ToString() != "")
            {
                userID      = JInfo["UserID"].ToString();
                disID       = JInfo["ResellerID"].ToString();
                phoneCodeID = JInfo["ChangePasswordID"].ToString();
                MessageCode = JInfo["MessageCode"].ToString();
                Phone       = JInfo["Phone"].ToString();
                Principal   = JInfo["Principal"].ToString();
                Province    = JInfo["Province"].ToString();
                City        = JInfo["City"].ToString();
                Area        = JInfo["Area"].ToString();
                Address     = JInfo["Address"].ToString();
            }
            else
            {
                return(new ResultAddrAdd()
                {
                    Result = "F", Description = "参数异常"
                });
            }

            Hi.Model.SYS_Users user = new Hi.Model.SYS_Users();
            if (!new Common().IsLegitUser(int.Parse(userID), out user, 0, int.Parse(disID == "" ? "0" : disID)))
            {
                return new ResultAddrAdd()
                       {
                           Result = "F", Description = "登录信息异常"
                       }
            }
            ;

            #endregion

            Hi.Model.SYS_PhoneCode code = new Hi.BLL.SYS_PhoneCode().GetModel(int.Parse(phoneCodeID));
            if (code != null)
            {
                if (code.ts.AddMinutes(30) < DateTime.Now || code.IsPast == 1)
                {
                    return new ResultAddrAdd()
                           {
                               Result = "F", Description = "验证码过期"
                           }
                }
                ;

                if (code.UserID.ToString() != userID)
                {
                    return new ResultAddrAdd()
                           {
                               Result = "F", Description = "非本人操作"
                           }
                }
                ;
                if (code.PhoneCode != MessageCode)
                {
                    return new ResultAddrAdd()
                           {
                               Result = "F", Description = "验证码错误"
                           }
                }
                ;
            }
            else
            {
                return(new ResultAddrAdd()
                {
                    Result = "F", Description = "验证码异常"
                });
            }

            List <Hi.Model.BD_DisAddr> addrList = new Hi.BLL.BD_DisAddr().GetList("", "disid='" + disID + "' and ", "");
            if (addrList != null)
            {
                if (addrList.Count >= 10)
                {
                    return new ResultAddrAdd()
                           {
                               Result = "F", Description = "一个经销商收货地址最多为10个"
                           }
                }
                ;
                if (addrList.Select(p => p.Address).Contains(Province + City + Area + Address))
                {
                    return new ResultAddrAdd()
                           {
                               Result = "F", Description = "经销商收货地址已经存在"
                           }
                }
                ;
            }

            Hi.Model.BD_DisAddr addr = new Hi.Model.BD_DisAddr()
            {
                IsDefault    = 0,
                Principal    = Principal,
                Phone        = Phone,
                Province     = Province,
                City         = City,
                Area         = Area,
                Address      = Province + City + Area + Address,
                CreateDate   = DateTime.Now,
                CreateUserID = Convert.ToInt32(userID),
                modifyuser   = Convert.ToInt32(userID),
                dr           = 0
            };

            int count = new Hi.BLL.BD_DisAddr().Add(addr);
            if (count > 0)
            {
                return new ResultAddrAdd()
                       {
                           Result = "T", Description = "新增成功", AddrID = count
                       }
            }
            ;
            else
            {
                return(new ResultAddrAdd()
                {
                    Result = "F", Description = "新增失败"
                });
            }
        }
        catch (Exception ex)
        {
            Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "ResellerAddrAdd :" + JSon);
            return(new ResultAddrAdd {
                Result = "F", Description = "异常"
            });
        }
    }
Exemple #5
0
    /// <summary>
    ///核心企业新增经销商
    /// </summary>
    /// <param name="JSon"></param>
    /// <returns></returns>
    public ReseltResellerEdit AddReseller(string JSon)
    {
        string UserID = string.Empty;
        string CompID = string.Empty;

        try
        {
            #region//JSon取值
            JsonData JInfo = JsonMapper.ToObject(JSon);
            if (JInfo["UserID"].ToString().Trim() == "" || JInfo["CompID"].ToString().Trim() == "" || JInfo["Reseller"].ToString().Trim() == "")
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "参数异常"
                       }
            }
            ;
            UserID = JInfo["UserID"].ToString();
            CompID = JInfo["CompID"].ToString();
            JsonData Reseller = JInfo["Reseller"];
            //判断登录信息是否异常
            Hi.Model.SYS_Users one = new Hi.Model.SYS_Users();
            if (!new Common().IsLegitUser(int.Parse(UserID), out one, Int32.Parse(CompID)))
            {
                return(new ReseltResellerEdit()
                {
                    Result = "F", Description = "登录信息异常"
                });
            }
            //判断核心企业信息是否异常
            Hi.Model.BD_Company comp = new Hi.BLL.BD_Company().GetModel(Int32.Parse(CompID));
            if (comp == null || comp.dr == 1 || comp.IsEnabled == 0 || comp.AuditState == 0)
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "核心企业信息异常"
                       }
            }
            ;
            #endregion
            #region//判断传入的经销商信息是否正确
            string resellername = Common.NoHTML(Reseller["ResellerName"].ToString().Trim());
            string resellercode = Common.NoHTML(Reseller["ResellerCode"].ToString().Trim());
            string address      = Common.NoHTML(Reseller["Address"].ToString().Trim());
            if (resellername == "")
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "请输入经销商名称"
                       }
            }
            ;
            //判断经销商名字是否已存在
            if (Common.DisExistsAttribute("DisName", resellername, CompID.ToString()))
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "经销商名称已经存在"
                       }
            }
            ;
            if (Reseller["ResellerProvince"].ToString().Trim() == "")
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "请选择经销商地址中的省"
                       }
            }
            ;
            if (Reseller["ResellerCity"].ToString().Trim() == "")
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "请选择经销商地址中的市"
                       }
            }
            ;
            if (Reseller["ResellerArea"].ToString().Trim() == "")
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "请选择经销商地址中的区"
                       }
            }
            ;
            if (address == "")
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "请输入经销商地址中的详细地址"
                       }
            }
            ;
            #endregion
            #region//判断登录信息的正确信
            JsonData account  = Reseller["Account"];
            string   username = Common.NoHTML(account["UserName"].ToString().Trim());
            string   truename = Common.NoHTML(account["TrueName"].ToString().Trim());
            if (account["UserName"].ToString().Trim() == "")
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "请输入登录账号"
                       }
            }
            ;
            //判断登录账号是否已经存在
            if (Common.GetUserExists(username))
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "该登录账号已存在"
                       }
            }
            ;
            if (truename == "")
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "请输入姓名"
                       }
            }
            ;
            if (account["Phone"].ToString().Trim() == "")
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "请登录信息中的手机号码"
                       }
            }
            ;
            //判断手机号有没被注册过
            Regex Phonereg = new Regex("^0?(13[0-9]|15[012356789]|18[0-9]|14[57]|17[7])[0-9]{8}$");
            if (!Phonereg.IsMatch(account["Phone"].ToString()))
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "登录信息中的手机号格式错误"
                       }
            }
            ;
            if (Common.GetUserExists("Phone", account["Phone"].ToString()))
            {
                return new ReseltResellerEdit()
                       {
                           Result = "F", Description = "登录信息中的手机号已被注册"
                       }
            }
            ;
            #endregion
            //创建需要导入的经销商实体
            Hi.Model.BD_Distributor disModel = new Hi.Model.BD_Distributor();
            disModel.CompID  = comp.ID;
            disModel.DisCode = resellercode;
            disModel.DisName = resellername;
            //传入分类ID的话,判断分类ID是否正确
            if (Reseller["ResellerClassifyID"].ToString().Trim() != "" && Reseller["ResellerClassifyID"].ToString() != "0")
            {
                Hi.Model.BD_DisType distpye = new Hi.BLL.BD_DisType().GetModel(Int32.Parse(Reseller["ResellerClassifyID"].ToString().Trim()));

                if (distpye == null || distpye.CompID != comp.ID)
                {
                    return new ReseltResellerEdit()
                           {
                               Result = "F", Description = "经销商分类异常"
                           }
                }
                ;
                if (distpye.dr == 1)
                {
                    return new ReseltResellerEdit()
                           {
                               Result = "F", Description = "此经销商分类已被删除"
                           }
                }
                ;
                //if (distpye.IsEnabled != 0)
                //    return new ReseltResellerEdit() { Result = "F", Description = "此经销商分类已被禁用" };

                disModel.DisTypeID = distpye.ID;
            }
            else
            {
                disModel.DisTypeID = 0;
            }
            //传入区域ID的话,判断区域ID是否正确
            if (Reseller["AreaID"].ToString().Trim() != "" && Reseller["AreaID"].ToString() != "0")
            {
                Hi.Model.BD_DisArea disarea = new Hi.BLL.BD_DisArea().GetModel(Int32.Parse(Reseller["AreaID"].ToString().Trim()));
                if (disarea == null || disarea.CompanyID != comp.ID)
                {
                    return new ReseltResellerEdit()
                           {
                               Result = "F", Description = "经销商区域异常"
                           }
                }
                ;
                if (disarea.dr == 1)
                {
                    return new ReseltResellerEdit()
                           {
                               Result = "F", Description = "此经销商区域已被删除"
                           }
                }
                ;
                disModel.AreaID = disarea.ID;
            }
            else
            {
                disModel.AreaID = 0;
            }
            disModel.DisLevel = "";
            disModel.Province = Reseller["ResellerProvince"].ToString();
            disModel.City     = Reseller["ResellerCity"].ToString();
            disModel.Area     = Reseller["ResellerArea"].ToString();
            disModel.Address  = address;
            //没输入经销商中的联系人,需要将登录信息的姓名赋值给联系人
            string principal = Common.NoHTML(Reseller["Principal"].ToString().Trim());
            string phone     = Common.NoHTML(Reseller["Phone"].ToString().Trim());
            if (principal == "")
            {
                disModel.Principal = truename;
            }
            else
            {
                disModel.Principal = principal;
            }
            //没输入联系人手机号,需要将登录信息中的手机号赋值给联系人手机号
            if (phone == "")
            {
                disModel.Phone = account["Phone"].ToString();
            }
            else
            {
                disModel.Phone = phone;
            }
            disModel.Leading      = "";
            disModel.LeadingPhone = "";
            disModel.Licence      = "";
            disModel.Tel          = Common.NoHTML(Reseller["Tel"].ToString());
            disModel.Zip          = Common.NoHTML(Reseller["Zip"].ToString());
            disModel.Fax          = Common.NoHTML(Reseller["Fax"].ToString());
            disModel.Remark       = "";
            disModel.DisAccount   = 0;
            disModel.IsCheck      = 1;
            disModel.CreditType   = 0;
            disModel.CreditAmount = 0;
            disModel.Paypwd       = Common.md5("123456");
            disModel.AuditState   = 2;
            disModel.IsEnabled    = 1;
            disModel.CreateUserID = one.ID;
            disModel.CreateDate   = DateTime.Now;
            disModel.ts           = DateTime.Now;
            disModel.dr           = 0;
            disModel.modifyuser   = one.ID;
            //开启事务,并将dismodel插入经销商表中
            SqlConnection conn = new SqlConnection(SqlHelper.LocalSqlServer);
            //开启数据库连接
            if (conn.State.ToString().ToLower() != "open")
            {
                conn.Open();
            }
            //开启事务
            SqlTransaction mytran = conn.BeginTransaction();
            int            DisID  = 0;
            try
            {
                //在经销商表中插入一条数据
                if ((DisID = new Hi.BLL.BD_Distributor().Add(disModel, mytran)) > 0)
                {
                    //经销商表插入成功的话继续新增角色
                    List <Hi.Model.SYS_Role> list_role = new Hi.BLL.SYS_Role().GetList("", "isnull(dr,0)=0 and isenabled=1 and DisID=" + DisID + " and RoleName='企业管理员'", "");

                    if (list_role == null || list_role.Count == 0)
                    {
                        //新增角色(企业管理员)
                        Hi.Model.SYS_Role role = new Hi.Model.SYS_Role();
                        role.CompID       = comp.ID;
                        role.DisID        = DisID;
                        role.RoleName     = "企业管理员";
                        role.IsEnabled    = 1;
                        role.SortIndex    = "1";
                        role.CreateDate   = DateTime.Now;
                        role.CreateUserID = one.ID;
                        role.ts           = DateTime.Now;
                        role.modifyuser   = one.ID;
                        role.dr           = 0;
                        int Roid = new Hi.BLL.SYS_Role().Add(role, mytran);
                        //新增管理员用户和角色
                        Hi.Model.SYS_Users user = new Hi.Model.SYS_Users();
                        user.UserName = username;
                        // user.CompID = CompID;
                        // user.Type = 5;
                        // user.RoleID = Roid;
                        user.TrueName     = truename;
                        user.UserPwd      = Common.md5("123456");
                        user.Phone        = account["Phone"].ToString();
                        user.AuditState   = 2;
                        user.IsEnabled    = 1;
                        user.CreateUserID = one.ID;
                        user.CreateDate   = DateTime.Now;
                        user.ts           = DateTime.Now;
                        user.modifyuser   = one.ID;
                        int AddUserid = new Hi.BLL.SYS_Users().Add(user, mytran);
                        ///用户明细表
                        Hi.Model.SYS_CompUser CompUser = new Hi.Model.SYS_CompUser();
                        CompUser.CompID       = comp.ID;
                        CompUser.DisID        = DisID;
                        CompUser.CreateDate   = DateTime.Now;
                        CompUser.CreateUserID = one.ID;
                        CompUser.modifyuser   = one.ID;
                        CompUser.CType        = 2;
                        CompUser.UType        = 5;
                        CompUser.IsEnabled    = 1;
                        CompUser.IsAudit      = 2;
                        CompUser.RoleID       = 0;
                        CompUser.ts           = DateTime.Now;
                        CompUser.dr           = 0;
                        CompUser.UserID       = AddUserid;
                        int compuserid = new Hi.BLL.SYS_CompUser().Add(CompUser, mytran);
                        //新增角色用户
                        Hi.Model.SYS_RoleUser RoleUser = new Hi.Model.SYS_RoleUser();
                        RoleUser.FunType    = 1;
                        RoleUser.UserID     = AddUserid;
                        RoleUser.RoleID     = Roid;
                        RoleUser.IsEnabled  = true;
                        RoleUser.CreateUser = UserID;
                        RoleUser.CreateDate = DateTime.Now;
                        RoleUser.ts         = DateTime.Now;
                        RoleUser.dr         = 0;
                        int roleuserid = new Hi.BLL.SYS_RoleUser().Add(RoleUser, mytran);
                        //新增角色权限表
                        Hi.Model.SYS_RoleSysFun    rolesys = null;
                        List <Hi.Model.SYS_SysFun> funList = new Hi.BLL.SYS_SysFun().GetList("", " Type=2", "");
                        foreach (Hi.Model.SYS_SysFun sys in funList)
                        {
                            rolesys              = new Hi.Model.SYS_RoleSysFun();
                            rolesys.CompID       = comp.ID;
                            rolesys.DisID        = DisID;
                            rolesys.RoleID       = Roid;
                            rolesys.FunCode      = sys.FunCode;
                            rolesys.FunName      = sys.FunName;
                            rolesys.IsEnabled    = 1;
                            rolesys.CreateUserID = one.ID;
                            rolesys.CreateDate   = DateTime.Now;
                            rolesys.ts           = DateTime.Now;
                            rolesys.modifyuser   = one.ID;
                            if (new Hi.BLL.SYS_RoleSysFun().Add(rolesys, mytran) <= 0)
                            {
                                mytran.Rollback();
                                return(new ReseltResellerEdit()
                                {
                                    Result = "F", Description = "新增失败"
                                });
                            }
                        }
                        //新增收货地址
                        Hi.Model.BD_DisAddr addr = new Hi.Model.BD_DisAddr();
                        addr.Province     = disModel.Province;
                        addr.City         = disModel.City;
                        addr.Area         = disModel.Area;
                        addr.DisID        = DisID;
                        addr.Principal    = disModel.Principal;
                        addr.Phone        = disModel.Phone;
                        addr.Address      = disModel.Province + disModel.City + disModel.Area + disModel.Address;
                        addr.IsDefault    = 1;
                        addr.ts           = DateTime.Now;
                        addr.CreateDate   = DateTime.Now;
                        addr.CreateUserID = one.ID;
                        addr.modifyuser   = one.ID;
                        int addrid = new Hi.BLL.BD_DisAddr().Add(addr, mytran);
                        //判断所有表是否都插入成功了吗
                        if (Roid <= 0 || AddUserid <= 0 || compuserid <= 0 || roleuserid <= 0 || addrid <= 0)
                        {
                            mytran.Rollback();
                            return(new ReseltResellerEdit()
                            {
                                Result = "F", Description = "新增失败"
                            });
                        }
                    }
                    else
                    {
                        mytran.Rollback();
                        return(new ReseltResellerEdit()
                        {
                            Result = "F", Description = "新增失败"
                        });
                    }
                }
                else
                {
                    mytran.Rollback();
                    return(new ReseltResellerEdit()
                    {
                        Result = "F", Description = "新增失败"
                    });
                }
                mytran.Commit();
            }
            catch (Exception ex)
            {
                mytran.Rollback();
                Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "AddReseller:" + JSon);
                return(new ReseltResellerEdit()
                {
                    Result = "F", Description = "新增失败"
                });
            }
            finally
            {
                conn.Close();
                mytran.Dispose();
            }
            return(new ReseltResellerEdit()
            {
                Result = "T", Description = "新增成功"
            });
        }
        catch (Exception ex)
        {
            Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "AddReseller:" + JSon);
            return(new ReseltResellerEdit()
            {
                Result = "F", Description = "新增失败"
            });
        }
    }
Exemple #6
0
    /// <summary>
    /// 同步代理商基本档案方法
    /// </summary>
    public void DisTransfer(XmlDocument Doc, string Method)
    {
        Regex rgx = null;

        try
        {
            int       SumDisAdd     = 0;
            int       SumDisTB      = 0;
            int       SumTypeAdd    = 0;
            int       SumTypeTB     = 0;
            int       SumAddressAdd = 0;
            int       SumAddressTB  = 0;
            DataTable dt            = null;
            int       Disid         = 0;
            TranSaction = DBUtility.SqlHelper.CreateStoreTranSaction();

            if (Method == "InsertCusClass")
            {
                #region 代理商分类新增/同步方法

                XmlElement  elment   = Doc.DocumentElement;
                XmlNodeList nodeList = Doc.DocumentElement.SelectNodes("bill");
                foreach (XmlNode nodel in nodeList)
                {
                    XmlNode             nodel1     = nodel.SelectSingleNode("header");
                    string              TypeCode   = nodel1.SelectSingleNode("customerclasscode").InnerText.Trim();
                    string              ParentCode = nodel1.SelectSingleNode("customerclassprecode").InnerText.Trim();
                    string              TypeName   = nodel1.SelectSingleNode("customerclassname").InnerText.Trim();
                    Hi.Model.BD_DisType type       = null;
                    dt = ImportDisProD.GetDataSource("*", "BD_DisType", " and isnull(dr,0)=0 and TypeCode='" + TypeCode + "' and CompID=" + CompID + "", "", TranSaction);
                    if (dt.Rows.Count > 0)
                    {
                        if (string.IsNullOrWhiteSpace(TypeName))
                        {
                            CreateReturnXML(TypeCode, false, "分类(同步):分类名称为空");
                            SetErrorTb("分类(同步)", "分类名称为空【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        else if (string.IsNullOrWhiteSpace(TypeCode))
                        {
                            CreateReturnXML(TypeCode, false, "分类(同步):分类编码为空");
                            SetErrorTb("分类(同步)", "分类编码为空【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        else if ((FindTb = ImportDisProD.GetDataSource("1 name", "BD_DisType", " and isnull(dr,0)=0 and TypeName='" + TypeName + "' and Typecode<>'" + TypeCode + "' and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            CreateReturnXML(TypeCode, false, "分类(同步):分类名称已存在");
                            SetErrorTb("分类(同步)", "分类名称已存在【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        type          = Common.GetEntity <Hi.Model.BD_DisType>(dt);
                        type.TypeName = TypeName;
                        if (new Hi.BLL.BD_DisType().Update(type, TranSaction))
                        {
                            CreateReturnXML(TypeCode, true);
                            SumTypeTB++;
                        }
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(TypeName))
                        {
                            CreateReturnXML(TypeCode, false, "分类(新增):分类名称为空");
                            SetErrorTb("分类(新增)", "分类名称为空【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        else if (string.IsNullOrWhiteSpace(TypeCode))
                        {
                            CreateReturnXML(TypeCode, false, "分类(新增):分类编码为空");
                            SetErrorTb("分类(新增)", "分类编码为空【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        else if ((ImportDisProD.GetDataSource("1 name", "BD_DisType", " and isnull(dr,0)=0 and (TypeName='" + TypeName + "') and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            CreateReturnXML(TypeCode, false, "分类(新增):分类名称或编码已存在");
                            SetErrorTb("分类(新增)", "分类名称或编码已存在【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        if (!string.IsNullOrWhiteSpace(ParentCode))
                        {
                            FindTb = ImportDisProD.GetDataSource(" ID", "BD_DisType", " and isnull(dr,0)=0 and TypeCode='" + ParentCode + "' and CompID=" + CompID + "", "", TranSaction);
                            if (FindTb.Rows.Count > 0)
                            {
                                type              = new Hi.Model.BD_DisType();
                                type.CreateDate   = DateTime.Now;
                                type.CreateUserID = UserID;
                                type.IsEnabled    = 1;
                                type.modifyuser   = UserID;
                                type.TypeName     = TypeName;
                                type.TypeCode     = TypeCode;
                                type.ts           = DateTime.Now;
                                type.CompID       = CompID;
                                type.ParentId     = FindTb.Rows[0]["ID"].ToString().ToInt(0);
                                if (new Hi.BLL.BD_DisType().Add(type, TranSaction) > 0)
                                {
                                    CreateReturnXML(TypeCode, true);
                                    SumTypeAdd++;
                                }
                            }
                            else
                            {
                                CreateReturnXML(TypeCode, false, "分类(新增):查找不到父分类");
                                SetErrorTb("分类(新增)", "查找不到父分类,【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            }
                        }
                        else
                        {
                            type              = new Hi.Model.BD_DisType();
                            type.CreateDate   = DateTime.Now;
                            type.CreateUserID = UserID;
                            type.IsEnabled    = 1;
                            type.CompID       = CompID;
                            type.modifyuser   = UserID;
                            type.TypeName     = TypeName;
                            type.TypeCode     = TypeCode;
                            type.ts           = DateTime.Now;
                            type.ParentId     = 0;
                            if (new Hi.BLL.BD_DisType().Add(type, TranSaction) > 0)
                            {
                                CreateReturnXML(TypeCode, true);
                                SumTypeAdd++;
                            }
                        }
                    }
                }
                #endregion
            }
            else if (Method == "InsertDisArea")
            {
                #region  代理商地址新增/同步
                XmlElement elment = Doc.DocumentElement;
                rgx = new Regex(@"^0?1[0-9]{10}$");
                XmlNodeList nodeList1 = Doc.DocumentElement.SelectNodes("bill");
                foreach (XmlNode nodel2 in nodeList1)
                {
                    XmlNode nodel3    = nodel2.SelectSingleNode("header");
                    string  addcode   = nodel3.SelectSingleNode("addresscode").InnerText.Trim();
                    string  DisCode   = nodel3.SelectSingleNode("customercode").InnerText.Trim();
                    string  Principal = nodel3.SelectSingleNode("linkperson").InnerText.Trim();
                    string  Address   = nodel3.SelectSingleNode("address").InnerText.Trim();
                    string  Phone     = nodel3.SelectSingleNode("handphone").InnerText.Trim();
                    string  Tel       = nodel3.SelectSingleNode("phone").InnerText.Trim();
                    int     isdefault = nodel3.SelectSingleNode("default").InnerText.Trim().ToInt(0);
                    if ((FindTb = ImportDisProD.GetDataSource("ID", "BD_Distributor", " and isnull(dr,0)=0 and DisCode='" + DisCode + "' and CompID=" + CompID + " ", "", TranSaction)).Rows.Count == 0)
                    {
                        CreateReturnXML(addcode, false, "代理商地址:查找不到代理商,代理商编码:" + DisCode + "");
                        SetErrorTb("代理商地址", "查找不到代理商【地址:" + Address + ",地址编码:" + addcode + ",代理商编码:" + DisCode + "】");
                        continue;
                    }
                    Disid = FindTb.Rows[0]["ID"].ToString().ToInt(0);
                    dt    = ImportDisProD.GetDataSource("*", "BD_DisAddr", " and isnull(dr,0)=0 and Code='" + addcode + "' and Disid=" + Disid + "", "", TranSaction);
                    if (dt.Rows.Count > 0)
                    {
                        if (string.IsNullOrWhiteSpace(addcode))
                        {
                            CreateReturnXML(addcode, false, "代理商地址(同步):地址编码为空");
                            SetErrorTb("代理商地址(同步)", "地址编码为空【地址:" + Address + ",地址编码:" + addcode + "】");
                            continue;
                        }
                        else if (string.IsNullOrWhiteSpace(Principal))
                        {
                            //CreateReturnXML(addcode, false, "代理商地址(同步):联系人为空");
                            //SetErrorTb("代理商地址(同步)", "联系人为空【地址:" + Address + ",地址编码:" + addcode + "】");
                            //continue;
                            Principal = "";
                        }
                        else if (string.IsNullOrWhiteSpace(Address))
                        {
                            CreateReturnXML(addcode, false, "代理商地址(同步):地址为空");
                            SetErrorTb("代理商地址(同步)", "地址为空【地址:" + Address + ",地址编码:" + addcode + "】");
                            continue;
                        }
                        else if (!rgx.IsMatch(Phone))
                        {
                            //CreateReturnXML(addcode, false, "代理商地址(同步):手机格式不正确");
                            //SetErrorTb("代理商地址(同步)", "手机格式不正确【地址:" + Address + ",地址编码:" + addcode + "】");
                            //continue;
                            Phone = "";
                        }
                        Hi.Model.BD_DisAddr addr = Common.GetEntity <Hi.Model.BD_DisAddr>(dt);
                        addr.Address   = addr.Province + addr.City + addr.Area + Address;
                        addr.Principal = Principal;
                        addr.Phone     = Phone;
                        addr.Tel       = Tel;
                        addr.IsDefault = isdefault;
                        if (new Hi.BLL.BD_DisAddr().Update(addr, TranSaction))
                        {
                            CreateReturnXML(addcode, true);
                            SumAddressTB++;
                        }
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(addcode))
                        {
                            CreateReturnXML(addcode, false, "代理商地址(同步):地址编码为空");
                            SetErrorTb("代理商地址(新增)", "地址编码为空【地址:" + Address + ",地址编码:" + addcode + "】");
                            continue;
                        }
                        else if (string.IsNullOrWhiteSpace(Principal))
                        {
                            //CreateReturnXML(addcode, false, "代理商地址(同步):联系人为空");
                            //SetErrorTb("代理商地址(新增)", "联系人为空【地址:" + Address + ",地址编码:" + addcode + "】");
                            //continue;
                            Principal = "";
                        }
                        else if (string.IsNullOrWhiteSpace(Address))
                        {
                            CreateReturnXML(addcode, false, "代理商地址(同步):地址为空");
                            SetErrorTb("代理商地址(新增)", "地址为空【地址:" + Address + ",地址编码:" + addcode + "】");
                            continue;
                        }
                        else if (!rgx.IsMatch(Phone))
                        {
                            //CreateReturnXML(addcode, false, "代理商地址(同步):手机格式不正确");
                            //SetErrorTb("代理商地址(新增)", "手机格式不正确【地址:" + Address + ",地址编码:" + addcode + "】");
                            //continue;
                            Phone = "";
                        }
                        else if ((ImportDisProD.GetDataSource("1 name", "BD_DisAddr", " and isnull(dr,0)=0 and (Code='" + addcode + "') and Disid=" + Disid + "", "", TranSaction)).Rows.Count > 0)
                        {
                            CreateReturnXML(addcode, false, "代理商地址(同步):地址编码已存在");
                            SetErrorTb("代理商地址(新增)", "地址编码已存在【地址:" + Address + ",地址编码:" + addcode + "】");
                            continue;
                        }
                        Hi.Model.BD_DisAddr addr = new Hi.Model.BD_DisAddr();
                        addr.DisID        = Disid;
                        addr.Province     = "上海市";
                        addr.City         = "市辖区";
                        addr.Area         = "徐汇区";
                        addr.Code         = addcode;
                        addr.Address      = addr.Province + addr.City + addr.Area + Address;
                        addr.Phone        = Phone;
                        addr.Principal    = Principal;
                        addr.Tel          = Tel;
                        addr.IsDefault    = isdefault;
                        addr.CreateDate   = DateTime.Now;
                        addr.CreateUserID = UserID;
                        addr.ts           = DateTime.Now;
                        addr.modifyuser   = UserID;
                        if (new Hi.BLL.BD_DisAddr().Add(addr, TranSaction) > 0)
                        {
                            CreateReturnXML(addcode, true);
                            SumAddressAdd++;
                        }
                    }
                }
                #endregion
            }
            else if (Method == "InsertCus")
            {
                #region 代理商新增/同步

                XmlElement  elment   = Doc.DocumentElement;
                XmlNodeList nodeList = Doc.DocumentElement.SelectNodes("bill");
                foreach (XmlNode nodel in nodeList)
                {
                    XmlNode nodel1    = nodel.SelectSingleNode("header");
                    string  DisCode   = nodel1.SelectSingleNode("customercode").InnerText.Trim();
                    string  DisName   = nodel1.SelectSingleNode("customername").InnerText.Trim();
                    string  TypeCode  = IsSelectNode(nodel1, "customerclasscode") ? nodel1.SelectSingleNode("customerclasscode").InnerText.Trim() : "";
                    string  Address   = IsSelectNode(nodel1, "address") ? nodel1.SelectSingleNode("address").InnerText.Trim() : "";
                    string  Principal = IsSelectNode(nodel1, "person") ? nodel1.SelectSingleNode("person").InnerText.Trim() : "";
                    string  Phone     = IsSelectNode(nodel1, "handphone") ? nodel1.SelectSingleNode("handphone").InnerText.Trim() : "";
                    string  Leading   = IsSelectNode(nodel1, "lperson") ? nodel1.SelectSingleNode("lperson").InnerText.Trim() : "";
                    string  Tel       = IsSelectNode(nodel1, "phone") ? nodel1.SelectSingleNode("phone").InnerText.Trim() : "";
                    string  Zip       = IsSelectNode(nodel1, "postcode") ? nodel1.SelectSingleNode("postcode").InnerText.Trim() : "";
                    string  Fax       = IsSelectNode(nodel1, "fax") ? nodel1.SelectSingleNode("fax").InnerText.Trim() : "";
                    dt = ImportDisProD.GetDataSource("*", "BD_Distributor", " and isnull(dr,0)=0 and DisCode='" + DisCode + "' and CompID=" + CompID + " and AuditState=2", "", TranSaction);
                    if (dt.Rows.Count > 0)
                    {
                        rgx = new Regex(@"^0?1[0-9]{10}$");
                        if (string.IsNullOrWhiteSpace(DisName))
                        {
                            CreateReturnXML(TypeCode, false, "代理商(同步):代理商名称为空");
                            SetErrorTb("代理商(同步)", "代理商名称为空【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        else if (string.IsNullOrWhiteSpace(DisCode))
                        {
                            CreateReturnXML(TypeCode, false, "代理商(同步):代理商编码为空");
                            SetErrorTb("代理商(同步)", "代理商编码为空【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        else if (!rgx.IsMatch(Phone))
                        {
                            //CreateReturnXML(TypeCode, false, "代理商(同步):手机号码格式错误");
                            //SetErrorTb("代理商(同步)", "手机号码格式错误【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            //continue;
                            Phone = "";
                        }
                        else if ((ImportDisProD.GetDataSource("1 name", "BD_Distributor", " and isnull(dr,0)=0 and (DisName='" + DisName + "' and DisCode<>'" + DisCode + "') and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            CreateReturnXML(TypeCode, false, "代理商(同步):代理商名称已存在");
                            SetErrorTb("代理商(同步)", "代理商名称已存在【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        Hi.Model.BD_Distributor Dis = Common.GetEntity <Hi.Model.BD_Distributor>(dt);
                        Dis.DisName = DisName;
                        if ((FindTb = ImportDisProD.GetDataSource("ID", "BD_DisType", " and isnull(dr,0)=0 and TypeCode='" + TypeCode + "' and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            Dis.DisTypeID = FindTb.Rows[0]["ID"].ToString().ToInt(0);
                        }
                        Dis.Address      = Address;
                        Dis.Principal    = Principal;
                        Dis.Leading      = Leading;
                        Dis.Phone        = Phone;
                        Dis.LeadingPhone = Phone;
                        Dis.Tel          = Tel;
                        Dis.Zip          = Zip;
                        Dis.Fax          = Fax;
                        if (new Hi.BLL.BD_Distributor().Update(Dis, TranSaction))
                        {
                            CreateReturnXML(TypeCode, true);
                            SumDisTB++;
                        }
                    }
                    else
                    {
                        rgx = new Regex(@"^0?1[0-9]{10}$");
                        if (string.IsNullOrWhiteSpace(DisName))
                        {
                            CreateReturnXML(TypeCode, false, "代理商(新增):代理商名称为空");
                            SetErrorTb("代理商(新增)", "代理商名称为空【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        else if (string.IsNullOrWhiteSpace(DisCode))
                        {
                            CreateReturnXML(TypeCode, false, "代理商(新增):代理商编码为空");
                            SetErrorTb("代理商(新增)", "代理商编码为空【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        else if (!rgx.IsMatch(Phone))
                        {
                            //CreateReturnXML(TypeCode, false, "代理商(新增):手机号码格式错误");
                            //SetErrorTb("代理商(新增)", "手机号码格式错误【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            //continue;
                            Phone = "";
                        }
                        else if ((ImportDisProD.GetDataSource("1 name", "SYS_Users", " and isnull(dr,0)=0 and (Phone='" + Phone + "' and isnull(Phone,'')<>'')", "", TranSaction)).Rows.Count > 0)
                        {
                            CreateReturnXML(TypeCode, false, "代理商(新增):代理商手机号码已存在");
                            SetErrorTb("代理商(新增)", "代理商手机号码已存在【代理商名称:" + DisName + ",代理商编码:" + DisCode + ",手机号码:" + Phone + "】");
                            continue;
                        }
                        else if ((ImportDisProD.GetDataSource("1 name", "BD_Distributor", " and isnull(dr,0)=0 and (DisName='" + DisName + "') and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            CreateReturnXML(TypeCode, false, "代理商(新增):代理商名称/编码已存在");
                            SetErrorTb("代理商(新增)", "代理商名称/编码已存在【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        Hi.Model.BD_Distributor Dis = new Hi.Model.BD_Distributor();
                        Dis.DisName = DisName;
                        Dis.DisCode = DisCode;
                        if ((FindTb = ImportDisProD.GetDataSource("ID", "BD_DisType", " and isnull(dr,0)=0 and TypeCode='" + TypeCode + "' and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            Dis.DisTypeID = FindTb.Rows[0]["ID"].ToString().ToInt(0);
                        }
                        Dis.Address      = Address;
                        Dis.Province     = "上海市";
                        Dis.City         = "市辖区";
                        Dis.Area         = "徐汇区";
                        Dis.Principal    = Principal;
                        Dis.Leading      = Leading;
                        Dis.Phone        = Phone;
                        Dis.LeadingPhone = Phone;
                        Dis.Tel          = Tel;
                        Dis.Zip          = Zip;
                        Dis.Fax          = Fax;
                        Dis.SMID         = 0;
                        Dis.IsCheck      = 0;
                        Dis.CreditType   = 0;
                        Dis.AuditState   = 2;
                        Dis.AuditUser    = UserID.ToString();
                        Dis.CompID       = CompID;
                        Dis.AuditDate    = DateTime.Now;
                        Dis.CreateDate   = DateTime.Now;
                        Dis.CreateUserID = UserID;
                        Dis.ts           = DateTime.Now;
                        Dis.modifyuser   = UserID;
                        Dis.IsEnabled    = 1;
                        Dis.Paypwd       = Util.md5("123456");
                        Dis.Remark       = "";
                        Hi.Model.SYS_Users user = new Hi.Model.SYS_Users();
                        if ((Disid = new Hi.BLL.BD_Distributor().Add(Dis, TranSaction)) > 0)
                        {
                            CreateReturnXML(TypeCode, true);
                            user.UserName     = Enum.GetName(typeof(Enums.Erptype), Erptype) + DisCode;
                            user.UserPwd      = Util.md5("123456");
                            user.IsEnabled    = 1;
                            user.AuditState   = 2;
                            user.IsFirst      = 0;
                            user.Type         = 5;
                            user.CompID       = CompID;
                            user.DisID        = Disid;
                            user.AddType      = 0;
                            user.Phone        = Phone;
                            user.TrueName     = Principal;
                            user.Tel          = Tel;
                            user.RoleID       = 0;
                            user.CreateDate   = DateTime.Now;
                            user.CreateUserID = UserID;
                            user.ts           = DateTime.Now;
                            user.modifyuser   = UserID;
                            if (new Hi.BLL.SYS_Users().Add(user, TranSaction) > 0)
                            {
                                SumDisAdd++;
                            }
                        }
                    }
                }
                #endregion
            }
            else
            {
                ReturnBill = "";
                ErrTb.Rows.Clear();
                CreateReturnXML("", false, "导入类型异常");
                SetErrorTb("", "导入类型异常");
                return;
            }
            TranSaction.Commit();
            LogManager.WriteLog2(LogFile.Trace.ToString(), "新增(代理商:" + SumDisAdd + "条;类别:" + SumTypeAdd + "条;地址:" + SumAddressAdd + "条),同步(代理商:" + SumDisTB + "条;类别:" + SumTypeTB + "条;地址:" + SumAddressTB + "条)");
        }
        catch (Exception ex)
        {
            ReturnBill = "";
            ErrTb.Rows.Clear();
            if (ex is XmlException)
            {
                CreateReturnXML("", false, "读取XML出现错误");
                SetErrorTb("", "读取XML出现错误");
            }
            else if (ex is XPathException)
            {
                CreateReturnXML("", false, "格式错误");
                SetErrorTb("", "XML格式错误");
            }
            else
            {
                CreateReturnXML("", false, ex.Message);
                SetErrorTb("", "同步失败:" + ex.Message + "");
            }
            if (TranSaction != null)
            {
                if (TranSaction.Connection != null)
                {
                    TranSaction.Rollback();
                }
            }
        }
        finally
        {
            if (TranSaction != null)
            {
                if (TranSaction.Connection != null)
                {
                    TranSaction.Rollback();
                }
            }
            TableWriteLog();
        }
    }
Exemple #7
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Hi.Model.BD_DisAddr model)
 {
     return(dal.Update(model));
 }
Exemple #8
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Hi.Model.BD_DisAddr model)
 {
     return(dal.Add(model));
 }
Exemple #9
0
    protected void btnDisTransfer_Click(object sender, EventArgs e)
    {
        SqlTransaction TranSaction = null;
        Regex          rgx         = null;
        string         ShowStr     = "<i style='color:red;'>{0}</i>";

        try
        {
            int SumDisAdd     = 0;
            int SumDisTB      = 0;
            int SumTypeAdd    = 0;
            int SumTypeTB     = 0;
            int SumAddressAdd = 0;
            int SumAddressTB  = 0;
            #region 代理商分类新增/同步方法
            XmlDocument Xdoc = null;//ImportDisProD.GetServiceXmlStr(Enum.GetName(typeof(Enums.Erptype), Erptype), "GetCusClass", "获取代理商分类");
            TranSaction = DBUtility.SqlHelper.CreateStoreTranSaction();
            XmlElement elment = Xdoc.DocumentElement;
            if (elment.GetAttribute("result") == "True")
            {
                XmlNodeList nodeList = Xdoc.DocumentElement.SelectNodes("bill");
                foreach (XmlNode nodel in nodeList)
                {
                    XmlNode             nodel1     = nodel.SelectSingleNode("header");
                    string              TypeCode   = nodel1.SelectSingleNode("customerclasscode").InnerText.Trim();
                    string              ParentCode = nodel1.SelectSingleNode("customerclassprecode").InnerText.Trim();
                    string              TypeName   = nodel1.SelectSingleNode("customerclassprecode").InnerText.Trim();
                    Hi.Model.BD_DisType type       = null;
                    DataTable           dt         = ImportDisProD.GetDataSource("*", "BD_DisType", " and isnull(dr,0)=0 and TypeCode='" + TypeCode + "' and CompID=" + CompID + "", "", TranSaction);
                    if (dt.Rows.Count > 0)
                    {
                        if (string.IsNullOrWhiteSpace(TypeName))
                        {
                            SetErrorTb("分类(同步)", "分类名称为空【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        else if (string.IsNullOrWhiteSpace(TypeCode))
                        {
                            SetErrorTb("分类(同步)", "分类编码为空【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        else if ((FindTb = ImportDisProD.GetDataSource("1 name", "BD_DisType", " and isnull(dr,0)=0 and TypeName='" + TypeName + "' and Typecode<>'" + TypeCode + "' and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            SetErrorTb("分类(同步)", "分类名称已存在【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        type          = Common.GetEntity <Hi.Model.BD_DisType>(dt);
                        type.TypeName = TypeName;
                        if (new Hi.BLL.BD_DisType().Update(type, TranSaction))
                        {
                            SumTypeTB++;
                        }
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(TypeName))
                        {
                            SetErrorTb("分类(新增)", "分类名称为空【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        else if (string.IsNullOrWhiteSpace(TypeCode))
                        {
                            SetErrorTb("分类(新增)", "分类编码为空【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        else if ((ImportDisProD.GetDataSource("1 name", "BD_DisType", " and isnull(dr,0)=0 and (TypeName='" + TypeName + "' or Typecode='" + TypeCode + "') and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            SetErrorTb("分类(新增)", "分类名称或编码已存在【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            continue;
                        }
                        if (!string.IsNullOrWhiteSpace(ParentCode))
                        {
                            FindTb = ImportDisProD.GetDataSource(" ID", "BD_DisType", " and isnull(dr,0)=0 and TypeCode='" + ParentCode + "' and CompID=" + CompID + "", "", TranSaction);
                            if (FindTb.Rows.Count > 0)
                            {
                                type              = new Hi.Model.BD_DisType();
                                type.CreateDate   = DateTime.Now;
                                type.CreateUserID = UserID;
                                type.IsEnabled    = 1;
                                type.modifyuser   = UserID;
                                type.TypeName     = TypeName;
                                type.TypeCode     = TypeCode;
                                type.ts           = DateTime.Now;
                                type.CompID       = CompID;
                                type.ParentId     = FindTb.Rows[0]["ID"].ToString().ToInt(0);
                                if (new Hi.BLL.BD_DisType().Add(type) > 0)
                                {
                                    SumTypeAdd++;
                                }
                            }
                            else
                            {
                                SetErrorTb("分类(新增)", "查找不到父分类,【分类名称:" + TypeName + ",分类编码:" + TypeCode + "】");
                            }
                        }
                        else
                        {
                            type              = new Hi.Model.BD_DisType();
                            type.CreateDate   = DateTime.Now;
                            type.CreateUserID = UserID;
                            type.IsEnabled    = 1;
                            type.CompID       = CompID;
                            type.modifyuser   = UserID;
                            type.TypeName     = TypeName;
                            type.TypeCode     = TypeCode;
                            type.ts           = DateTime.Now;
                            type.ParentId     = 0;
                            if (new Hi.BLL.BD_DisType().Add(type) > 0)
                            {
                                SumTypeAdd++;
                            }
                        }
                    }
                }
            }
            else
            {
                throw new ApplicationException("获取分类错误:" + elment.GetAttribute("err"));
            }
            #endregion

            #region  代理商(地址)新增/同步方法

            #region 代理商新增/同步
            Xdoc   = null;//ImportDisProD.GetServiceXmlStr(Enum.GetName(typeof(Enums.Erptype), Erptype), "GetCus", "获取代理商档案");
            elment = Xdoc.DocumentElement;
            if (elment.GetAttribute("result") == "True")
            {
                XmlNodeList nodeList = Xdoc.DocumentElement.SelectNodes("bill");
                foreach (XmlNode nodel in nodeList)
                {
                    XmlNode   nodel1    = nodel.SelectSingleNode("header");
                    string    DisCode   = nodel1.SelectSingleNode("customercode").InnerText.Trim();
                    string    DisName   = nodel1.SelectSingleNode("customername").InnerText.Trim();
                    string    TypeCode  = nodel1.SelectSingleNode("customerclasscode").InnerText.Trim();
                    string    Address   = nodel1.SelectSingleNode("address").InnerText.Trim();
                    string    Principal = nodel1.SelectSingleNode("person").InnerText.Trim();
                    string    Phone     = nodel1.SelectSingleNode("handphone").InnerText.Trim();
                    string    Leading   = nodel1.SelectSingleNode("lperson").InnerText.Trim();
                    string    Tel       = nodel1.SelectSingleNode("phone").InnerText.Trim();
                    string    Zip       = nodel1.SelectSingleNode("postcode").InnerText.Trim();
                    string    Fax       = nodel1.SelectSingleNode("fax").InnerText.Trim();
                    int       Disid     = 0;
                    DataTable dt        = ImportDisProD.GetDataSource("*", "BD_Distributor", " and isnull(dr,0)=0 and DisCode='" + DisCode + "' and CompID=" + CompID + " and AuditState=2", "", TranSaction);
                    if (dt.Rows.Count > 0)
                    {
                        rgx = new Regex(@"^0?1[0-9]{10}$");
                        if (string.IsNullOrWhiteSpace(DisName))
                        {
                            SetErrorTb("代理商(同步)", "代理商名称为空【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        else if (string.IsNullOrWhiteSpace(DisCode))
                        {
                            SetErrorTb("代理商(同步)", "代理商编码为空【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        else if (!rgx.IsMatch(Phone))
                        {
                            SetErrorTb("代理商(同步)", "手机号码格式错误【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        else if ((ImportDisProD.GetDataSource("1 name", "BD_Distributor", " and isnull(dr,0)=0 and (DisName='" + DisName + "' and DisCode<>'" + DisCode + "') and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            SetErrorTb("代理商(同步)", "代理商名称已存在【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        Hi.Model.BD_Distributor Dis = Common.GetEntity <Hi.Model.BD_Distributor>(dt);
                        Disid       = Dis.ID;
                        Dis.DisName = DisName;
                        if ((FindTb = ImportDisProD.GetDataSource("ID", "BD_DisType", " and isnull(dr,0)=0 and TypeCode='" + TypeCode + "' and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            Dis.DisTypeID = FindTb.Rows[0]["ID"].ToString().ToInt(0);
                        }
                        Dis.Address      = Address;
                        Dis.Principal    = Principal;
                        Dis.Leading      = Leading;
                        Dis.Phone        = Phone;
                        Dis.LeadingPhone = Phone;
                        Dis.Tel          = Tel;
                        Dis.Zip          = Zip;
                        Dis.Fax          = Fax;
                        if (new Hi.BLL.BD_Distributor().Update(Dis, TranSaction))
                        {
                            SumDisTB++;
                        }
                    }
                    else
                    {
                        rgx = new Regex(@"^0?1[0-9]{10}$");
                        if (string.IsNullOrWhiteSpace(DisName))
                        {
                            SetErrorTb("代理商(新增)", "代理商名称为空【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        else if (string.IsNullOrWhiteSpace(DisCode))
                        {
                            SetErrorTb("代理商(新增)", "代理商编码为空【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        else if (!rgx.IsMatch(Phone))
                        {
                            SetErrorTb("代理商(新增)", "手机号码格式错误【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        else if ((ImportDisProD.GetDataSource("1 name", "SYS_Users", " and isnull(dr,0)=0 and (Phone='" + Phone + "')", "", TranSaction)).Rows.Count > 0)
                        {
                            SetErrorTb("代理商(新增)", "代理商手机号码已存在【代理商名称:" + DisName + ",代理商编码:" + DisCode + ",手机号码:" + Phone + "】");
                            continue;
                        }
                        else if ((ImportDisProD.GetDataSource("1 name", "BD_Distributor", " and isnull(dr,0)=0 and (DisName='" + DisName + "' or DisCode='" + DisCode + "') and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            SetErrorTb("代理商(新增)", "代理商名称/编码已存在【代理商名称:" + DisName + ",代理商编码:" + DisCode + "】");
                            continue;
                        }
                        Hi.Model.BD_Distributor Dis = new Hi.Model.BD_Distributor();
                        Dis.DisName = DisName;
                        Dis.DisCode = DisCode;
                        if ((FindTb = ImportDisProD.GetDataSource("ID", "BD_DisType", " and isnull(dr,0)=0 and TypeCode='" + TypeCode + "' and CompID=" + CompID + "", "", TranSaction)).Rows.Count > 0)
                        {
                            Dis.DisTypeID = FindTb.Rows[0]["ID"].ToString().ToInt(0);
                        }
                        Dis.Address      = Address;
                        Dis.Province     = "上海市";
                        Dis.City         = "市辖区";
                        Dis.Area         = "徐汇区";
                        Dis.Principal    = Principal;
                        Dis.Leading      = Leading;
                        Dis.Phone        = Phone;
                        Dis.LeadingPhone = Phone;
                        Dis.Tel          = Tel;
                        Dis.Zip          = Zip;
                        Dis.Fax          = Fax;
                        Dis.SMID         = 0;
                        Dis.IsCheck      = 0;
                        Dis.CreditType   = 0;
                        Dis.AuditState   = 2;
                        Dis.AuditUser    = UserID.ToString();
                        Dis.CompID       = CompID;
                        Dis.AuditDate    = DateTime.Now;
                        Dis.CreateDate   = DateTime.Now;
                        Dis.CreateUserID = UserID;
                        Dis.ts           = DateTime.Now;
                        Dis.modifyuser   = UserID;
                        Dis.IsEnabled    = 1;
                        Dis.Paypwd       = Util.md5("123456");
                        Dis.Remark       = "";
                        Hi.Model.SYS_Users user = new Hi.Model.SYS_Users();
                        if ((Disid = new Hi.BLL.BD_Distributor().Add(Dis, TranSaction)) > 0)
                        {
                            user.UserName     = Enum.GetName(typeof(Enums.Erptype), Erptype) + DisCode;
                            user.UserPwd      = Util.md5("123456");
                            user.IsEnabled    = 1;
                            user.IsFirst      = 0;
                            user.Type         = 5;
                            user.CompID       = CompID;
                            user.DisID        = Disid;
                            user.AddType      = 0;
                            user.Phone        = Phone;
                            user.TrueName     = Principal;
                            user.Tel          = Tel;
                            user.RoleID       = 0;
                            user.CreateDate   = DateTime.Now;
                            user.CreateUserID = UserID;
                            user.ts           = DateTime.Now;
                            user.modifyuser   = UserID;
                            if (new Hi.BLL.SYS_Users().Add(user, TranSaction) > 0)
                            {
                                SumDisAdd++;
                            }
                        }
                    }
                    #endregion

                    #region  代理商地址新增/同步
                    string      XMLbody = "<bill><header><customercode>" + DisCode + "</customercode></header></bill>";
                    XmlDocument Doc1    = null;//ImportDisProD.GetServiceXmlStr(Enum.GetName(typeof(Enums.Erptype), Erptype), "GetCusAddress", "获取代理商收货地址", XMLbody);
                    elment = Xdoc.DocumentElement;
                    if (elment.GetAttribute("result") == "True")
                    {
                        rgx = new Regex(@"^0?1[0-9]{10}$");
                        XmlNodeList nodeList1 = Xdoc.DocumentElement.SelectNodes("bill");
                        foreach (XmlNode nodel2 in nodeList1)
                        {
                            XmlNode nodel3  = nodel2.SelectSingleNode("header");
                            string  addcode = nodel3.SelectSingleNode("addresscode").InnerText.Trim();
                            Principal = nodel3.SelectSingleNode("linkperson").InnerText.Trim();
                            Address   = nodel3.SelectSingleNode("address").InnerText.Trim();
                            Phone     = nodel3.SelectSingleNode("handphone").InnerText.Trim();
                            Tel       = nodel3.SelectSingleNode("phone").InnerText.Trim();
                            int isdefault = nodel3.SelectSingleNode("default").InnerText.Trim().ToInt(0);
                            dt = ImportDisProD.GetDataSource("*", "BD_DisAddr", " and isnull(dr,0)=0 and Code='" + addcode + "' and Disid=" + Disid + "", "", TranSaction);
                            if (dt.Rows.Count > 0)
                            {
                                if (string.IsNullOrWhiteSpace(addcode))
                                {
                                    SetErrorTb("代理商地址(同步)", "地址编码为空【地址:" + Address + ",地址编码:" + addcode + "】");
                                    continue;
                                }
                                else if (string.IsNullOrWhiteSpace(Principal))
                                {
                                    SetErrorTb("代理商地址(同步)", "联系人为空【地址:" + Address + ",地址编码:" + addcode + "】");
                                    continue;
                                }
                                else if (string.IsNullOrWhiteSpace(Address))
                                {
                                    SetErrorTb("代理商地址(同步)", "地址为空【地址:" + Address + ",地址编码:" + addcode + "】");
                                    continue;
                                }
                                else if (!rgx.IsMatch(Phone))
                                {
                                    SetErrorTb("代理商地址(同步)", "手机格式不正确【地址:" + Address + ",地址编码:" + addcode + "】");
                                    continue;
                                }
                                Hi.Model.BD_DisAddr addr = Common.GetEntity <Hi.Model.BD_DisAddr>(dt);
                                addr.Address   = Address;
                                addr.Principal = Principal;
                                addr.Phone     = Phone;
                                addr.Tel       = Tel;
                                addr.IsDefault = isdefault;
                                if (new Hi.BLL.BD_DisAddr().Update(addr, TranSaction))
                                {
                                    SumAddressTB++;
                                }
                            }
                            else
                            {
                                if (string.IsNullOrWhiteSpace(addcode))
                                {
                                    SetErrorTb("代理商地址(新增)", "地址编码为空【地址:" + Address + ",地址编码:" + addcode + "】");
                                    continue;
                                }
                                else if (string.IsNullOrWhiteSpace(Principal))
                                {
                                    SetErrorTb("代理商地址(新增)", "联系人为空【地址:" + Address + ",地址编码:" + addcode + "】");
                                    continue;
                                }
                                else if (string.IsNullOrWhiteSpace(Address))
                                {
                                    SetErrorTb("代理商地址(新增)", "地址为空【地址:" + Address + ",地址编码:" + addcode + "】");
                                    continue;
                                }
                                else if (!rgx.IsMatch(Phone))
                                {
                                    SetErrorTb("代理商地址(新增)", "手机格式不正确【地址:" + Address + ",地址编码:" + addcode + "】");
                                    continue;
                                }
                                else if ((ImportDisProD.GetDataSource("1 name", "BD_DisAddr", " and isnull(dr,0)=0 and (Code='" + addcode + "') and Disid=" + Disid + "", "", TranSaction)).Rows.Count > 0)
                                {
                                    SetErrorTb("代理商地址(新增)", "地址编码已存在【地址:" + Address + ",地址编码:" + addcode + "】");
                                    continue;
                                }
                                Hi.Model.BD_DisAddr addr = new Hi.Model.BD_DisAddr();
                                addr.DisID        = Disid;
                                addr.Province     = "上海市";
                                addr.City         = "市辖区";
                                addr.Area         = "徐汇区";
                                addr.Code         = addcode;
                                addr.Address      = Address;
                                addr.Phone        = Phone;
                                addr.Principal    = Principal;
                                addr.Tel          = Tel;
                                addr.IsDefault    = isdefault;
                                addr.CreateDate   = DateTime.Now;
                                addr.CreateUserID = UserID;
                                addr.ts           = DateTime.Now;
                                addr.modifyuser   = UserID;
                                if (new Hi.BLL.BD_DisAddr().Add(addr) > 0)
                                {
                                    SumAddressAdd++;
                                }
                            }
                        }
                    }

                    #endregion
                }
            }

            #endregion
            TranSaction.Commit();
            lblDisIpResult.InnerHtml = "新增(代理商:" + string.Format(ShowStr, SumDisAdd) + "条;类别:" + string.Format(ShowStr, SumTypeAdd) + "条;地址:" + string.Format(ShowStr, SumAddressAdd) + "条),同步(代理商:" + string.Format(ShowStr, SumDisTB) + "条;类别:" + string.Format(ShowStr, SumTypeTB) + "条;地址:" + string.Format(ShowStr, SumAddressTB) + "条)";
            if (ErrTb.Rows.Count > 0)
            {
                HERCount.InnerText   = ErrTb.Rows.Count.ToString();
                DivError.Visible     = true;
                Rpt_Error.DataSource = ErrTb;
                Rpt_Error.DataBind();
            }
        }
        catch (Exception ex)
        {
            if (ex is XmlException)
            {
                lblDisIpResult.InnerHtml = string.Format(ShowStr, "读取XML出现错误");
            }
            else if (ex is XPathException)
            {
                lblDisIpResult.InnerHtml = string.Format(ShowStr, "XML格式错误");
            }
            else
            {
                lblDisIpResult.InnerHtml = string.Format(ShowStr, "同步失败:" + ex.Message + "");
            }
            if (TranSaction != null)
            {
                if (TranSaction.Connection != null)
                {
                    TranSaction.Rollback();
                }
            }
        }
    }