From f3ad850c3ae72b8b76b2e1074eb51a71e86e8a40 Mon Sep 17 00:00:00 2001
From: yusijie <ysj@hz-kingdee.com>
Date: 星期五, 07 二月 2025 10:36:27 +0800
Subject: [PATCH] 安瑞条码内容错误修复;送货单编辑功能;送货单审核同步信息到金蝶时获取数据方式改为存储过程获取;夏宝修改连接金蝶表方式

---
 WebAPI/Controllers/WebAPIController.cs |  568 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 528 insertions(+), 40 deletions(-)

diff --git a/WebAPI/Controllers/WebAPIController.cs b/WebAPI/Controllers/WebAPIController.cs
index 1ecfa5b..a578e16 100644
--- a/WebAPI/Controllers/WebAPIController.cs
+++ b/WebAPI/Controllers/WebAPIController.cs
@@ -1,15 +1,22 @@
 锘縰sing DAL;
+using DBUtility;
+using Microsoft.AspNet.SignalR;
 using Model;
+using Newtonsoft.Json.Linq;
+using Pub_Class;
 using SQLHelper;
 using System;
 using System.Collections.Generic;
 using System.Data;
+using System.Data.SqlClient;
 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 +24,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 +47,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;
+            ClsCN oCnLoc = new ClsCN();
+            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>
@@ -78,7 +85,7 @@
             {
                 string VsWhere = "";
                 string PcWhere = "";
-                SQLHelper.ClsCNSRM oCn = new SQLHelper.ClsCNSRM();
+                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                 DataSet ds;
                 //鍏朵粬杩囨护
                 if (msg.Trim() == "")
@@ -131,6 +138,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>
@@ -144,9 +183,19 @@
             try
             {
                 DataSet ds = null;
-                ClsCNSRM oCnLoc = new ClsCNSRM();
+                ClsCN oCnLoc = new ClsCN();
                 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(FCusName);
+                LogService.Write("DBUtility.ClsPub.StrToPsd(PassWord.Trim()):" + DBUtility.ClsPub.StrToPsd(PassWord.Trim()));
+                //if (FCusName == "澶忓疂鐢靛櫒")
+                //    ds = CheckMainID(UserName.Trim(), DBUtility.ClsPub.StrToPsd(PassWord.Trim()));
+                //else
+                //    ds = CheckCzymc(UserName.Trim(), DBUtility.ClsPub.StrToPsd(PassWord.Trim()));
+
+                ds = CheckMainID(UserName.Trim(), DBUtility.ClsPub.StrToPsd(PassWord.Trim()));
                 if (ds == null || ds.Tables[0].Rows.Count == 0)
                 {
                     objJsonResult.code = "0";
@@ -165,16 +214,44 @@
                     return objJsonResult;
                 }
             }
-            catch (Exception)
+            catch (Exception e)
             {
 
                 objJsonResult.code = "0";
                 objJsonResult.count = 0;
-                objJsonResult.Message = "鐧诲綍寮傚父锛�";
+                objJsonResult.Message = "鐧诲綍寮傚父锛�" + e.ToString();
                 objJsonResult.data = null;
                 return objJsonResult; ;
             }
         }
+        public DataSet CheckMainID(string MainID, string sPsd)
+        {
+            DataSet DS;
+            try
+            {
+                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
+                DS = oCn.RunProcReturn("select * from Gy_Czygl where Czybm='" + MainID + "' and Czmm='" + sPsd + "' ", "Gy_Czygl");
+                if (DS.Tables[0].Rows.Count == 0)
+                    return null;
+                else
+                {
+                    return DS;
+                }
+            }
+            catch (Exception e)
+            {
+                throw (e);
+            }
+        }
+        public DataSet CheckCzymc(string sUser, string sPsd)
+        {
+            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
+            SqlParameter[] prams ={oCn.MakeInParam("@Czymc",SqlDbType.VarChar,100,sUser ),
+                                    oCn.MakeInParam("@Czmm",SqlDbType.VarChar ,100,sPsd ),
+            };
+            return oCn.RunProcReturn("select * from Gy_Czygl where Czymc='" + sUser + "' and Czmm='" + sPsd + "' ", prams, "Gy_Czygl");
+        }
+
         /// <summary>
         /// 淇敼瀵嗙爜
         /// </summary>
@@ -187,7 +264,7 @@
         {
             try
             {
-                ClsCNSRM oCn = new ClsCNSRM();
+                ClsCN oCn = new ClsCN();
                 DataSet oDs = new DataSet();
                 //==========
                 if (PassWord.Trim() != Repassword.Trim())
@@ -199,18 +276,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 = "* 瀵嗙爜淇敼鎴愬姛锛�";
@@ -330,17 +408,17 @@
         [HttpGet]
         public object SaveOpenTmp(string HNumber, string HName)
         {
-            ClsCNSRM oCn = new ClsCNSRM();
+            ClsCN oCn = new ClsCN();
             try
             {
 
-                oCn.BeginTran();
-                oCn.RunProc("Insert into SRM_OpenTmp " +
-                    " (HNumber,HModel,HName) " +
-                    " Values('" + HNumber + "','" + HName + "','" + HName + "')", ref DBUtility.ClsPub.sExeReturnInfo);
-                //淇敼涓婄骇涓洪潪鏈骇浠g爜
-                //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);
+                ////淇敼涓婄骇涓洪潪鏈骇浠g爜
+                ////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 = "淇濆瓨鎴愬姛!";
@@ -367,12 +445,12 @@
         [HttpGet]
         public object DelOpenTmp(string HItemID)
         {
-            ClsCNSRM oCn = new ClsCNSRM();
+            ClsCN oCn = new ClsCN();
             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 = "鍒犻櫎鎴愬姛!";
@@ -390,6 +468,87 @@
             }
 
         }
+        /// <summary>
+        /// 璁剧疆榛樿鎵撳嵃妯℃澘
+        /// </summary>
+        /// <returns></returns>
+        [Route("Open_PrintTem/DefaultOpenTmp")]
+        [HttpGet]
+        public object DefaultOpenTmp(string HNumber, string HName)
+        {
+            ClsCN oCn = new ClsCN();
+            try
+            {
+                oCn.BeginTran();
+                //鍏堟妸姝ゆā鍧椾笅鐨勬ā鏉块粯璁ゆā鏉挎爣璁伴兘鍏抽棴
+                oCn.RunProc("update SRM_OpenTmp set HStdFlag = 0 where HNumber='" + HNumber + "'", ref DBUtility.ClsPub.sExeReturnInfo);
+                //鏇存柊褰撳墠妯℃澘涓洪粯璁ゆā鏉�
+                oCn.RunProc("update SRM_OpenTmp set HStdFlag = 1 where HNumber='" + HNumber + "' and HName='" + HName + "'", ref DBUtility.ClsPub.sExeReturnInfo);
+                oCn.Commit();
+                objjson.code = "0";
+                objjson.count = 1;
+                objjson.Message = "璁剧疆鎴愬姛!";
+                objjson.data = null;
+                return objjson;
+            }
+            catch (Exception e)
+            {
+                oCn.RollBack();
+                objjson.code = "0";
+                objjson.count = 0;
+                objjson.Message = "璁剧疆澶辫触" + e.ToString();
+                objjson.data = null;
+                return objjson;
+            }
+        }
+
+        #region [鑾峰彇榛樿鎵撳嵃妯℃澘]
+        /// <summary>
+        /// 鑾峰彇鎵撳嵃妯℃澘鍒楄〃
+        /// </summary>
+        /// <returns></returns>
+        [Route("Open_PrintTem/GetDefaultOpenTmp_Json")]
+        [HttpGet]
+        public object GetDefaultOpenTmp_Json(string HNumber)
+        {
+            sWhere = " Where 榛樿鏍囪=1 ";
+            //sWhere = " Where HStopFlag=0  and HEndFlag=1  and HUSEORGID = " + DBUtility.ClsPub.HORGANIZATIONSID.ToString();
+            if (HNumber != "")
+            {
+                sWhere = sWhere + " and ( HNumber = '" + HNumber + "') ";
+            }
+            ClsCN oCn = new ClsCN();
+            try
+            {
+                ds = oCn.RunProcReturn("select * from h_v_IF_OpenTmpList " + sWhere, "h_v_IF_OpenTmpList");
+                if (ds == null || ds.Tables[0].Rows.Count <= 0)
+                {
+                    objjson.code = "0";
+                    objjson.count = 0;
+                    objjson.Message = "鑾峰彇澶辫触,娌℃湁璁剧疆榛樿妯℃澘" + DBUtility.ClsPub.sErrInfo;
+                    objjson.data = null;
+                    return objjson;
+                }
+                else
+                {
+                    objjson.code = "0";
+                    objjson.count = 1;
+                    objjson.Message = "鑾峰彇鎴愬姛!";
+                    objjson.data = ds.Tables[0];
+                    return objjson;
+                }
+            }
+            catch (Exception ex)
+            {
+                objjson.code = "0";
+                objjson.count = 0;
+                objjson.Message = "寮傚父" + ex.ToString();
+                objjson.data = null;
+                return objjson;
+            }
+        }
+        #endregion
+
         #region 鍩虹璧勬枡
         /// <summary>
         /// 鑾峰彇浠撳簱鍒楄〃
@@ -695,6 +854,335 @@
         #endregion
 
 
-  
+        /// <summary>
+        /// 瑙﹀彂hub鐨刟pi
+        /// </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>();
+            //娉ㄦ剰杩欓噷鐨剆howMessage 灏辨槸瀵筊epairHub涓嬪畾涔夌殑showMessage鏂规硶璋冪敤,鍚屾牱鍓嶇涔熸槸璋冪敤杩欎釜鏂规硶
+            string aa = hub.Clients.All.showMessage("杩欓噷闈㈠彲浠ユ斁鍏ヤ换鎰忓璞�,鍓嶅彴鍙互鏀跺埌姝ゅ唴瀹�");
+            return request.CreateResponse(HttpStatusCode.OK, aa);
+        }
+
+        [Route("Message/MsgCount")]
+        [HttpPost]
+        public object MsgCount()
+        {
+            ClsCN oCn = new ClsCN();
+            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)
+        {
+            ClsCN oCn = new ClsCN();
+            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)
+        {
+            ClsCN oCn = new ClsCN();
+            oCn.BeginTran();
+            oCn.RunProc("Update OA_InformBillSub set HReadFlag=1 HUpDater='" + UserName + "',HUpDateDate=getdate() where HInterID='" + HInterID + "' and HEntryID='" + HEntryID + "'", ref Pub_Class.ClsPub.sExeReturnInfo);
+            oCn.Commit();
+            objjson.code = "1";
+            objjson.count = 1;
+            objjson.Message = Pub_Class.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/ZYMES/layuiAdmin.std-v1.2.1/src/views/SRM/Api/SRM_Web_PoBarCodeBillApi.ashx", postMesseege);
+            HttpHelper.PostData("http://60.191.21.115:9090/layuiAdmin.std-v1.2.1/src/views/SRM/Api/SRM_Web_PoBarCodeBillApi.ashx", postMesseege);
+            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
+            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
+
+        /// <summary>
+        /// 琛ㄥご淇℃伅
+        /// </summary>
+        /// <param name="sMsg"></param>
+        /// <returns></returns>
+        [Route("Web/GetMAXNum")]
+        [HttpGet]
+        public object GetMAXNum(string HBillType)
+        {
+            try
+            {
+                string HBillNo = "";
+                Int64 HInterID = 0;//鏄剧ず鐨勫瓧娈�
+                HInterID = DBUtility.ClsPub.CreateBillID(HBillType, ref DBUtility.ClsPub.sExeReturnInfo);
+                HBillNo = DBUtility.ClsPub.CreateBillCode(HBillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
+                //----------鍒涘缓铏氳〃------------------------
+                DataTable dt_Main = new DataTable("Json");
+                dt_Main.Columns.Add("HBillNo", typeof(string));
+                dt_Main.Columns.Add("HInterID", typeof(int));
+                //---------鍒涘缓鏂拌------------------------
+                DataRow dr_main = dt_Main.NewRow();//鍒涘缓鏂拌 
+                dt_Main.Rows.Add(dr_main);//灏嗘柊琛屽姞鍏ュ埌琛ㄤ腑
+                dr_main["HBillNo"] = DBUtility.ClsPub.isStrNull(HBillNo);
+                dr_main["HInterID"] = DBUtility.ClsPub.isLong(HInterID);
+
+                if (HBillNo == null || HInterID == 0)
+                {
+                    objjson.code = "0";
+                    objjson.count = 0;
+                    objjson.Message = "鑾峰彇澶辫触";
+                    objjson.data = null;
+                    return objjson;
+                }
+                else
+                {
+                    objjson.code = "0";
+                    objjson.count = 1;
+                    objjson.Message = "鑾峰彇鎴愬姛";
+                    objjson.data = dt_Main;
+                    return objjson;
+                }
+            }
+            catch (Exception e)
+            {
+                objjson.code = "0";
+                objjson.count = 0;
+                objjson.Message = "鑾峰彇澶辫触" + e.ToString();
+                objjson.data = null;
+                return objjson;
+            }
+        }
+
+        //寰楀埌鏈�澶INTERID
+        public static Int64 CreateBillID(string BillCode, ref string sReturn)
+        {
+            string BillType = "";
+            DataSet Ds;
+            ClsSqlHelper oCn = new ClsSqlHelper();
+            Int64 lID;
+            Ds = oCn.RunProcReturn("select * from Gy_BillNumber with (nolock) where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber");
+            if (Ds.Tables[0].Rows.Count != 0)
+            {
+                lID = Pub_Class.ClsPub.isLong(Ds.Tables[0].Rows[0]["IDNow"].ToString());
+                BillType = Ds.Tables[0].Rows[0]["BillType"].ToString().Trim();
+            }
+            else
+            {
+                lID = 0;
+            }
+            //鍚岀被鍨嬪崟鎹� 鑷1
+            if (BillType.Trim() != "")
+            {
+                oCn.RunProc("update Gy_BillNumber set IDNow=IDNow+1 where BillType='" + BillType.Trim() + "'");
+            }
+            oCn.CnClose();
+            oCn.CnDispose();
+            oCn = null;
+            Ds = null;
+            return lID;
+        }
+
+        //寰楀埌鏈�澶у崟鎹彿
+        public static string CreateBillCode(string BillCode, ref string sReturn, bool Add)
+        {
+            Int64 BillCodeMode;
+            string Profix;
+            Int64 Glida;
+            Int32 CodeLen;
+            string sBillNo = "";
+            char c = Convert.ToChar("0");
+            string sKjYear = DateTime.Today.Year.ToString();
+            string sPeriod = DateTime.Today.Month.ToString();
+            string sDay = DateTime.Today.Day.ToString();
+            //寰楀埌鍗曟嵁鍙疯〃 淇℃伅
+            ClsSqlHelper oCn = new ClsSqlHelper();
+            DataSet Ds = new DataSet();
+            Ds = oCn.RunProcReturn("Select * from Gy_BillNumber where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber");
+            if (Ds.Tables[0].Rows.Count != 0)
+            {
+                BillCodeMode = Pub_Class.ClsPub.isLong(Ds.Tables[0].Rows[0]["BillCodeMode"].ToString());
+                Profix = Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Profix"].ToString());
+                Glida = Pub_Class.ClsPub.isLong(Ds.Tables[0].Rows[0]["Glida"].ToString());
+                CodeLen = Pub_Class.ClsPub.isInt(Ds.Tables[0].Rows[0]["CodeLen"].ToString());
+            }
+            else
+            {
+                return "";
+            }
+            //
+            string sStr;
+            switch (BillCodeMode)
+            {
+                case 0:
+                    switch (Glida)
+                    {
+                        case 0://绾祦姘村彿
+                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "'", "Gy_MaxNum");
+                            if (Ds.Tables[0].Rows.Count != 0)
+                            {
+                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
+                                sBillNo = Profix.Trim() + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
+                            }
+                            else //鎻掑叆鏂拌褰�
+                            {
+                                sStr = new string(c, CodeLen - 1);
+                                oCn.RunProc("insert into Gy_MaxNum(BillCode,NowNumber) values('" + BillCode.Trim() + "',1)");
+                                sBillNo = Profix.Trim() + sStr + 1;
+                            }
+                            if (Add == true)
+                            {
+                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "'");
+                            }
+                            return sBillNo;
+
+                        case 1://鏍规嵁 YY骞�+MM鏈� 鏃� + 娴佹按鍙�  鐢熸垚鍗曟嵁鍙� 锛堟棩 閲囩敤浜� 浠撳簱鐨勫瓧娈碉級
+                            sKjYear = sKjYear.Substring(2, 2);
+                            sPeriod = "0" + sPeriod;
+                            sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
+                            sDay = "";
+                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum");
+                            if (Ds.Tables[0].Rows.Count != 0)
+                            {
+                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
+                                sBillNo = Profix.Trim() + sKjYear + sPeriod + sDay + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
+                            }
+                            else //鎻掑叆鏂拌褰�
+                            {
+                                sStr = new string(c, CodeLen - 1);
+                                oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)");
+                                sBillNo = Profix.Trim() + sKjYear + sPeriod + sDay + sStr + "1";
+                            }
+                            if (Add == true)
+                            {
+                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'");
+                            }
+                            return sBillNo;
+                        case 2:      //鏍规嵁骞�+鏈�+鏃�  鐢熸垚鍗曟嵁鍙�
+                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum");
+                            if (Ds.Tables[0].Rows.Count != 0)
+                            {
+                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
+                                sBillNo = Profix.Trim() + sKjYear + Pub_Class.ClsPub.isStrNull(("0" + sPeriod)).Substring(Pub_Class.ClsPub.isStrNull(("0" + sPeriod)).Length - 2, 2) + Pub_Class.ClsPub.isStrNull(("0" + sDay)).Substring(Pub_Class.ClsPub.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
+                            }
+                            else //鎻掑叆鏂拌褰�
+                            {
+                                sStr = new string(c, CodeLen - 1);
+                                oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)");
+                                sBillNo = Profix.Trim() + sKjYear + Pub_Class.ClsPub.isStrNull(("0" + sPeriod)).Substring(Pub_Class.ClsPub.isStrNull(("0" + sPeriod)).Length - 2, 2) + Pub_Class.ClsPub.isStrNull(("0" + sDay)).Substring(Pub_Class.ClsPub.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + 1;
+                            }
+                            if (Add == true)
+                            {
+                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'");
+                            }
+                            return sBillNo;
+                        case 3: //鏍规嵁 涔斾竴 锛圫 + 骞达紙23锛�+浜斾綅娴佹按鍙凤級瀹炰緥锛歋2300001
+                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='0'  and whcode=''", "Gy_MaxNum");
+                            sKjYear = sKjYear.Substring(2, 2);
+                            if (Ds.Tables[0].Rows.Count != 0)
+                            {
+                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
+                                Profix = Profix.Substring(0, 1);
+                                sBillNo = Profix.Trim() + sKjYear + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
+                            }
+                            else //鎻掑叆鏂拌褰�
+                            {
+                                sStr = new string(c, CodeLen - 1);
+                                oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)");
+                                sBillNo = Profix.Trim() + sKjYear + sStr + 1;
+                            }
+                            if (Add == true)
+                            {
+                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='0'  and whcode=''");
+                            }
+                            return sBillNo;
+                        case 4: //鏍规嵁 涔斾竴 宸ュ簭娴佽浆鍗″彿鏀规垚骞�+鏈�+鍥涗綅娴佹按鍙凤紙23050001锛�
+                            Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='0'  and whcode=''", "Gy_MaxNum");
+                            sKjYear = sKjYear.Substring(2, 2);
+                            sPeriod = "0" + sPeriod;
+                            sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
+                            if (Ds.Tables[0].Rows.Count != 0)
+                            {
+                                sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length);
+                                sBillNo = sKjYear + sPeriod + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim();
+                            }
+                            else //鎻掑叆鏂拌褰�
+                            {
+                                sStr = new string(c, CodeLen - 1);
+                                oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)");
+                                sBillNo = sKjYear + sPeriod + sStr + 1;
+                            }
+                            if (Add == true)
+                            {
+                                oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='0'  and whcode=''");
+                            }
+                            return sBillNo;
+                        default:
+                            return sBillNo;
+
+                    }
+
+                case 1:
+                    return sBillNo;
+
+                default:
+                    return sBillNo;
+
+            }
+            oCn.CnClose();
+            oCn.CnDispose();
+            oCn = null;
+        }
+
     }
 }

--
Gitblit v1.9.1