using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Linq;
|
using System.Net;
|
using System.Net.Http;
|
using System.Web.Http;
|
using WebAPI.Models.基础资料;
|
using WebAPI.Models;
|
|
namespace WebAPI.Controllers.基础资料.基础资料
|
{
|
public class Gy_DutyBillController : ApiController
|
{
|
private json objJsonResult = new json();
|
public DataSet ds = new DataSet();
|
public SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
|
#region 组织架构设置 树形图
|
public class TreeModel
|
{
|
public string id { get; set; }
|
public string title { get; set; }
|
public List<TreeModel> children = new List<TreeModel>();
|
}
|
[Route("Gy_DutyBill/Gy_DutyBillTreeList")]
|
[HttpGet]
|
public object Gy_DutyBillTreeList()
|
{
|
try
|
{
|
string sql1 = string.Format("select hitemid,hnumber,hname from Gy_Duty order by hnumber");
|
|
ds = oCN.RunProcReturn(sql1, "Gy_Duty");
|
|
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 strLen = row["hnumber"].ToString().Split('.');
|
if (strLen.Length == 1)
|
{
|
TreeModel tree = new TreeModel();
|
tree.id = row["hnumber"].ToString();
|
tree.title = row["hname"].ToString();
|
treeModels[0].children.Add(tree);
|
}
|
}
|
|
digui(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;
|
}
|
}
|
|
/// <summary>
|
/// 递归函数
|
/// </summary>
|
public void digui(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 strLen = dt.Rows[i]["hnumber"].ToString().Split('.');
|
if (strLen.Length == num && dt.Rows[i]["hnumber"].ToString().Contains(tree[m].id + "."))
|
{
|
TreeModel tbjson = new TreeModel();
|
tbjson.id = dt.Rows[i]["hnumber"].ToString();
|
tbjson.title = dt.Rows[i]["hname"].ToString();
|
tree[m].children.Add(tbjson);
|
}
|
}
|
var strLens = tree[m].id.Split('.');
|
for (int i = 0; i < tree[m].children.Count; i++)
|
{
|
digui(dt, tree[m].children, strLens.Length + 2);//再次用子集去循环,拿出子集的子集
|
}
|
}
|
|
}
|
#endregion
|
|
#region 组织架构设置 列表
|
[Route("Gy_DutyBill/Gy_DutyBillList")]
|
[HttpGet]
|
public object Gy_DutyBillList(string sWhere)
|
{
|
try
|
{
|
string sql1 = string.Format(@"select * from h_v_Gy_DutyList where 1=1 ");
|
|
ds = oCN.RunProcReturn(sql1+ sWhere+ " order by 组织架构代码", "h_v_Gy_DutyList");
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 组织架构设置 保存
|
[Route("Gy_DutyBill/Gy_DutyBillEdit")]
|
[HttpPost]
|
public object Xt_CheckFlowBillEdit([FromBody] JObject msg)
|
{
|
var _value = msg["msg"].ToString();
|
string msg3 = _value.ToString();
|
string[] sArray = msg3.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
string msg1 = sArray[0].ToString();
|
string msg2 = sArray[1].ToString();
|
string msg4 = sArray[2].ToString();
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
|
try
|
{
|
Gy_Duty Duty = JsonConvert.DeserializeObject<Gy_Duty>(msg1);
|
|
|
//获取上级的代码
|
var topHNum = DBUtility.ClsPub.GetParentCode(Duty.HNumber);
|
|
if (topHNum == "")
|
{
|
Duty.HParentID = 0;
|
}
|
else
|
{
|
ds = oCN.RunProcReturn("select * from Gy_Duty where HStopflag=0 and HNumber='" + topHNum + "' or HNumber='" + Duty.HNumber + "' ", "Gy_Duty");
|
if (ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "上级代码不存在或被禁用!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
if (msg4 == "1") {
|
if (ds.Tables[0].Rows.Count == 2)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "代码重复!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
Duty.HParentID = int.Parse(ds.Tables[0].Rows[0]["HItemID"].ToString());
|
}
|
|
if (Duty.HItemID != 0)
|
{
|
ds = oCN.RunProcReturn("select * from Gy_Duty where HItemID='" + Duty.HItemID + "' ", "Gy_Duty");
|
var newHNum = Duty.HNumber.Split('.');
|
var oldHNum = ds.Tables[0].Rows[0]["HNumber"].ToString().Split('.');
|
|
if (newHNum.Length > oldHNum.Length && Duty.HItemID == Duty.HParentID)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "新代码不能是自己的下级的子项目!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
ds = oCN.RunProcReturn("select * from Gy_Duty where HParentID='" + Duty.HItemID + "' ", "Gy_Duty");
|
|
if (ds.Tables[0].Rows.Count>0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "该项目下面有子项目,不能修改!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
Duty.HEndFlag = 1;
|
Duty.HShortNumber = DBUtility.ClsPub.GetShortNumber(Duty.HNumber);
|
Duty.HLevel = DBUtility.ClsPub.GetLevel(Duty.HNumber);
|
|
if (Duty.HShortNumber == "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "短代码为空!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCN.BeginTran();
|
|
if (msg4 == "1")
|
{
|
//保存
|
//保存完毕后处理
|
oCN.RunProc("Insert into Gy_Duty " +
|
" (HNumber,HName,HHelpCode,HShortNumber,HParentID,HUserGroupID" +
|
",HLevel,HEndFlag,HStopflag,HRemark) " +
|
" Values('" + Duty.HNumber + "','" + Duty.HName + "','" + Duty.HHelpCode + "','" + Duty.HShortNumber + "'," + Duty.HParentID.ToString() + "," + Duty.HUserGroupID.ToString() +
|
"," + Duty.HLevel.ToString() + "," + Duty.HEndFlag + "," + Convert.ToString(Duty.HStopflag ? 1 : 0) + ",'" + Duty.HRemark + "')", ref DBUtility.ClsPub.sExeReturnInfo);
|
}
|
else
|
{
|
oCN.RunProc("Update Gy_Duty set " +
|
" HNumber='" + Duty.HNumber + "'" +
|
",HName='" + Duty.HName + "'" +
|
",HShortNumber='" + Duty.HShortNumber + "'" +
|
",HHelpCode='" + Duty.HHelpCode + "'" +
|
",HLevel=" + Duty.HLevel.ToString() +
|
",HParentID=" + Duty.HParentID.ToString() +
|
",HUserGroupID=" + Duty.HUserGroupID.ToString() +
|
",HEndflag=" + Duty.HEndFlag +
|
",HStopflag=" + Convert.ToString(Duty.HStopflag ? 1 : 0) +
|
",HRemark= '" + Duty.HRemark + "' Where HItemID=" + Duty.HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
|
}
|
|
//修改上级为非末级代码
|
oCN.RunProc("Update Gy_Duty set HEndflag=0 where HItemID=" + Duty.HParentID, ref DBUtility.ClsPub.sExeReturnInfo);
|
oCN.Commit();
|
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "保存成功!";
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "保存失败!" + e.ToString();
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
}
|
|
#endregion
|
|
#region 组织架构设置 删除
|
[Route("Gy_DutyBill/Gy_DutyBillDel")]
|
[HttpGet]
|
public object Gy_DutyBillDel(string HItemID, string user)
|
{
|
try
|
{
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
if (string.IsNullOrWhiteSpace(HItemID))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "HItemID为空!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
ds = oCN.RunProcReturn("select * from Gy_Duty where HParentID='" + HItemID + "' ", "Gy_Duty");
|
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "该项目下面有子项目,不能删除!,请先删除子项目!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
ds = oCN.RunProcReturn("select * from Gy_Duty where HItemID='" + HItemID + "' ", "Gy_Duty");
|
|
oCN.BeginTran();//开始事务
|
|
//删除数据
|
oCN.RunProc("Delete from Gy_Duty where HItemID='" + HItemID + "'");
|
//修改上级为末级
|
oCN.RunProc("Update Gy_Duty set HEndflag=1 where HItemID=" + ds.Tables[0].Rows[0]["HParentID"].ToString());
|
|
oCN.Commit();//提交事务
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "* 数据删除成功!";
|
objJsonResult.data = null;
|
return objJsonResult; ;
|
|
}
|
catch (Exception e)
|
{
|
//回滚
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "删除失败!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 组织架构设置 检测
|
[Route("Gy_DutyBill/Gy_DutyBillTest")]
|
[HttpGet]
|
public object Gy_DutyBillTest(string HItemID, string user)
|
{
|
try
|
{
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
if (string.IsNullOrWhiteSpace(HItemID))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "HItemID为空!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCN.BeginTran();//开始事务
|
|
//检测数据
|
oCN.RunProc("exec h_p_Gy_Duty " + HItemID );
|
|
oCN.Commit();//提交事务
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "成功!";
|
objJsonResult.data = null;
|
return objJsonResult; ;
|
|
}
|
catch (Exception e)
|
{
|
//回滚
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "失败!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
}
|
}
|