chenhaozhe
2025-05-09 df6cfd87bdaa0eae121fba82939cfb01a3b5f9f6
WebAPI/Controllers/BaseSet/Gy_CustomerController.cs
@@ -12,8 +12,8 @@
using SyntacticSugar.constant;
using System.Web;
using WebAPI.Controllers.SCGL.日计划管理;
using WebAPI.WebBLL.JCJM.GYZL;
using WebAPI.WebBLL.JCJM.IMPL;
//using WebAPI.WebBLL.JCJM.GYZL;
//using WebAPI.WebBLL.JCJM.IMPL;
using System.IO;
namespace WebAPI.Controllers
{
@@ -25,7 +25,7 @@
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        private Gy_CustomerService customerService = new Gy_CustomerImpl();
        //private Gy_CustomerService customerService = new Gy_CustomerImpl();
        DataSet ds;
        #region 返回客户列表
@@ -102,6 +102,73 @@
        }
        #endregion
        #region 客户分页列表
        [Route("Gy_Customer/page")]
        [HttpGet]
        public json Gy_CustomerPage(string sWhere, string user, int page, int size, string Organization)
        {
            DataSet ds;
            json res = new json();
            try
            {
                List<object> columnNameList = new List<object>();
                //判断权限
                if (!DBUtility.ClsPub.Security_Log_second("Crm_CustomerFileList", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //客户制定
                string sErr = "";
                if (oSystemParameter.ShowBill(ref sErr))
                {
                    if (oSystemParameter.omodel.WMS_CampanyName != "乔一")
                    {
                        sWhere += ("and 组织名称 = '" + Organization + "'");
                    }
                }
                sWhere = sWhere.Replace("'", "''");
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("exec h_p_Gy_CustomerList " + page + "," + size + ",''", "h_p_Gy_CustomerList");
                }
                else
                {
                    ds = oCN.RunProcReturn("exec h_p_Gy_CustomerList " + page + "," + size + ",'" + sWhere + "'", "h_p_Gy_CustomerList");
                }
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                res.code = CodeConstant.SUCCEED;
                res.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
                res.Message = "Sucess!";
                res.list = columnNameList;
                res.data = ds.Tables[0];
                return res;
            }
            catch (Exception e)
            {
                res.code = CodeConstant.FAIL;
                res.count = CountConstant.FAIL;
                res.Message = "Exception!" + e.ToString();
                res.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 客户子表[关联用户] 查询
        /// <summary>
        /// 返回客户子表[关联用户]列表
@@ -161,11 +228,11 @@
                                            ,c.HMobilePhone 手机,c.HFax 传真,c.HPostalCode 邮编,c.HEmail 电子邮件,c.HCorMan 法人代表,c.HBank 开户银行,c.HBankAccount 银行账号,c.HMateOutEmp 领用人,
                                            c.HTaxNum 税务登记号,c.HTaxRate 增值税率,c.HEnglishName 英文名称,c.HEngLishAddress 英文地址,c.HCountry 国家,c.HCusStatus 客户状态
                                            ,c.HStopflag 禁用标志,c.HRemark 备注,c.HAreaID 地区ID,a.HName 地区名称,c.HCurID 默认货币ID,r.HName 默认货币,
                                            c.HSSID 结算方式ID,s.HName 结算方式,c.HCusTypeID 客户分类ID,t.HName 客户分类 from Gy_Customer c
                                            c.HSSID 结算方式ID,s.HName 结算方式,c.HCusTypeID 客户分类ID,t.HName 客户分类, c.HCheckEmp 审核人 from Gy_Customer c
                                            left join Gy_AreaSet a on c.HAreaID=a.HItemID
                                            left join Gy_Currency r on c.HCurID=r.HItemID 
                                            left  join Gy_SettleStyle s on c.HSSID=s.HItemID
                                            left  join Gy_CusType t on c.HCusTypeID=t.HItemID
                                            left  join Gy_CusType t on c.HCusTypeID=t.HItemID
                                            where c.HItemID='" + HInterID + "'");
                ds = oCN.RunProcReturn(sql, "Gy_Customer");
                objJsonResult.code = "1";
@@ -1318,6 +1385,56 @@
        }
        #endregion
        // #region 客户分类属性结构 根据组织分类
        [Route("Gy_BadReason/Gy_CusTypeTreeListByOrganization")]
        [HttpGet]
        public object Gy_CusTypeTreeListByOrganization()
        {
            try
            {
                string sql1 = string.Format("select hitemid,hnumber,hname,hparentid from Xt_ORGANIZATIONS where hstopflag != 1 order by hnumber");
                ds = oCN.RunProcReturn(sql1, "Xt_ORGANIZATIONS");
                List <TreeModel> treeModels = new List<TreeModel>();
                TreeModel first = new TreeModel();
                first.title = "使用组织";
                first.id = "0";
                treeModels.Add(first);
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    int HParentID = (int)row["hparentid"];
                    int HItemID = (int)row["hitemid"];
                    //if(HParentID == 0 || HItemID == HParentID) // 父节点为0或者自引用的设置为一级几点
                    //{
                        TreeModel tree = new TreeModel();
                        tree.id = row["hitemid"].ToString();
                        tree.title = row["hname"].ToString();
                        treeModels[0].children.Add(tree);
                    //}
                }
                //getTreeByHItemID(ds.Tables[0], treeModels);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = Newtonsoft.Json.JsonConvert.SerializeObject(treeModels);
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        // #endregion
        #region 根据父id和等级获得树状图递归
        [Route("Gy_BadReason/Gy_CusTypeTreeListByLevel")]
@@ -1367,41 +1484,41 @@
        #endregion
        #region 客户列表 文件上传
        [Route("Gy_Customer/Gy_Process_Excel")]
        [HttpPost]
        public json Gy_Department_Excel()
        {
            json res = new json();
            try
            {
                //获取文件名称
                var file = HttpContext.Current.Request.Files[0];
                //获取文件物理路径
                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
                //保存文件
                file.SaveAs(ExcelPath);
        //[Route("Gy_Customer/Gy_Process_Excel")]
        //[HttpPost]
        //public json Gy_Department_Excel()
        //{
        //    json res = new json();
        //    try
        //    {
        //        //获取文件名称
        //        var file = HttpContext.Current.Request.Files[0];
        //        //获取文件物理路径
        //        string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
        //        //保存文件
        //        file.SaveAs(ExcelPath);
                NpoiHelper np = new NpoiHelper();
                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
                //删除文件
                File.Delete(ExcelPath);
                DataTable provisional = customerService.UploadExcel(ExcelDs);
        //        NpoiHelper np = new NpoiHelper();
        //        DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
        //        //删除文件
        //        File.Delete(ExcelPath);
        //        DataTable provisional = customerService.UploadExcel(ExcelDs);
                
                res.code = CodeConstant.SUCCEED;
                res.count = CountConstant.SUCCEED;
                res.Message = "上传成功";
                res.data = provisional;
                return res;
            }
            catch (Exception e)
            {
                res.code = "0";
                res.count = 0;
                res.Message = "Exception!" + e.ToString();
                res.data = null;
                return res;
            }
        }
        //        res.code = CodeConstant.SUCCEED;
        //        res.count = CountConstant.SUCCEED;
        //        res.Message = "上传成功";
        //        res.data = provisional;
        //        return res;
        //    }
        //    catch (Exception e)
        //    {
        //        res.code = "0";
        //        res.count = 0;
        //        res.Message = "Exception!" + e.ToString();
        //        res.data = null;
        //        return res;
        //    }
        //}
        /// <summary>
        /// 判断当前职员是否存在
@@ -1409,15 +1526,15 @@
        /// <param name="HEmpNumber"></param>
        /// <param name="HEmpName"></param>
        /// <returns></returns>
        private bool JudgeEmp(string HEmpNumber, string HEmpName)
        {
            if (!String.IsNullOrEmpty(HEmpNumber) && !String.IsNullOrEmpty(HEmpName))
            {
                DataSet emp = oCN.RunProcReturn("select * from Gy_Employee where HNumber = '" + HEmpNumber + "' and HName = '" + HEmpName + "'", "Gy_Employee");
                return emp.Tables[0].Rows.Count <= EmptyConstant.EMPTY ? true : false;
            }
            return false;
        }
        //private bool JudgeEmp(string HEmpNumber, string HEmpName)
        //{
        //    if (!String.IsNullOrEmpty(HEmpNumber) && !String.IsNullOrEmpty(HEmpName))
        //    {
        //        DataSet emp = oCN.RunProcReturn("select * from Gy_Employee where HNumber = '" + HEmpNumber + "' and HName = '" + HEmpName + "'", "Gy_Employee");
        //        return emp.Tables[0].Rows.Count <= EmptyConstant.EMPTY ? true : false;
        //    }
        //    return false;
        //}
        /// <summary>
        /// 判断列
@@ -1472,6 +1589,31 @@
        #endregion
        public void getTreeByHItemID(DataTable dt, List<TreeModel> tree)
        {
            for (int m = 0; m < tree.Count; m++)
            {
                tree[m].children = new List<TreeModel>();
                for (int i = 0; i < dt.Rows.Count; i++)//第一次循环,得到所有根节点的子集
                {
                    var HParentID = dt.Rows[i]["hparentid"].ToString();
                    var HItemID = dt.Rows[i]["hitemid"].ToString();
                    if (HParentID == tree[m].id && HParentID != HItemID)
                    {
                        TreeModel tbjson = new TreeModel();
                        tbjson.id = dt.Rows[i]["hitemid"].ToString();
                        tbjson.title = dt.Rows[i]["hname"].ToString();
                        tree[m].children.Add(tbjson);
                    }
                }
                for (int i = 0; i < tree[m].children.Count; i++)
                {
                    getTreeByHItemID(dt, tree[m].children);//再次用子集去循环,拿出子集的子集
                }
            }
        }
        #region 递归函数
        /// <summary>
        /// 递归函数