王 垚
2022-04-06 9167264eeb081fdbb94d8a1d2f76f35a6ccdd5fe
WebAPI/Controllers/²Ö´æ¹ÜÀí/ÌõÂë³öÈë¿â¼Ç¼/Kf_ICStockInOutBillController.cs
New file
@@ -0,0 +1,206 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Http;
using WebAPI.Models;
namespace WebAPI.Controllers.仓存管理.条码出入库记录
{
    public class Kf_ICStockInOutBillController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更)
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        //存储过程 æ•°æ® ç±»
        public class Data
        {
            public Data()
            {
                HStartDate = DateTime.Now.AddMonths(-1);
                HEndDate = DateTime.Now;
                BillType = "全部";
            }
            public DateTime HStartDate;//开始日期
            public DateTime HEndDate;//结束日期
            public string MaterialName;//物料
            public string sWH;//仓库
            public string sSP;//仓位
            public string sBatchNo;//批号
            public string HBarCode;//条形码
            public string BillType;//单据类型
            public string BillNo;//单据号
            public string SeOrderBillNo;//(销售订单号)
        }
        #region å‡ºå…¥åº“记录查询
        [Route("Kf_ICStockInOutBill/StockInOutBillList")]
        [HttpGet]
        public object StockInOutBillList(string sWhere)
        {
            List<object> columnNameList = new List<object>();
            try
            {
                var data = JsonConvert.DeserializeObject<Data>(sWhere);
                ds = oCN.RunProcReturn("exec h_p_Kf_BarCodeOutInReport '" +
                    data.HStartDate + "','" + data.HEndDate + "','" + data.MaterialName + "','" + data.sWH + "','" + data.sSP + "','" + data.sBatchNo + "','" + data.HBarCode + "','" + data.BillType + "','" + data.BillNo + "','" + data.SeOrderBillNo
                    + "'", "h_p_Kf_BarCodeOutInReport");
                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列对象的列名
                }
                //if (ds.Tables[0].Rows.Count > 0)
                //{
                objJsonResult.code = "1";
                objJsonResult.count = ds.Tables[0].Rows.Count;
                objJsonResult.Message = "获取资源绑定数据成功!";
                objJsonResult.data = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(ds.Tables[0], new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }));  //序列化DataSet中的时间格式,然后再反序列化回来
                objJsonResult.list = columnNameList;
                return objJsonResult;
                //}
                //else
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "暂无资源绑定!";
                //    objJsonResult.data = null;
                //    objJsonResult.list = columnNameList;
                //    return objJsonResult;
                //}
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message.ToString();
                objJsonResult.data = null;
                objJsonResult.list = columnNameList;
            }
            return objJsonResult;
        }
        #endregion
        #region æ¡ç å‡ºå…¥åº“缓存
        #region æ¡ç å‡ºå…¥åº“缓存列表
        [Route("Kf_ICStockInOutBill/GetPonderationBillMain_Temp")]
        [HttpGet]
        public object GetPonderationBillMain_Temp(string sWhere,string user)
        {
            try
            {
                //编辑权限
                if (!DBUtility.ClsPub.Security_Log_second("Gy_BarCodeBillList", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DataSet ds = new DataSet();
                string sql1 = string.Format(@"select * from h_v_KF_PonderationBillMain_Temp2 where 1=1 ");
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds= oCN.RunProcReturn(sql1 + "order by HInterID desc", "h_v_KF_PonderationBillMain_Temp2");
                }
                else
                {
                    ds = oCN.RunProcReturn(sql1 + sWhere + "order by HInterID desc", "h_v_KF_PonderationBillMain_Temp2");
                }
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查询数据异常,请与管理员联系!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "返回记录成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message.ToString();
                objJsonResult.data = null;
            }
            return objJsonResult;
        }
        #endregion
        #region æ¡ç å‡ºå…¥åº“缓存删除
        [Route("Kf_ICStockInOutBill/DelectPonderationBillMain_TempByID")]
        [HttpGet]
        public object DelectPonderationBillMain_TempByID(string HInterID, string user)
        {
            //编辑权限
            if (!DBUtility.ClsPub.Security_Log_second("Gy_BarCodeBillList_Delete", 1, false, user))
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "无删除权限!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            string s = "";
            Int64 lngBillKey = 0;
            lngBillKey = DBUtility.ClsPub.isLong(HInterID);
            if (lngBillKey == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "单据ID为空!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            DataSet ds = new DataSet();
            DataSet ds1 = new DataSet();
            ds = oCN.RunProcReturn("select * from KF_PonderationBillMain_Temp where HInterID="+ HInterID, "KF_PonderationBillMain_Temp");
            if (ds.Tables[0].Rows.Count!=0)
            {
                oCN.BeginTran();
                oCN.RunProc("delete from KF_PonderationBillMain_Temp where HInterID=" + HInterID);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "删除成功";
                objJsonResult.data = null;
                oCN.Commit();
                return objJsonResult;
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "单据未找到";
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
    }
}