using DBUtility;
|
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;
|
|
namespace WebAPI.Controllers
|
{
|
public class Gy_UnitConvertRateController : ApiController
|
{
|
public DBUtility.ClsPub.Enum_BillStatus BillStatus;
|
const string ModCaption = "单位换算";
|
public const string ModRightName = "Gy_UnitConvertRate";
|
public const string ModRightNameDelete = ModRightName + "_Delete"; //删除
|
public DataSet ds = new DataSet();
|
private json objJsonResult = new json();
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
|
|
|
#region 单位换算列表
|
/// <summary>
|
/// 获取单位换算列表信息
|
/// </summary>
|
/// <returns></returns>
|
[Route("Gy_UnitConvertRateController/GetGy_UnitConvertRateList_Json")]
|
[HttpGet]
|
public object GetGy_UnitConvertRateList_Json(string sWhere, string HMaker, string OperationType)
|
{
|
try
|
{
|
//判断权限 1为直接列表模块打开 2为从其他模块跳转打开列表
|
if (OperationType == "1")
|
{
|
//判断权限
|
if (!DBUtility.ClsPub.Security_Log(ModRightName, 1, false, HMaker))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "您没有该模块权限,请与管理员联系!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
//返回列表信息
|
ds = oCn.RunProcReturn("select * from h_v_Gy_UnitConvertRateList where " + sWhere + " order by HItemID desc", "h_v_Gy_UnitConvertRateList");
|
List<object> columnNameList = new List<object>();
|
//添加列名
|
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列对象的列名
|
}
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "成功!";
|
objJsonResult.data = ds.Tables[0];
|
objJsonResult.list = columnNameList;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "查询列表信息失败!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 单位换算删除
|
/// <summary>
|
/// 删除单位换算
|
/// </summary>
|
/// <returns></returns>
|
[Route("Gy_UnitConvertRateController/GetGy_UnitConvertRate_Delete_Json")]
|
[HttpGet]
|
public object GetGy_UnitConvertRate_Delete_Json(Int64 HItemID, string HMaker)
|
{
|
try
|
{
|
//判断权限
|
if (!DBUtility.ClsPub.Security_Log(ModRightNameDelete, 1, false, HMaker))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "您没有该模块删除功能权限,请与管理员联系!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCn.BeginTran();
|
//判断存在性
|
ds = oCn.RunProcReturn("select HNumber,HName from Gy_UnitConvertRate with(nolock) where HItemID= " + HItemID.ToString(), "Gy_UnitConvertRate");
|
if (ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
oCn.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "未查询到该单位换算,请刷新数据后重新选择!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
else
|
{
|
oCn.RunProc("Delete from Gy_UnitConvertRate where HItemID= " + HItemID.ToString(), ref DBUtility.ClsPub.sExeReturnInfo);
|
//写入日志
|
DBUtility.ClsPub.Add_Log("", "删除单位换算,代码:" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HNumber"]) + ",名称:" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HName"]), HMaker);
|
oCn.Commit();
|
objJsonResult.code = "0";
|
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 单位换算批量同步
|
/// <summary>
|
/// 从金蝶云批量同步单位换算至本地表
|
/// </summary>
|
[Route("Gy_UnitConvertRateController/GetGy_UnitConvertRate_BatchSync_Json")]
|
[HttpGet]
|
public object GetGy_UnitConvertRate_BatchSync_Json()
|
{
|
try
|
{
|
//获取系统参数
|
string sErrMsg = "";
|
if (oSystemParameter.ShowBill(ref sErrMsg) == true)
|
{
|
//系统参数是否为私有云模式,N为公有云模式,Y为私有云模式
|
//私有云模式,通过调用存储过程进行同步
|
if (oSystemParameter.omodel.WMS_CloudMode.ToUpper() == "Y")
|
{
|
ds = oCn.RunProcReturn("exec h_p_IFCLD_ERPDataToLocal_UnitConvertRate", "h_p_IFCLD_ERPDataToLocal_UnitConvertRate");
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "单位换算批量同步成功!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
//公有云模式,通过调用WEBAPI方式进行同步
|
else if (oSystemParameter.omodel.WMS_CloudMode.ToUpper() == "N")
|
{
|
//判断金蝶云是否登录成功
|
var loginRet = InvokeHelper.Login();
|
var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
|
//判断是否登录成功
|
if (isSuccess <= 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "批量同步失败,金蝶云登入不成功,请确认C盘配置文件所设置金蝶云对应网址、账套、登录用户、登录密码是否正确!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
var json = new
|
{
|
FormId = "BD_UNITCONVERTRATE",
|
FieldKeys = "FUNITCONVERTRATEID,FBILLNO,FMATERIALID,FUSEORGID,FCREATEORGID,FFORBIDSTATUS" +
|
",FCURRENTUNITID,FDESTUNITID,FCONVERTTYPE,FCONVERTNUMERATOR,FCONVERTDENOMINATOR" +
|
",FCREATORID,FCREATEDATE,FMODIFIERID,FMODIFYDATE,FAPPROVERID,FAPPROVEDATE,FFORBIDDERID,FFORBIDDATE",
|
FilterString = "",
|
OrderString = "",
|
TopRowCount = 0,
|
StartRow = 0,
|
Limit = 0
|
};
|
//查看 获取数据
|
var _result = InvokeHelper.Query("BD_UNITCONVERTRATE", JsonConvert.SerializeObject(json));
|
|
//反序列化
|
_result = _result.Replace("\"", "");
|
_result = _result.Replace("\n", "");
|
_result = _result.Replace(",[", "");
|
_result = _result.Replace("[", "");
|
string[] rows = _result.Split(new string[] { "]" }, StringSplitOptions.RemoveEmptyEntries); //以"]"分隔每一行并移除空行
|
string[,] arr = new string[rows.Length, rows[0].Split(',').Length]; //根据行和列数创建二维数组
|
for (int i = 0; i < rows.Length; i++) //遍历每一行
|
{
|
string[] cols = rows[i].Split(','); //以逗号分隔每一列
|
for (int j = 0; j < cols.Length; j++) //遍历每一列
|
{
|
arr[i, j] = cols[j]; //存入二维数组
|
}
|
}
|
|
oCn.BeginTran();
|
//清空单位换算表数据
|
oCn.RunProc("Delete from Gy_UnitConvertRate", ref DBUtility.ClsPub.sExeReturnInfo);
|
|
//输出二维数组
|
for (int i = 0; i < arr.GetLength(0); i++)
|
{
|
var subData = new
|
{
|
HItemID = DBUtility.ClsPub.isLong(arr[i, 0]),
|
HNumber = "",
|
HName = "",
|
HShortNumber = "",
|
HParentID = 0,
|
HLevel = 1,
|
HEndFlag = 1,
|
HStopflag = arr[i, 5].ToString() == "B" ? 1 : 0,
|
HRemark = "CLD-ERP导入",
|
HUseFlag = "已使用",
|
HUSEORGID = DBUtility.ClsPub.isLong(arr[i, 3]),
|
HCREATEORGID = DBUtility.ClsPub.isLong(arr[i, 4]),
|
HBILLNO = DBUtility.ClsPub.isStrNull(arr[i, 1]),
|
HMATERID = DBUtility.ClsPub.isLong(arr[i, 2]),
|
HCURRENTUNITID = DBUtility.ClsPub.isLong(arr[i, 6]),
|
HDESTUNITID = DBUtility.ClsPub.isLong(arr[i, 7]),
|
HCONVERTTYPE = DBUtility.ClsPub.isStrNull(arr[i, 8]),
|
HCONVERTNUMERATOR = DBUtility.ClsPub.isDoule(arr[i, 9]),
|
HCONVERTDENOMINATOR = DBUtility.ClsPub.isDoule(arr[i, 10]),
|
HFORBIDSTATUS = DBUtility.ClsPub.isStrNull(arr[i, 5]),
|
HUnitID = DBUtility.ClsPub.isLong(arr[i, 2] == "0" ? arr[i, 6] : "-1"),
|
HMakeEmp = DBUtility.ClsPub.isStrNull(arr[i, 11]),
|
HMakeTime = DBUtility.ClsPub.isDate(arr[i, 12]),
|
HCheckEmp = DBUtility.ClsPub.isStrNull(arr[i, 15]),
|
HCheckTime = DBUtility.ClsPub.isDate(arr[i, 16]),
|
HModifyEmp = DBUtility.ClsPub.isStrNull(arr[i, 13]),
|
HModifyTime = DBUtility.ClsPub.isDate(arr[i, 14]),
|
HStopEmp = DBUtility.ClsPub.isStrNull(arr[i, 17]),
|
HStopTime = DBUtility.ClsPub.isDate(arr[i, 18]),
|
};
|
|
//写入单位换算表数据
|
oCn.RunProc("set identity_insert Gy_UnitConvertRate on", ref DBUtility.ClsPub.sExeReturnInfo);
|
string sql = $@"Insert into Gy_UnitConvertRate
|
(HItemID,HNumber,HName,HShortNumber,HParentID,HLevel
|
,HEndFlag,HStopflag,HRemark,HUseFlag,HUSEORGID,HCREATEORGID
|
,HBILLNO,HMATERID,HCURRENTUNITID,HDESTUNITID,HCONVERTTYPE,HCONVERTNUMERATOR
|
,HCONVERTDENOMINATOR,HFORBIDSTATUS,HUnitID
|
,HMakeEmp,HMakeTime
|
,HCheckEmp,HCheckTime
|
,HModifyEmp,HModifyTime
|
,HStopEmp,HStopTime)
|
Values({subData.HItemID},'{subData.HNumber}','{subData.HName}','{subData.HShortNumber}',{subData.HParentID},{subData.HLevel}
|
,{subData.HEndFlag},{subData.HStopflag},'{subData.HRemark}','{subData.HUseFlag}',{subData.HUSEORGID},{subData.HCREATEORGID}
|
,'{subData.HBILLNO}',{subData.HMATERID},{subData.HCURRENTUNITID},{subData.HDESTUNITID},{subData.HCONVERTTYPE},{subData.HCONVERTNUMERATOR}
|
,{subData.HCONVERTDENOMINATOR},'{subData.HFORBIDSTATUS}',{subData.HUnitID}
|
,'{subData.HMakeEmp}',case when '{subData.HMakeTime}' = '1900/1/1 0:00:00' then NULL else '{subData.HMakeTime}' end
|
,'{subData.HCheckEmp}',case when '{subData.HCheckTime}' = '1900/1/1 0:00:00' then NULL else '{subData.HCheckTime}' end
|
,'{subData.HModifyEmp}',case when '{subData.HModifyTime}' = '1900/1/1 0:00:00' then NULL else '{subData.HModifyTime}' end
|
,'{subData.HStopEmp}',case when '{subData.HStopTime}' = '1900/1/1 0:00:00' then NULL else '{subData.HStopTime}' end)";
|
oCn.RunProc(sql.Replace("\r\n", ""));
|
oCn.RunProc("set identity_insert Gy_UnitConvertRate off", ref DBUtility.ClsPub.sExeReturnInfo);
|
}
|
oCn.Commit();
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "单位换算批量同步成功!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
else
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "不支持批量同步功能!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
else
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "获取系统参数失败! " + sErrMsg;
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单位换算批量同步失败!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
#endregion
|
|
}
|
}
|