Ejemplo n.º 1
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string Typename = Common.NoHTML(txtTypeName.Value.Trim());
        string Parentid = Common.NoHTML(hideTypeId.Value.Trim());
        string sortid   = NewCateId().ToString();

        //string Typecode = txtTypecode.Value.Trim();
        Hi.Model.BD_DisType DisType = new Hi.Model.BD_DisType();
        int Result = 0;

        if (string.IsNullOrEmpty(Typename))
        {
            JScript.AlertMethod(this, "分类名称不能为空", JScript.IconOption.错误, "function (){ location.replace('" + ("DisTypeList.aspx?page=" + Pager.CurrentPageIndex + "") + "'); }");
            return;
        }
        if (IsExistsType("TypeName", Typename))
        {
            JScript.AlertMethod(this, "此分类名已存在", JScript.IconOption.错误, "function (){ location.replace('" + ("DisTypeList.aspx?page=" + Pager.CurrentPageIndex + "") + "'); }");
            return;
        }
        if (string.IsNullOrEmpty(Parentid) || !int.TryParse(Parentid, out Result))
        {
            DisType.ParentId = 0;
        }
        else
        {
            DisType.ParentId = Result;
        }
        DisType.CompID   = CompID;
        DisType.TypeName = Typename;
        //DisType.TypeCode = Typecode;
        DisType.SortIndex    = sortid;
        DisType.CreateDate   = DateTime.Now;
        DisType.CreateUserID = 0;
        DisType.ts           = DateTime.Now;
        DisType.modifyuser   = 0;
        if (new Hi.BLL.BD_DisType().Add(DisType) > 0)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>location.href='DisTypeList.aspx?page=" + Pager.CurrentPageIndex + "&lefttype=" + Request["lefttype"] + "&type=" + Request["type"] + "';</script>");
        }
        else
        {
            JScript.AlertMethod(this, "添加失败", JScript.IconOption.错误, "function (){ location.replace('" + ("DisTypeList.aspx?page=" + Pager.CurrentPageIndex + "") + "'); }");
        }
    }
Ejemplo n.º 2
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();
        }
    }
Ejemplo n.º 3
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (KeyID > 0)
        {
            bool Audit = false;
            Hi.Model.BD_Company comp = new Hi.BLL.BD_Company().GetModel(KeyID);
            if (comp != null)
            {
                if (comp.dr == 1)
                {
                    JScript.AlertMsg(this, "厂商不存在!。");
                    return;
                }
                string         str  = string.Empty;
                SqlTransaction Tran = null;
                try
                {
                    if (comp.AuditState == 2)
                    {
                        Audit = true;
                    }
                    if (Common.CompExistsAttribute("CompName", txtCompName.Value.Trim(), KeyID.ToString()))
                    {
                        JScript.AlertMsg(this, "该厂商名称已存在。");
                        return;
                    }
                    string CompAddr = hidProvince.Value.Trim();
                    if (!string.IsNullOrWhiteSpace(hidCity.Value.Trim()) && hidCity.Value.Trim() != "选择市")
                    {
                        CompAddr += "-" + hidCity.Value.Trim();
                    }
                    if (!string.IsNullOrWhiteSpace(hidArea.Value.Trim()) && hidArea.Value.Trim() != "选择区")
                    {
                        CompAddr += "-" + hidArea.Value.Trim();
                    }
                    comp.CompAddr = CompAddr;
                    comp.CompName = Common.NoHTML(txtCompName.Value.Trim());
                    comp.Capital  = Capital.Value.Trim();
                    comp.CompType = Convert.ToInt32(CompType.SelectedValue);
                    comp.Tel      = Common.NoHTML(txtTel.Value.Trim());
                    if (txtPrincipal.Value.Trim() != "")
                    {
                        comp.Principal = Common.NoHTML(txtPrincipal.Value.Trim());
                    }
                    else
                    {
                        comp.Principal = Common.NoHTML(txtUserTrueName.Value.Trim());
                    }
                    comp.Legal = Common.NoHTML(txtLegal.Value.Trim());
                    if (txtPhone.Value.Trim() != "")
                    {
                        comp.Phone = Common.NoHTML(txtPhone.Value.Trim());
                    }
                    else
                    {
                        comp.Phone = Common.NoHTML(txtUserPhone.Value.Trim());
                    }
                    comp.ShortName  = Common.NoHTML(txtShotName.Value.Trim());
                    comp.Zip        = Common.NoHTML(txtZip.Value.Trim());
                    comp.Identitys  = Common.NoHTML(txtIdentitys.Value.Trim());
                    comp.Licence    = Common.NoHTML(txtLicence.Value.Trim());
                    comp.LegalTel   = Common.NoHTML(txtLegalTel.Value.Trim());
                    comp.ManageInfo = Common.NoHTML(txtInfo.Value.Trim());
                    comp.Fax        = Common.NoHTML(txtFax.Value.Trim());
                    comp.Account    = Common.NoHTML(txtAccount.Value.Trim());
                    comp.Address    = Common.NoHTML(txtAddress.Value.Trim());
                    comp.IndID      = txtIndusName.SelectedValue.ToInt(0);
                    comp.Trade      = txtIndusName.Items[txtIndusName.SelectedIndex].Text;
                    comp.AuditState = 2;
                    comp.AuditDate  = DateTime.Now;//add by hgh 审核日期
                    comp.AuditUser  = UserID.ToString();

                    comp.ts               = DateTime.Now;
                    comp.modifyuser       = UserID;
                    comp.OrganizationCode = Common.NoHTML(txtOrcode.Value.Trim());
                    comp.IsEnabled        = rdEbleYes.Checked ? 1 : 0;
                    comp.HotShow          = rdHotShowYes.Checked ? 1 : 0;
                    comp.FirstShow        = Convert.ToInt32(ddlChkShow.SelectedValue);// rdFirstShowYes.Checked ? 1 : 0;
                    comp.Remark           = Common.NoHTML(txtRemark.Value.Trim());
                    comp.Erptype          = ddlErptype.SelectedValue.ToInt(0);
                    //企业编号  add by hgh
                    comp.CompCode = Common.CreateCode(KeyID);
                    if (HidFfileName.Value != "")
                    {
                        if (string.IsNullOrEmpty(comp.Attachment))
                        {
                            comp.Attachment = HidFfileName.Value;
                        }
                        else
                        {
                            comp.Attachment += "," + HidFfileName.Value;
                        }
                    }
                    List <Hi.Model.SYS_CompUser> ListComp = new Hi.BLL.SYS_CompUser().GetList("", " dr=0 and Ctype=1 and Utype=4 and CompID=" + KeyID + "", "");
                    if (ListComp.Count > 0)
                    {
                        Tran  = DBUtility.SqlHelper.CreateStoreTranSaction();
                        Audit = ListComp[0].IsAudit == 2;
                        if (Audit)
                        {
                            List <Hi.Model.BD_Distributor> dis = new Hi.BLL.BD_Distributor().GetList("", " isnull(dr,0)=0 and compid=" + KeyID + "", "");
                            foreach (Hi.Model.BD_Distributor model2 in dis)
                            {
                                model2.IsEnabled  = comp.IsEnabled;
                                model2.ts         = DateTime.Now;
                                model2.modifyuser = UserID;
                                new Hi.BLL.BD_Distributor().Update(model2, Tran);
                            }
                            new Hi.BLL.BD_Company().Update(comp, Tran);
                            List <Hi.Model.SYS_Users> user = new Hi.BLL.SYS_Users().GetList("", " isnull(dr,0)=0 and id=" + ListComp[0].UserID + " ", "");
                            if (user.Count > 0)
                            {
                                user[0].TrueName   = Common.NoHTML(txtUserTrueName.Value.Trim());
                                user[0].ts         = DateTime.Now;
                                user[0].modifyuser = UserID;
                                new Hi.BLL.SYS_Users().Update(user[0], Tran);
                            }
                            Tran.Commit();
                            Response.Redirect("CompInfo.aspx?go=1&KeyID=" + KeyID + "&type=5", false);
                        }
                        else
                        {
                            if (UserType == 3 || UserType == 4)
                            {
                                comp.OrgID      = OrgID;
                                comp.SalesManID = SalesManID;
                            }
                            if ((new Hi.BLL.BD_Company().Update(comp, Tran)))
                            {
                                //新增数据字典
                                Hi.Model.BD_DefDoc doc = new Hi.Model.BD_DefDoc();
                                doc.CompID     = KeyID;
                                doc.AtCode     = "";
                                doc.AtName     = "计量单位";
                                doc.ts         = DateTime.Now;
                                doc.modifyuser = UserID;
                                doc.dr         = 0;
                                List <Hi.Model.BD_DefDoc> ll = new Hi.BLL.BD_DefDoc().GetList("", "isnull(dr,0)=0 and compid=" + KeyID + " and atname='计量单位'", "", Tran);
                                if (ll.Count == 0)
                                {
                                    new Hi.BLL.BD_DefDoc().Add(doc, Tran);
                                }

                                //代理商加盟是否需要审核
                                Hi.Model.SYS_SysName sysname = new Hi.Model.SYS_SysName();
                                sysname.CompID     = KeyID;
                                sysname.Code       = "";
                                sysname.Name       = "代理商加盟是否需要审核";
                                sysname.Value      = "0";
                                sysname.ts         = DateTime.Now;
                                sysname.modifyuser = UserID;
                                List <Hi.Model.SYS_SysName> sysl = new Hi.BLL.SYS_SysName().GetList("", "Name='代理商加盟是否需要审核' and CompID=" + KeyID, "", Tran);
                                if (sysl != null && sysl.Count == 0)
                                {
                                    new Hi.BLL.SYS_SysName().Add(sysname, Tran);
                                }

                                //费用科目
                                Hi.Model.BD_DefDoc doc1 = new Hi.Model.BD_DefDoc();
                                doc1.CompID     = KeyID;
                                doc1.AtCode     = "";
                                doc1.AtName     = "费用科目";
                                doc1.ts         = DateTime.Now;
                                doc1.modifyuser = UserID;
                                doc1.dr         = 0;
                                List <Hi.Model.BD_DefDoc> ll1 = new Hi.BLL.BD_DefDoc().GetList("", "isnull(dr,0)=0 and compid=" + KeyID + " and atname='费用科目'", "", Tran);
                                if (ll1.Count == 0)
                                {
                                    new Hi.BLL.BD_DefDoc().Add(doc1, Tran);
                                }


                                doc.CompID     = KeyID;
                                doc.AtCode     = "";
                                doc.AtName     = "代理商等级";
                                doc.ts         = DateTime.Now;
                                doc.modifyuser = UserID;
                                doc.dr         = 0;
                                List <Hi.Model.BD_DefDoc> lll = new Hi.BLL.BD_DefDoc().GetList("", "isnull(dr,0)=0 and compid=" + KeyID + " and atname='代理商等级'", "", Tran);
                                if (lll.Count == 0)
                                {
                                    new Hi.BLL.BD_DefDoc().Add(doc, Tran);
                                }
                                List <Hi.Model.SYS_Role> l = new Hi.BLL.SYS_Role().GetList("", "isnull(dr,0)=0 and isenabled=1 and compid=" + KeyID + " and RoleName='企业管理员'", "");
                                if (l.Count == 0)
                                {
                                    //新增角色(企业管理员)
                                    Hi.Model.SYS_Role role = new Hi.Model.SYS_Role();
                                    role.CompID       = KeyID;
                                    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_RoleUser RoleUser = new Hi.Model.SYS_RoleUser();
                                    RoleUser.FunType    = 1;
                                    RoleUser.UserID     = ListComp[0].UserID;
                                    RoleUser.RoleID     = Roid;
                                    RoleUser.IsEnabled  = true;
                                    RoleUser.CreateUser = this.UserID.ToString();
                                    RoleUser.CreateDate = DateTime.Now;
                                    RoleUser.ts         = DateTime.Now;
                                    RoleUser.dr         = 0;
                                    new Hi.BLL.SYS_RoleUser().Add(RoleUser, Tran);

                                    //修改用户对应的角色
                                    List <Hi.Model.SYS_Users> ListUser = new Hi.BLL.SYS_Users().GetList("", " isnull(dr,0)=0 and id=" + ListComp[0].UserID + " ", "");
                                    if (ListUser.Count > 0)
                                    {
                                        ListUser[0].TrueName   = Common.NoHTML(txtUserTrueName.Value.Trim());
                                        ListUser[0].ts         = DateTime.Now;
                                        ListUser[0].modifyuser = UserID;
                                        ListUser[0].AuditState = 2;
                                        new Hi.BLL.SYS_Users().Update(ListUser[0], Tran);
                                    }
                                    ListComp[0].IsAudit    = 2;
                                    ListComp[0].modifyuser = UserID;
                                    ListComp[0].ts         = DateTime.Now;
                                    ListComp[0].RoleID     = Roid;
                                    new Hi.BLL.SYS_CompUser().Update(ListComp[0], Tran);

                                    Hi.Model.BD_CompNews CNew = new Hi.Model.BD_CompNews();
                                    CNew.NewsTitle    = "欢迎登录" + ConfigurationManager.AppSettings["PhoneSendName"].ToString() + "平台";
                                    CNew.NewsContents = "”" + ConfigurationManager.AppSettings["PhoneSendName"].ToString() + "”平台为企业和代理商之间搭建了电子商务平台,通过企业入驻及代理商的加盟,形成覆盖全行业的线上销售网络。同时,充分利用平台信息化整合优势,帮助入驻企业销售模式电商化改造,以及为代理商信息化建设提供有力支持。另外,还将为供应链上的相关各方提供全渠道的结算服务以及授信融资等多项互联网金融服务。";
                                    CNew.IsEnabled    = 1;
                                    CNew.IsTop        = 0;
                                    CNew.NewsType     = 2;
                                    CNew.ShowType     = "1,2";
                                    CNew.CompID       = KeyID;
                                    CNew.CreateDate   = DateTime.Now;
                                    CNew.CreateUserID = UserID;
                                    CNew.ts           = DateTime.Now;
                                    CNew.modifyuser   = UserID;
                                    new Hi.BLL.BD_CompNews().Add(CNew, Tran);

                                    //新增角色权限表
                                    Hi.Model.SYS_RoleSysFun rolesys = null;
                                    //add by hgh   增加了:and funcode<>'1030'
                                    List <Hi.Model.SYS_SysFun> funList = new Hi.BLL.SYS_SysFun().GetList("", " Type=1 and funcode<>'1030'", "");
                                    foreach (Hi.Model.SYS_SysFun sys in funList)
                                    {
                                        rolesys              = new Hi.Model.SYS_RoleSysFun();
                                        rolesys.CompID       = KeyID;
                                        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_DisType distype = new Hi.Model.BD_DisType();
                                    distype.CompID       = KeyID;
                                    distype.TypeName     = "全部";
                                    distype.ParentId     = 0;
                                    distype.TypeCode     = "1001";
                                    distype.SortIndex    = "1000";
                                    distype.IsEnabled    = 0;
                                    distype.CreateUserID = UserID;
                                    distype.CreateDate   = DateTime.Now;
                                    distype.ts           = DateTime.Now;
                                    distype.modifyuser   = UserID;
                                    distype.dr           = 0;
                                    new Hi.BLL.BD_DisType().Add(distype, Tran);
                                    Tran.Commit();

                                    //审核成功   添加一条默认的商品分类 -开始

                                    string Typecode = "";//商品大类
                                    //Hi.Model.SYS_GType gtype = new Hi.BLL.SYS_GType().GetList(" top 1 *", " Deep=3  and FullCode like '"+ Typecode + "-%' and IsEnabled=1 and dr=0 ", " parentid,ID")[0];
                                    //Hi.Model.BD_GoodsCategory DisType = new Hi.Model.BD_GoodsCategory();

                                    //DisType.Code = NewCategoryCode("1");
                                    //DisType.Deep = 1;
                                    //DisType.ParCode = "";
                                    //DisType.ParentId = 0;
                                    //DisType.CompID = KeyID;
                                    //DisType.CategoryName = "默认";
                                    //DisType.GoodsTypeID = gtype.ID;
                                    //DisType.SortIndex = "1000";
                                    //DisType.CreateDate = DateTime.Now;
                                    //DisType.CreateUserID = 0;
                                    //DisType.IsEnabled = 1;
                                    //DisType.ts = DateTime.Now;
                                    //DisType.modifyuser = 0;
                                    //SqlTransaction trans = SqlHelper.CreateStoreTranSaction();
                                    //try
                                    //{
                                    //    int countID = 0;
                                    //    if ((countID = new Hi.BLL.BD_GoodsCategory().Add(DisType, trans)) > 0)
                                    //    {
                                    //        List<Hi.Model.BD_Goods> gList = new Hi.BLL.BD_Goods().GetList("", " CategoryID=''", "");
                                    //        if (gList != null && gList.Count > 0)
                                    //        {
                                    //            foreach (var bdGoodse in gList)
                                    //            {
                                    //                bdGoodse.CategoryID = countID;
                                    //                new Hi.BLL.BD_Goods().Update(bdGoodse, trans);
                                    //            }
                                    //        }
                                    //        trans.Commit();

                                    //    }

                                    //}
                                    //catch (Exception ex)
                                    //{
                                    //    Tiannuo.LogHelper.LogHelper.Error("Error", ex);
                                    //    if (trans != null)
                                    //    {
                                    //        if (trans.Connection != null)
                                    //        {
                                    //            trans.Rollback();
                                    //        }
                                    //    }
                                    //    return;
                                    //}
                                    //finally
                                    //{
                                    //    SqlHelper.ConnectionClose();
                                    //    if (trans != null)
                                    //    {
                                    //        if (trans.Connection != null)
                                    //        {
                                    //            trans.Connection.Close();
                                    //        }
                                    //    }
                                    //}
                                    //审核成功   添加一条默认的商品分类 -结束



                                    DBUtility.GetPhoneCode getphonecode = new DBUtility.GetPhoneCode();
                                    str = getphonecode.ReturnSTRS(ListUser[0].Phone, comp.CompName, ListUser[0].UserName);
                                    if (str != "Success")
                                    {
                                        JScript.AlertMsgMo(this, "审核通过的通知短信发送失败!请自行发送短信通知企业。", "function(){ window.location.href='CompInfo.aspx?go=1&KeyID=" + KeyID + "&type=" + Request.QueryString["type"] + "" + "'; }");
                                    }
                                    else
                                    {
                                        JScript.AlertMsgMo(this, "审核成功", "function(){ window.location.href='CompInfo.aspx?go=1&KeyID=" + KeyID + "&type=5'; }");
                                    }
                                }
                                else
                                {
                                    ListComp[0].IsAudit    = 2;
                                    ListComp[0].modifyuser = UserID;
                                    ListComp[0].ts         = DateTime.Now;
                                    new Hi.BLL.SYS_CompUser().Update(ListComp[0], Tran);
                                    Hi.Model.SYS_Users           user  = null;
                                    List <Hi.Model.SYS_CompUser> User2 = new Hi.BLL.SYS_CompUser().GetList("", " dr=0 and utype=4 and CompID=" + KeyID + "", "");
                                    if (User2.Count > 0)
                                    {
                                        user = new Hi.BLL.SYS_Users().GetModel(User2[0].UserID);
                                    }
                                    Tran.Commit();

                                    // 发短信通知
                                    DBUtility.GetPhoneCode getphonecode = new DBUtility.GetPhoneCode();
                                    getphonecode.GetUser(ConfigurationManager.AppSettings["PhoneCodeAccount"].ToString(), ConfigurationManager.AppSettings["PhoneCodePwd"].ToString());
                                    str = getphonecode.ReturnSTRS(user.Phone, comp.CompName, user.UserName);
                                    if (str != "Success")
                                    {
                                        JScript.AlertMsgMo(this, "审核通过的通知短信发送失败!请自行发送短信通知企业。", "function(){ window.location.href='CompInfo.aspx?go=1&KeyID=" + KeyID + "&type=" + Request.QueryString["type"] + "" + "'; }");
                                    }
                                    else
                                    {
                                        JScript.AlertMsgMo(this, "审核成功", "function(){ window.location.href='CompInfo.aspx?go=1&KeyID=" + KeyID + "&type=5'; }");
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        JScript.AlertMsg(this, "用户明细数据异常!。");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Tiannuo.LogHelper.LogHelper.Error("Error", ex);
                    if (Tran != null)
                    {
                        if (Tran.Connection != null)
                        {
                            Tran.Rollback();
                        }
                    }
                    JScript.AlertMsgMo(this, "审核失败", "function(){ window.location.href=window.location.href; }");
                }
                finally
                {
                    DBUtility.SqlHelper.ConnectionClose();
                }
            }
            else
            {
                JScript.AlertMsg(this, "厂商不存在!。");
                return;
            }


            //cust by ggh 20180327 begin  审核通过时,默认给核心企业设置手续费

            Settings(KeyID);

            //cust by ggh 20180327  end  审核通过时,默认给核心企业设置手续费
        }
        else
        {
            if (Common.GetUserExists(txtUsername.Value.Trim()))
            {
                JScript.AlertMsg(this, "该登录帐号已存在。");
                return;
            }
            if (Common.CompExistsAttribute("CompName", txtCompName.Value.Trim()))
            {
                JScript.AlertMsg(this, "该厂商名称已存在。");
                return;
            }
            Regex Phonereg = new Regex("^0?1[0-9]{10}$");
            if (!Phonereg.IsMatch(txtUserPhone.Value.Trim()))
            {
                JScript.AlertMsg(this, "手机号码格式错误!");
                return;
            }
            if (Common.GetUserExists("Phone", txtUserPhone.Value.Trim()))
            {
                JScript.AlertMsg(this, "手机号码已被注册!");
                return;
            }
            Hi.Model.BD_Company comp = new Hi.Model.BD_Company();
            if (UserType == 3 || UserType == 4)
            {
                comp.OrgID      = OrgID;
                comp.SalesManID = SalesManID;
            }
            comp.CompName = Common.NoHTML(txtCompName.Value.Trim());
            comp.Capital  = Capital.Value.Trim();
            comp.CompType = Convert.ToInt32(CompType.SelectedValue);
            comp.Tel      = Common.NoHTML(txtTel.Value.Trim());
            if (txtPrincipal.Value.Trim() != "")
            {
                comp.Principal = Common.NoHTML(txtPrincipal.Value.Trim());
            }
            else
            {
                comp.Principal = Common.NoHTML(txtUserTrueName.Value.Trim());
            }
            comp.Legal    = Common.NoHTML(txtLegal.Value.Trim());
            comp.LegalTel = Common.NoHTML(txtLegalTel.Value.Trim());
            if (txtPhone.Value.Trim() != "")
            {
                comp.Phone = Common.NoHTML(txtPhone.Value.Trim());
            }
            else
            {
                comp.Phone = Common.NoHTML(txtUserPhone.Value.Trim());
            }
            comp.ShortName        = Common.NoHTML(txtShotName.Value.Trim());
            comp.Zip              = Common.NoHTML(txtZip.Value.Trim());
            comp.Identitys        = Common.NoHTML(txtIdentitys.Value.Trim());
            comp.Licence          = Common.NoHTML(txtLicence.Value.Trim());
            comp.ManageInfo       = Common.NoHTML(txtInfo.Value.Trim());
            comp.Fax              = Common.NoHTML(txtFax.Value.Trim());
            comp.OrganizationCode = Common.NoHTML(txtOrcode.Value.Trim());
            comp.Trade            = txtIndusName.Items[txtIndusName.SelectedIndex].Text;
            comp.Account          = Common.NoHTML(txtAccount.Value.Trim());
            comp.Attachment       = HidFfileName.Value;
            comp.Address          = Common.NoHTML(txtAddress.Value.Trim());
            comp.CustomCompinfo   = "本公司产品种类丰富、质量优良、价格公道、服务周到。感谢您长期的支持与厚爱,您的满意是我们最高的追求,我们将竭诚为您提供优质、贴心的服务!";

            string CompAddr = hidProvince.Value.Trim();
            if (!string.IsNullOrWhiteSpace(hidCity.Value.Trim()) && hidCity.Value.Trim() != "选择市")
            {
                CompAddr += "-" + hidCity.Value.Trim();
            }
            if (!string.IsNullOrWhiteSpace(hidArea.Value.Trim()) && hidArea.Value.Trim() != "选择区")
            {
                CompAddr += "-" + hidArea.Value.Trim();
            }
            comp.CompAddr = CompAddr;

            comp.IndID        = txtIndusName.SelectedValue.ToInt(0);
            comp.CreateDate   = DateTime.Now;
            comp.CreateUserID = UserID;
            comp.ts           = DateTime.Now;
            comp.modifyuser   = UserID;
            comp.IsEnabled    = rdEbleYes.Checked ? 1 : 0;
            comp.HotShow      = rdHotShowYes.Checked ? 1 : 0;
            comp.FirstShow    = Convert.ToInt32(ddlChkShow.SelectedValue);// rdFirstShowYes.Checked ? 1 : 0;
            comp.SortIndex    = "001";
            comp.Remark       = Common.NoHTML(txtRemark.Value.Trim());
            comp.Erptype      = ddlErptype.SelectedValue.ToInt(0);
            comp.AuditState   = 0;
            int            comid = 0;
            SqlTransaction Tran  = DBUtility.SqlHelper.CreateStoreTranSaction();
            comid         = new Hi.BLL.BD_Company().Add(comp, Tran);
            comp.CompCode = Common.CreateCode(comid);
            comp.ID       = comid;
            new Hi.BLL.BD_Company().Update(comp, Tran);
            Hi.Model.SYS_Users user = new Hi.Model.SYS_Users();
            user.UserName     = Common.NoHTML(txtUsername.Value.Trim());
            user.TrueName     = Common.NoHTML(txtUserTrueName.Value.Trim());
            user.UserPwd      = Util.md5(txtUpwd.Text.Trim());
            user.Phone        = Common.NoHTML(txtUserPhone.Value.Trim());
            user.AuditState   = 2;
            user.IsEnabled    = 1;
            user.AuditUser    = UserID.ToString();
            user.CreateUserID = UserID;
            user.CreateDate   = DateTime.Now;
            user.ts           = DateTime.Now;
            user.modifyuser   = UserID;
            int userid = 0;
            userid = new Hi.BLL.SYS_Users().Add(user, Tran);
            Hi.Model.SYS_CompUser CompUser = new Hi.Model.SYS_CompUser();
            CompUser.CompID       = comid;
            CompUser.DisID        = 0;
            CompUser.CreateDate   = DateTime.Now;
            CompUser.CreateUserID = UserID;
            CompUser.modifyuser   = UserID;
            CompUser.CType        = 1;
            CompUser.UType        = 4;
            CompUser.IsEnabled    = 1;
            CompUser.IsAudit      = 0;
            CompUser.ts           = DateTime.Now;
            CompUser.dr           = 0;
            CompUser.UserID       = userid;
            new Hi.BLL.SYS_CompUser().Add(CompUser, Tran);
            Tran.Commit();
            Response.Redirect("CompInfo.aspx?go=1&KeyID=" + comid, false);
        }
    }
Ejemplo n.º 4
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Hi.Model.BD_DisType model)
 {
     return(dal.Update(model));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Hi.Model.BD_DisType model)
 {
     return(dal.Add(model));
 }
Ejemplo n.º 6
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();
                }
            }
        }
    }