chenhaozhe
5 天以前 47b45a4ac3284936515a2edd3e50265de30993a0
WebAPI/Controllers/BaseSet/Gy_ModelTypeController.cs
@@ -25,6 +25,85 @@
        DAL.ClsGy_MouldType_Ctl oDept = new DAL.ClsGy_MouldType_Ctl();
        DAL.ClsGy_MouldType_View oDeptHlp = new DAL.ClsGy_MouldType_View();
        #region 根据父id和等级获得树状图递归
        public class TreeModel
        {
            public string id { get; set; }
            public string title { get; set; }
            public List<TreeModel> children = new List<TreeModel>();
        }
        [Route("Gy_ModelType/Gy_ModelTypeTreeListByLevel")]
        [HttpGet]
        public object Gy_ModelTypeTreeListByLevel(string HOrgID)
        {
            try
            {
                string sql1 = string.Format("select hitemid,hnumber,hname,hparentid,hlevel,hhelpcode from Gy_MouldType where HUSEORGID = '" + HOrgID + "' order by hhelpcode");
                ds = oCN.RunProcReturn(sql1, "Gy_ModelType");
                List<TreeModel> treeModels = new List<TreeModel>();
                TreeModel first = new TreeModel();
                first.id = "0";
                first.title = "器具分类设置";
                treeModels.Add(first);
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    var HLevel = (int)row["hlevel"];
                    if (HLevel == 1)
                    {
                        TreeModel tree = new TreeModel();
                        tree.id = row["hitemid"].ToString();
                        tree.title = row["hname"].ToString();
                        treeModels[0].children.Add(tree);
                    }
                }
                getTreeByLevel(ds.Tables[0], treeModels[0].children, 2);
                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;
            }
        }
        public void getTreeByLevel(DataTable dt, List<TreeModel> tree, int num)
        {
            for (int m = 0; m < tree.Count; m++)
            {
                tree[m].children = new List<TreeModel>();
                for (int i = 0; i < dt.Rows.Count; i++)//第一次循环,得到所有根节点的子集
                {
                    var HLevel = (int)dt.Rows[i]["hlevel"];
                    var HParentID = dt.Rows[i]["hparentid"].ToString();
                    if (HLevel == num && HParentID == tree[m].id)
                    {
                        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++)
                {
                    getTreeByLevel(dt, tree[m].children, num + 1);//再次用子集去循环,拿出子集的子集
                }
            }
        }
        #endregion
        #region 模治具分类列表数据
        /// <summary>
@@ -48,7 +127,12 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select HItemID,HParentID,HNumber,HName,HLevel, case when HEndFlag<>0 then 'Y'else ' 'end HEndFlag,case when HStopFlag <> 0 then 'Y'else ' 'end HStopFlag, HRemark, HUseFlag from Gy_MouldType where 1=1 " + sWhere+ " order by HNumber", "Gy_MouldType");
                //ds = oCN.RunProcReturn("select HItemID,HParentID,HNumber,HName,HLevel, case when HEndFlag<>0 then 'Y'else ' 'end HEndFlag,case when HStopFlag <> 0 then 'Y'else ' 'end HStopFlag, HRemark, HUseFlag from Gy_MouldType where 1=1 " + sWhere+ " order by HNumber", "Gy_MouldType");
                string sql = "select * from h_v_Gy_MouldType where 1=1 " + sWhere + " order by 器具分类代码,器具分类名称,所属父级分类名称,创建人,审核人,备注,组织,禁用标记";
                ds = oCN.RunProcReturn(sql, "h_v_Gy_MouldType");
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
@@ -150,6 +234,25 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DataSet ds_check_1 = oCN.RunProcReturn("select * from Gy_MouldType where HItemID =" + HItemID, "Gy_MouldType");
                if (ds_check_1.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "删除失败:数据不存在";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else if (ds_check_1.Tables[0].Rows[0]["HCheckEmp"].ToString() != "")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "删除失败:当前数据已审核,不可删除";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oDeptHlp.GetInfoByID(HItemID))
                {
                    if (oDept.HavChildCodes(HItemID))
@@ -243,6 +346,17 @@
                bool HStopflag = list[0].HStopflag;
                string HUseFlag = list[0].HUseFlag;
                bool HEndFlag = list[0].HEndFlag;
                long HUSEORGID = list[0].HUSEORGID;
                DataSet ds_check = oCN.RunProcReturn("select * from Gy_MouldType where HNumber = '" + HNumber + "' and HUSEORGID = " + HUSEORGID, "Gy_MouldType");
                if (ds_check.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "新增失败:当前组织下代码【" + HNumber + "】已存在,请修改代码后重新保存";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //判断权限
                if (!DBUtility.ClsPub.Security_Log(msg4, 1, false, msg3))
@@ -270,9 +384,9 @@
                //主表
                oCN.RunProc("Insert into Gy_MouldType " +
                   " (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
                   ",HLevel,HEndFlag,HStopflag,HRemark,HMakeTime) " +
                   ",HLevel,HEndFlag,HStopflag,HRemark,HMakeEmp,HMakeTime,HUSEORGID) " +
                   " Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + HShortNumber + "'," + HParentID +
                   "," + HLevel+ "," + Convert.ToString(HEndFlag ? 1 : 0) + "," + Convert.ToString(HStopflag ? 1 : 0) + ",'" + HRemark + "',getdate())", ref DBUtility.ClsPub.sExeReturnInfo);
                   "," + HLevel+ "," + Convert.ToString(HEndFlag ? 1 : 0) + "," + Convert.ToString(HStopflag ? 1 : 0) + ",'" + HRemark + "','" + msg3 + "',getdate()," + HUSEORGID + ")", ref DBUtility.ClsPub.sExeReturnInfo);
                //修改上级为非末级代码
                oCN.RunProc("Update Gy_MouldType set HEndflag=0 where HItemID=" + HParentID, ref DBUtility.ClsPub.sExeReturnInfo);
                oCN.Commit();
@@ -328,6 +442,35 @@
                string HRemark = list[0].HRemark;
                bool HStopflag = list[0].HStopflag;
                string HUseFlag = list[0].HUseFlag;
                long HUSEORGID = list[0].HUSEORGID;
                DataSet ds_check = oCN.RunProcReturn("select * from Gy_MouldType where HNumber = '" + HNumber + "' and HUSEORGID = " + HUSEORGID + " and HItemID <>" + HItemID,"Gy_MouldType");
                if (ds_check.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "修改失败:当前组织下代码【" + HNumber + "】已存在,请修改代码后重新保存";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DataSet ds_check_1 = oCN.RunProcReturn("select * from Gy_MouldType where HItemID =" + HItemID, "Gy_MouldType");
                if (ds_check_1.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "修改失败:数据不存在";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else if(ds_check_1.Tables[0].Rows[0]["HCheckEmp"].ToString() != "")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "修改失败:当前数据已审核,不可修改";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //判断权限
                if (!DBUtility.ClsPub.Security_Log(msg5, 1, false, msg4))
@@ -369,7 +512,11 @@
                    ",HHelpCode='" + HHelpCode + "'" +
                    ",HParentID=" + HParentID +
                    ",HStopflag='" + HStopflag + "'" +
                    ",HRemark= '" + HRemark + "' Where HItemID=" + HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                    ",HRemark= '" + HRemark + "' " +
                    ",HModifyEmp='" + msg4 + "' " +
                    ",HModifyTime=getdate() " +
                    ",HUSEORGID=" + HUSEORGID + " " +
                    " Where HItemID=" + HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                //修改子项目代码
                //oCN.RunProc("exec h_p_Gy_UpdateNumber Gy_RepairCheck,'" + HNumber + ".','" + this.HOldNumber + ".'", ref DBUtility.ClsPub.sExeReturnInfo);
                //将上级 为非末级
@@ -406,7 +553,8 @@
        {
            try
            {
                ds = oCN.RunProcReturn("select * from Gy_MouldType where HItemID=" + HInterID, "Gy_MouldType");
                string sql = "select a.*,b.HName HParentName from Gy_MouldType as a left join Gy_MouldType as b on a.HParentID = b.HItemID where a.HItemID=" + HInterID;
                ds = oCN.RunProcReturn(sql, "Gy_MouldType");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
@@ -556,6 +704,101 @@
        }
        #endregion
        #region 器具分类 禁用、反禁用
        /// <summary>
        ///
        /// </summary>
        /// <param name="HInterID">单据ID</param>
        /// <param name="IsStop">禁用(0),反禁用(1)</param>
        /// <param name="CurUserName">审核人</param>
        /// <returns></returns>
        [Route("Gy_MouldType/StopGy_MouldType")]
        [HttpGet]
        public object StopGy_MouldType(int HInterID, int IsStop, string CurUserName)
        {
            try
            {
                //审核权限
                if (!DBUtility.ClsPub.Security_Log_second("Gy_MouldType_Stop", 1, false, CurUserName))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "禁用失败!无权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                var ds = oCN.RunProcReturn("select * from Gy_MouldType where HItemID=" + HInterID, "Gy_MouldType");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (IsStop == 0)  //禁用判断
                    {
                        if (ds.Tables[0].Rows[0]["HStopEmp"].ToString() != "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "已禁用!不能再次禁用!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    if (IsStop == 1) //反禁用判断
                    {
                        if (ds.Tables[0].Rows[0]["HStopEmp"].ToString() == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据未禁用!不需要反禁用!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "数据不存在!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.BeginTran();
                if (IsStop == 0)  //禁用判断
                {
                    oCN.RunProc("update Gy_MouldType set HStopEmp='" + CurUserName + "',HStopTime=getdate(),HStopflag=1 where HItemID=" + HInterID);
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "禁用成功";
                    objJsonResult.data = null;
                }
                if (IsStop == 1) //反禁用判断
                {
                    oCN.RunProc("update Gy_MouldType set HStopEmp='',HStopTime=null,HStopflag=0 where HItemID=" + HInterID);
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "反禁用成功";
                    objJsonResult.data = null;
                }
                oCN.Commit();
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "禁用失败或者反禁用失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 器具分类 文件导入保存
        #region 器具分类 文件上传
        [Route("Gy_MouldType/Gy_MouldType_Excel")]