王 垚
2022-07-06 91fae0337579f3259c2920ed3ee0a742bd145127
WebAPI/Controllers/WebAPIController.cs
@@ -1,5 +1,8 @@
using DAL;
using DBUtility;
using Microsoft.AspNet.SignalR;
using Model;
using Newtonsoft.Json.Linq;
using SQLHelper;
using System;
using System.Collections.Generic;
@@ -7,9 +10,11 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using WebAPI.BLL;
using WebAPI.Models;
using WebAPI.Utility;
namespace WebAPI.Controllers
{
@@ -17,7 +22,7 @@
    {
        private JsonResult objJsonResult = new JsonResult();
        private json objjson = new json();
      //  private POInStockBillServices oclscg_poinstockbillmain = new POInStockBillServices();
        //  private POInStockBillServices oclscg_poinstockbillmain = new POInStockBillServices();
        public string sWhere = "";
        public WebServer webserver = new WebServer();
        public DataSet ds = new DataSet();
@@ -40,25 +45,25 @@
        public static bool Add_Log(string WorkList, string CurUserName, string State)
        {
                DBUtility.ClsPub.SetIPAddress();
               string IPAddress;
               string ComputerName;
               IPAddress = DBUtility.ClsPub.IPAddress;
               ComputerName = DBUtility.ClsPub.ComputerName;
                ClsCNSRM oCnLoc = new ClsCNSRM();
                try
                {
                    oCnLoc.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
                        "(getdate(),'" + CurUserName + "','" + ComputerName + "','" + WorkList + "','SRM系统','" + IPAddress + "','" + State + "')"
                        );
            DBUtility.ClsPub.SetIPAddress();
            string IPAddress;
            string ComputerName;
            IPAddress = DBUtility.ClsPub.IPAddress;
            ComputerName = DBUtility.ClsPub.ComputerName;
            ClsCNSRM oCnLoc = new ClsCNSRM();
            try
            {
                oCnLoc.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
                    "(getdate(),'" + CurUserName + "','" + ComputerName + "','" + WorkList + "','SRM系统','" + IPAddress + "','" + State + "')"
                    );
                    return true;
                }
                catch (Exception e)
                {
                    return false;
                return true;
            }
            catch (Exception e)
            {
                return false;
                }
            }
        }
        /// <summary>
@@ -131,6 +136,38 @@
            }
        }
        /// <summary>
        /// 获取登录页组织列
        /// </summary>
        /// <returns></returns>
        [Route("GetOrganizations")]
        [HttpGet]
        public object GetOrganizations()
        {
            try
            {
                ClsCN oCn = new ClsCN();
                DataSet oDs = new DataSet();
                //==========
                oDs = oCn.RunProcReturn("select HItemID ID,Hname Name,HStopflag Stopflag from Xt_ORGANIZATIONS", "Xt_ORGANIZATIONS");
                objjson.code = "1";
                objjson.count = 1;
                objjson.Message = "获取成功!";
                objjson.data = oDs.Tables[0];
                return objjson; ;
            }
            catch (Exception e)
            {
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "获取失败!异常" + e.ToString();
                objjson.data = null;
                return objjson; ;
            }
        }
        /// <summary>
        /// 登录
        /// </summary>
@@ -143,10 +180,19 @@
        {
            try
            {
                LogService.Write("测试登录错误");
                DataSet ds = null;
                ClsCNSRM oCnLoc = new ClsCNSRM();
                DAL.ClsUser oUser = new DAL.ClsUser();
                ds = oUser.CheckCzymc(UserName.Trim(), DBUtility.ClsPub.StrToPsd(PassWord.Trim()));
                Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
                LogService.Write("测试1:" + DBUtility.ClsPub.sExeReturnInfo);
                string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
                LogService.Write("测试2:" + DBUtility.ClsPub.sExeReturnInfo);
                LogService.Write(FCusName);
                if (FCusName == "夏宝电器")
                    ds = oUser.CheckMainID(UserName.Trim(), DBUtility.ClsPub.StrToPsd(PassWord.Trim()));
                else
                    ds = oUser.CheckCzymc(UserName.Trim(), DBUtility.ClsPub.StrToPsd(PassWord.Trim()));
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
@@ -157,6 +203,7 @@
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "登录成功!";
@@ -165,12 +212,13 @@
                    return objJsonResult;
                }
            }
            catch (Exception)
            catch (Exception e)
            {
                LogService.Write("异常" + e.Message.ToString());
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "登录异常!";
                objJsonResult.Message = "登录异常!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult; ;
            }
@@ -199,18 +247,19 @@
                    return objJsonResult; ;
                }
                //===========
                oDs = oCn.RunProcReturn("select Czmm from  Gy_Czygl where Czybm='" + UserName + "'", "Gy_Czygl");
                //LogService.Write("select Czmm from  Gy_Czygl where Czymc='" + UserName + "' and  Czmm = '" + DBUtility.ClsPub.StrToPsd(oldPassword.Trim()) + "'");
                oDs = oCn.RunProcReturn("select Czmm from  Gy_Czygl where Czymc='" + UserName + "' and  Czmm = '" + DBUtility.ClsPub.StrToPsd(oldPassword.Trim()) + "'", "Gy_Czygl");
                if (oDs == null || oDs.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有这个用户,不能修改密码!";
                    objJsonResult.Message = "原密码错误!";
                    objJsonResult.data = null;
                    return objJsonResult; ;
                }
                else
                {
                    oCn.RunProc("update  Gy_Czygl set Czmm='" + DBUtility.ClsPub.StrToPsd(PassWord.Trim()) + "' where Czybm='" + UserName.Trim() + "'");
                    oCn.RunProc("update  Gy_Czygl set Czmm='" + DBUtility.ClsPub.StrToPsd(PassWord.Trim()) + "' where Czymc='" + UserName.Trim() + "'");
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "* 密码修改成功!";
@@ -334,13 +383,13 @@
            try
            {
                oCn.BeginTran();
                oCn.RunProc("Insert into SRM_OpenTmp " +
                    " (HNumber,HModel,HName) " +
                    " Values('" + HNumber + "','" + HName + "','" + HName + "')", ref DBUtility.ClsPub.sExeReturnInfo);
                //修改上级为非末级代码
                //oCn.RunProc("Update Gy_OpenTmp set HEndflag=0 where HItemID=" + oModel.HParentID, ref ClsPub.sExeReturnInfo);
                oCn.Commit();
                //oCn.BeginTran();
                //oCn.RunProc("Insert into SRM_OpenTmp " +
                //    " (HNumber,HModel,HName) " +
                //    " Values('" + HNumber + "','" + HName + "','" + HName + "')", ref DBUtility.ClsPub.sExeReturnInfo);
                ////修改上级为非末级代码
                ////oCn.RunProc("Update Gy_OpenTmp set HEndflag=0 where HItemID=" + oModel.HParentID, ref ClsPub.sExeReturnInfo);
                //oCn.Commit();
                objjson.code = "0";
                objjson.count = 1;
                objjson.Message = "保存成功!";
@@ -370,9 +419,9 @@
            ClsCNSRM oCn = new ClsCNSRM();
            try
            {
                oCn.BeginTran();
                oCn.RunProc("Delete from SRM_OpenTmp where HItemID='" + DBUtility.ClsPub.isLong(HItemID) + "'", ref DBUtility.ClsPub.sExeReturnInfo);
                oCn.Commit();
                //oCn.BeginTran();
                //oCn.RunProc("Delete from SRM_OpenTmp where HItemID='" + DBUtility.ClsPub.isLong(HItemID) + "'", ref DBUtility.ClsPub.sExeReturnInfo);
                //oCn.Commit();
                objjson.code = "0";
                objjson.count = 1;
                objjson.Message = "删除成功!";
@@ -695,6 +744,106 @@
        #endregion
        /// <summary>
        /// 触发hub的api
        /// </summary>
        /// <param name="request">request</param>
        /// <returns>message</returns>
        [AllowAnonymous]
        [Route("show/hub"), HttpGet]
        public HttpResponseMessage GetMessage(HttpRequestMessage request)
        {
            var hub = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
            //注意这里的showMessage 就是对RepairHub下定义的showMessage方法调用,同样前端也是调用这个方法
            string aa = hub.Clients.All.showMessage("这里面可以放入任意对象,前台可以收到此内容");
            return request.CreateResponse(HttpStatusCode.OK, aa);
        }
        [Route("Message/MsgCount")]
        [HttpPost]
        public object MsgCount()
        {
            ClsCNSRM oCn = new ClsCNSRM();
            DataSet oDs = new DataSet();
            oDs = oCn.RunProcReturn("select * from  Gy_Message", "Gy_Message");
            objJsonResult.code = "0";
            objJsonResult.count = 0;
            objJsonResult.Message = "返回数据";
            objJsonResult.data = oDs;
            return objJsonResult; ;
        }
        #region [公告数据查询]
        [Route("MsgData")]
        [HttpGet]
        public object MsgData(string sWhere)
        {
            ClsCNSRM oCn = new ClsCNSRM();
            DataSet oDs = new DataSet();
            var sql = "select A.HInterID,b.HEntryID,A.HContext,A.HDeptID,D.HName HDeptName, A.HSendMan, B.HReceiveMan,A.HLevel,A.HDescription,case when B.HReadFlag=0 then '未阅' when B.HReadFlag=1 then '已阅' end HReadFlag,A.HDate" +
                " from OA_InformBillMain A inner join  OA_InformBillSub B on A.HInterID=B.HInterID left join Gy_Department D on A.HDeptID=D.HItemID where 1=1 " + sWhere;
            oDs = oCn.RunProcReturn(sql, "OA_InformBillMain");
            if (oDs.Tables[0].Rows.Count > 0)
            {
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "返回数据成功!";
                objJsonResult.data = oDs;
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "返回数据失败!";
                objJsonResult.data = oDs;
            }
            return objJsonResult; ;
        }
        #endregion
        #region[更改公告状态]
        [Route("UpdateMessage")]
        [HttpGet]
        public object UpdateMessage(string UserName, string HInterID, string HEntryID)
        {
            ClsCNSRM oCn = new ClsCNSRM();
            oCn.BeginTran();
            oCn.RunProc("Update OA_InformBillSub set HReadFlag=1 HUpDater='" + UserName + "',HUpDateDate=getdate() where HInterID='" + HInterID + "' and HEntryID='" + HEntryID + "'", ref ClsPub.sExeReturnInfo);
            oCn.Commit();
            objjson.code = "1";
            objjson.count = 1;
            objjson.Message = ClsPub.sExeReturnInfo;
            objjson.data = null;
            return objjson; ;
        }
        #endregion
        #region[打印idSession]
        [Route("linteridSession")]
        [HttpPost]
        public object linteridSession([FromBody] JObject linterid)
        {
            var _linterid = linterid["linterid"].ToString();
            var _huserName = linterid["HUserName"].ToString();
            var postMesseege = _linterid + ";" + _huserName;
            //HttpHelper.PostData("http://localhost:8082/AR-SRMLAYUI/layuiAdmin.std-v1.2.1/src/views/SRM/Api/SRM_Web_PoBarCodeBillApi.ashx", postMesseege);
            HttpHelper.PostData("http://60.191.21.116:9090/srmui/layuiAdmin.std-v1.2.1/src/views/SRM/Api/SRM_Web_PoBarCodeBillApi.ashx", postMesseege);
            SQLHelper.ClsCNSRM oCn = new SQLHelper.ClsCNSRM();
            string sql = $"Update Gy_BarCodeBill set HPrintQty=isnull(HPrintQty,0) + 1  where HItemID in ({_linterid})";
            oCn.RunProc(sql);
            objJsonResult.code = "0";
            objJsonResult.count = 0;
            objJsonResult.Message = "";
            objJsonResult.data = 1;
            return objJsonResult;
            //HttpContext.Current.Session["linterid"];
        }
        #endregion
    }
}