using DBUtility;
|
using Model;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Converters;
|
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 KF_BarCodeStatusChangeBillController : ApiController
|
{
|
private json objJsonResult = new json();
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
DataSet ds;
|
|
#region [条码状态变更单列表]
|
[Route("KF_BarCodeStatusChangeBill/list")]
|
[HttpGet]
|
public object list(string sWhere, string user)
|
{
|
try
|
{
|
List<object> columnNameList = new List<object>(); //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量
|
if (sWhere == null || sWhere.Equals(""))
|
{
|
ds = oCN.RunProcReturn("select * from h_v_KF_BarCodeStatusChangeBillList order by HMainID asc", "h_v_KF_BarCodeStatusChangeBillList");
|
}
|
else
|
{
|
string sql1 = "select * from h_v_KF_BarCodeStatusChangeBillList where 1 = 1 ";
|
string sql = sql1 + sWhere + " order by HMainID asc";
|
ds = oCN.RunProcReturn(sql, "h_v_KF_BarCodeStatusChangeBillList");
|
}
|
foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用
|
{
|
Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType
|
string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接 // 将列名和数据类型信息拼接成一个JSON格式的字符串
|
columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];//代码将第一个DataTable(索引为0)赋值给objJsonResult的data属性
|
objJsonResult.list = columnNameList;//将columnNameList赋值给objJsonResult的list属性
|
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("KF_BarCodeStatusChangeBill/cx")]
|
[HttpGet]
|
public object cx(long HInterID)
|
{
|
try
|
{
|
|
ds = oCN.RunProcReturn("select * from h_v_KF_BarCodeStatusChangeBillList where HMainID =" + HInterID, "h_v_KF_BarCodeStatusChangeBillList");
|
if (ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "false!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
else
|
{
|
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("KF_BarCodeStatusChangeBill/BarCodeStatusChangeBillEdit")]
|
[HttpPost]
|
public object BarCodeStatusChangeBillEdit([FromBody] JObject sMainSub)
|
{
|
try
|
{
|
var _value = sMainSub["sMainSub"].ToString();
|
string msg1 = _value.ToString();
|
oCN.BeginTran();
|
//保存主表
|
objJsonResult = AddBillMain(msg1);
|
if (objJsonResult.code == "0")
|
{
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = objJsonResult.Message;
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
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;
|
}
|
}
|
|
public json AddBillMain(string msg1)
|
{
|
string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
string msg2 = sArray[0].ToString(); //主表数据
|
string msg3 = sArray[1].ToString(); //子表数据
|
int OperationType = int.Parse(sArray[2].ToString()); // 数据类型 1添加 3修改
|
string user = sArray[3].ToString();
|
|
try
|
{
|
msg2 = "[" + msg2.ToString() + "]";
|
List<ClsKF_BarCodeStatusChangeBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKF_BarCodeStatusChangeBillMain>>(msg2);
|
|
long HInterID = mainList[0].HInterID;//递入type得到的单据ID
|
string HBillNo = mainList[0].HBillNo;//递入type得到的单据号
|
long HBillStatus = 1;//单据号
|
long HPRDORGID = mainList[0].HPRDORGID;//组织
|
DateTime HDate = mainList[0].HDate;//日期
|
string HRemark = mainList[0].HRemark;//备注
|
long HEmpID = mainList[0].HEmpID;//变更人
|
long HDeptID = mainList[0].HDeptID;//部门
|
string HMaker = user;//制单人
|
|
DateTime dt = DateTime.Now;
|
|
//进行 会计期间 结账 的判断和控制
|
string s = "";
|
int sYear = 0;
|
int sPeriod = 0;
|
if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
|
{
|
objJsonResult.Message = s;
|
return objJsonResult;
|
}
|
|
//ds = oCN.RunProcReturn("select * from h_v_IF_POOrderBillList where hmainid=" + HInterID + " and 单据号='" + HBillNo + "'", "h_v_IF_POOrderBillList");
|
|
if ((OperationType == 1 || OperationType == 2))//新增 && ds.Tables[0].Rows.Count == 0
|
{
|
//DataSet Ds;
|
//Int64 NewHInterID = 1;
|
//Ds = oCN.RunProcReturn("select MAX(HInterID)HInterID from Cg_POOrderBillMain", "Cg_POOrderBillMain");
|
//if (Ds.Tables[0].Rows.Count != 0 && ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()) != 0)
|
//{
|
// NewHInterID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
|
// NewHInterID += 1;
|
//}
|
//主表
|
oCN.RunProc(@"Insert Into KF_BarCodeStatusChangeBillMain
|
(HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillNo,HBillStatus
|
,HRemark,HBackRemark,HMaker,HMakeDate,HMainSourceBillType,HMainSourceInterID
|
,HMainSourceEntryID,HMainSourceBillNo,HPrintQty,HEmpID,HDeptID)
|
values(" + HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + 1288 + "','" +
|
mainList[0].HBillSubType + "','" + HDate + "','" + HBillNo + "','" + HBillStatus + "','" + mainList[0].HRemark +
|
"','" + mainList[0].HBackRemark + "','" + mainList[0].HMaker + "','" + dt + "','" + mainList[0].HMainSourceBillType + "'," + mainList[0].HMainSourceInterID +
|
"," + mainList[0].HMainSourceEntryID + ",'" + mainList[0].HMainSourceBillNo + "'," + mainList[0].HPrintQty + "," + mainList[0].HEmpID + "," + mainList[0].HDeptID + ")");
|
}
|
else if (OperationType == 3)//|| ds.Tables[0].Rows.Count != 0
|
{ //修改
|
oCN.RunProc("update KF_BarCodeStatusChangeBillMain set " +
|
"HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" + ",HBillStatus=" + HBillStatus +
|
",HEmpID=" + HEmpID + ",HDeptID=" + HDeptID + " where HInterID=" + HInterID);
|
|
//删除子表
|
oCN.RunProc("delete from KF_BarCodeStatusChangeBillSub where HInterID='" + HInterID + "'");
|
}
|
//保存子表
|
objJsonResult = AddBillSub(msg3, HInterID, OperationType);
|
|
if (objJsonResult.code == "0")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = objJsonResult.Message;
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = null;
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
public json AddBillSub(string msg3, long HInterID, int OperationType)
|
{
|
List<ClsKF_BarCodeStatusChangeBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKF_BarCodeStatusChangeBillSub>>(msg3);
|
|
|
|
int i = 0;
|
foreach (ClsKF_BarCodeStatusChangeBillSub oSub in DetailColl)
|
{
|
i++;
|
|
DataSet Cs;
|
Int64 NewHEntryID = 1;
|
Cs = oCN.RunProcReturn("select MAX(HEntryID)HEntryID from KF_BarCodeStatusChangeBillSub", "KF_BarCodeStatusChangeBillSub");
|
if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()) != 0)
|
{
|
NewHEntryID = ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString());
|
NewHEntryID += 1;
|
}
|
|
oCN.RunProc($@"Insert into KF_BarCodeStatusChangeBillSub
|
(HInterID,HEntryID,HBillNo_bak,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty
|
,HRelationMoney,HBarCode,HBarCodeStatus_Old,HBarCodeStatus_New,HAuxPropID_Old,HAuxPropID_New,HMTONo_Old,HMTONo_New)
|
values({HInterID},{NewHEntryID},'{oSub.HBillNo_bak}','{oSub.HRemark}',{oSub.HSourceInterID}
|
,{oSub.HSourceEntryID},'{oSub.HSourceBillNo}','{oSub.HSourceBillType}',{oSub.HRelationQty},{oSub.HRelationMoney},'{oSub.HBarCode}','{oSub.HBarCodeStatus_Old}','{oSub.HBarCodeStatus_New}','{oSub.HAuxPropID_Old}','{oSub.HAuxPropID_New}','{oSub.HMTONo_Old}','{oSub.HMTONo_New}')");
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = null;
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
#endregion
|
|
#region [删除]
|
[Route("KF_BarCodeStatusChangeBill/Delete")]
|
[HttpGet]
|
public object Delete(string HInterID,string user)
|
{
|
try
|
{
|
//进行 会计期间 结账 的判断和控制
|
string s = "";
|
int sYear = 0;
|
int sPeriod = 0;
|
DateTime HDate = DateTime.Now;
|
if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
|
{
|
objJsonResult.Message = s;
|
return objJsonResult;
|
}
|
|
oCN.BeginTran();
|
oCN.RunProc("Delete From KF_BarCodeStatusChangeBillMain where HInterID = " + HInterID);
|
oCN.RunProc("Delete From KF_BarCodeStatusChangeBillSub where HInterID = " + HInterID);
|
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 = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
}
|
}
|