using Model;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using Pub_Class;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Data.SqlClient;
|
using System.Web.Http;
|
using WebAPI.Models;
|
using WebAPI.Service;
|
|
namespace WebAPI.Controllers
|
{
|
public class Gy_StockPlace_Controller : ApiController
|
{
|
//获取系统参数
|
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
|
public DBUtility.ClsPub.Enum_BillStatus BillStatus;
|
|
private json objJsonResult = new json();
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
DataSet ds;
|
|
|
/// <summary>
|
/// 返回仓位列表
|
///参数:string sql。
|
///返回值:object。
|
/// </summary>
|
[Route("Gy_StockPlace/list")]
|
[HttpGet]
|
public object list(string sWhere, string user, string Organization)
|
{
|
try
|
{
|
List<object> columnNameList = new List<object>();
|
|
string sql1 = string.Format(@"select * from h_v_IF_StockPlaceList_ where 使用组织='" + Organization + "'");
|
if (sWhere == null || sWhere.Equals(""))
|
{
|
ds = oCN.RunProcReturn(sql1 + sWhere + " order by HMainID", "h_v_IF_StockPlaceList_");
|
}
|
else
|
{
|
string sql = sql1 + sWhere + " order by HMainID";
|
ds = oCN.RunProcReturn(sql, "h_v_IF_StockPlaceList_");
|
}
|
|
//添加列名
|
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 = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];
|
objJsonResult.list = columnNameList;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
/// <summary>
|
/// 根据基础资料ID 查找记录
|
///参数:string sql。
|
///返回值:object。
|
/// </summary>
|
[Route("Gy_StockPlace/cx")]
|
[HttpGet]
|
public object cx(long HInterID)
|
{
|
try
|
{
|
ds = oCN.RunProcReturn("select * from h_v_IF_StockPlaceList_ where HMainID = " + HInterID, "h_v_IF_StockPlaceList_");
|
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;
|
}
|
}
|
|
/// <summary>
|
/// 保存按钮
|
///参数:string sql。
|
///返回值:object。
|
/// </summary>
|
[Route("Gy_StockPlace/AddBill1")]
|
[HttpPost]
|
public object AddBill1([FromBody] JObject oMain)
|
{
|
|
try
|
{
|
var _value = oMain["oMain"].ToString();
|
string msg1 = _value.ToString();
|
string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
string msg2 = sArray[0].ToString();
|
|
//反序列化
|
msg2 = msg2.Replace("\\", "");
|
msg2 = msg2.Replace("\n", "");
|
msg2 = "[" + msg2.ToString() + "]";
|
List<ClsGy_StockPlace_Model> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsGy_StockPlace_Model>>(msg2);
|
|
long HItemID = list[0].HItemID;
|
string HNumber = list[0].HNumber;
|
string HName = list[0].HName;
|
string HShortNumber = list[0].HNumber;
|
string HRemark = list[0].HRemark;
|
string HHelpCode = list[0].HHelpCode;
|
long HSPGroupID = list[0].HSPGroupID;
|
bool HStopflag = list[0].HStopflag;
|
bool HStandard = list[0].HStandard;
|
string HUseFlag = "未审";
|
long HCREATEORGID = list[0].HCREATEORGID;
|
long HUSEORGID = list[0].HUSEORGID;
|
|
//保存
|
//保存完毕后处理
|
if (HItemID == 0)
|
{
|
//新增
|
oCN.BeginTran();
|
oCN.RunProc("Insert into Gy_StockPlace " +
|
" (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
|
",HLevel,HEndFlag,HStopflag,HRemark,HSPGroupID,HStandard,HUseFlag,HERPItemID," +
|
"HMakeTime,HCREATEORGID,HUSEORGID,HSPType,HDesSPType,HSrcSPType) " +
|
" Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + HShortNumber + "'," + 0 +
|
"," + 1 + "," + 1 + "," + Convert.ToString(HStopflag ? 1 : 0) + ",'" + HRemark + "'," + HSPGroupID + ","
|
+ Convert.ToString(HStandard ? 1 : 0) + ",'" + HUseFlag + "'," + 0 + ",'" + System.DateTime.Now.ToString("G") + "',"
|
+ HCREATEORGID + "," + HUSEORGID + ",' ',' ',' '" + ")", ref DBUtility.ClsPub.sExeReturnInfo);
|
|
oCN.Commit();
|
}
|
else
|
{
|
oCN.BeginTran();
|
//主表
|
oCN.RunProc("Update Gy_StockPlace set " +
|
" HNumber='" + HNumber + "'" +
|
",HName='" + HName + "'" +
|
",HHelpCode='" + HHelpCode + "'" +
|
",HSPGroupID=" + HSPGroupID +
|
",HUSEORGID=" + HUSEORGID +
|
",HStopflag=" + Convert.ToString(HStopflag ? 1 : 0) +
|
",HStandard=" + Convert.ToString(HStandard ? 1 : 0) +
|
",HRemark= '" + HRemark + "' Where HItemID=" + HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
|
oCN.Commit();
|
}
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "保存成功!";
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
//oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.Message;
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
/// <summary>
|
/// 仓位列表删除功能
|
/// </summary>
|
/// <returns></returns>
|
[Route("Deltet_Gy_StockPlace")]
|
[HttpGet]
|
public object Deltet_Gy_StockPlace(string HItemID, string user)
|
{
|
DataSet ds;
|
DataSet ds1;
|
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();//开始事务
|
ds = oCN.RunProcReturn("select * from Gy_StockPlace where HItemID=" + HItemID, "Gy_StockPlace");
|
if (ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "没有数据,无法删除!";
|
objJsonResult.data = null;
|
return objJsonResult; ;
|
}
|
ds1 = oCN.RunProcReturn("Select HItemID from Gy_StockPlace Where HParentID='" + HItemID + "'", "Gy_StockPlace");
|
if (ds1.Tables[0].Rows.Count != 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "此项目存在子项目,不能删除!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
string HUseFlag = Convert.ToString(ds.Tables[0].Rows[0]["HUseFlag"]);
|
if (HUseFlag == "已使用")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "此项目已使用,不能删除!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCN.RunProc("delete from Gy_StockPlace where HItemID=" + HItemID);
|
oCN.Commit();//提交事务
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "* 数据删除成功!";
|
objJsonResult.data = null;
|
return objJsonResult; ;
|
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "删除失败!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
}
|
}
|