| 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; | 
|   | 
| namespace WebAPI.Controllers.项目管理.基础建模 | 
| { | 
|     #region 客户信息列表 新增、查询、删除 | 
|     public class PM_CustomerProInfoBillController : ApiController | 
|     { | 
|         //获取系统参数 | 
|         Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); | 
|         public DBUtility.ClsPub.Enum_BillStatus BillStatus; | 
|         public DAL.ClsCustomerProInfoBill BillOld = new DAL.ClsCustomerProInfoBill(); | 
|         public DAL.ClsCustomerProInfoBill BillNew0 = new DAL.ClsCustomerProInfoBill(); | 
|   | 
|         private json objJsonResult = new json(); | 
|         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
|         DataSet ds; | 
|   | 
|         /// <summary> | 
|         /// 获取客户信息列表 | 
|         /// </summary> | 
|         /// <param name="sWhere"></param> | 
|         /// <param name="user"></param> | 
|         /// <returns></returns> | 
|         [Route("PM_ProInfo/PM_ProInfolist")] | 
|         [HttpGet] | 
|         public object GetProInfoBillList(string sWhere, string user) | 
|         { | 
|             json res = new json(); | 
|             try | 
|             { | 
|                 //权限查看 | 
|                 if(!DBUtility.ClsPub.Security_Log("PM_CustomerProInfoBill_Query", 1, false, user)) | 
|                 { | 
|                     res.code = "0"; | 
|                     res.count = 0; | 
|                     res.Message = "无查看权限!"; | 
|                     res.data = null; | 
|                     return res; | 
|                 } | 
|                 DataSet ds = new DataSet(); | 
|                 SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
|                 if (sWhere == null || sWhere.Equals("")) | 
|                 { | 
|                     ds = oCN.RunProcReturn("select * from h_v_PM_CustomerProInfoBill order by 单据号 desc", "h_v_PM_CustomerProInfoBill"); | 
|                 } | 
|                 else | 
|                 { | 
|                     string sql1 = "select * from h_v_PM_CustomerProInfoBill where 1 = 1 "; | 
|                     string sql = sql1 + sWhere + " order by 单据号 desc"; | 
|                     ds = oCN.RunProcReturn(sql, "h_v_PM_CustomerProInfoBill"); | 
|                 } | 
|                 List<object> columnNameList = new List<object>(); | 
|                 //添加列名 | 
|                 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列对象的列名 | 
|                 } | 
|   | 
|                 res.code = "1"; | 
|                 res.count = 1; | 
|                 res.Message = "Sucess!"; | 
|                 res.data = ds.Tables[0]; | 
|                 res.list = columnNameList; | 
|                 return res; | 
|             } | 
|             catch(Exception e) | 
|             { | 
|                 res.code = "0"; | 
|                 res.count = 0; | 
|                 res.Message = "Exception!" + e.ToString(); | 
|                 res.data = null; | 
|                 return res; | 
|             } | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 保存或更新 | 
|         /// </summary> | 
|         /// <param name="msg"></param> | 
|         /// <returns></returns> | 
|         [Route("PM_ProInfo/SavePM_ProInfoBill")] | 
|         [HttpPost] | 
|         public object SavePM_ProInfoBill([FromBody] JObject msg) | 
|         { | 
|             var _value = msg["msg"].ToString(); | 
|             string msg1 = _value.ToString(); | 
|             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | 
|             string msg2 = sArray[0].ToString();                             //表头数据 | 
|             string msg3 = sArray[1].ToString();                             //子表1数据 | 
|             string refSav = sArray[2].ToString();                           //操作方式 | 
|             string msg4 = sArray[3].ToString();                             //用户 | 
|   | 
|             DBUtility.ClsPub.CurUserName = msg4; | 
|   | 
|             string UserName = ""; | 
|             string s = ""; | 
|             ListModels oListModels = new ListModels(); | 
|             try | 
|             { | 
|                 //编辑权限 | 
|                 if (!DBUtility.ClsPub.Security_Log_second("PM_CustomerProInfoBill_Edit", 1, false, msg4)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "无保存权限!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 DAL.ClsCustomerProInfoBill oBill = new DAL.ClsCustomerProInfoBill(); | 
|                 List<Model.ClsPM_CustomerProInfoBillMain> lsmain = new List<Model.ClsPM_CustomerProInfoBillMain>(); | 
|                 msg2 = msg2.Replace("\\", ""); | 
|                 msg2 = msg2.Replace("\n", "");  //\n | 
|                 lsmain = oListModels.getObjectByJson_ClsPM_CustomerProInfoBillMain(msg2); | 
|                 foreach (Model.ClsPM_CustomerProInfoBillMain oItem in lsmain) | 
|                 { | 
|                     if (refSav == "Add") | 
|                     { | 
|                         //单据号是否重复 | 
|                         if (BillNew0.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, BillOld.omodel.HInterID)) | 
|                         { | 
|                             objJsonResult.code = "0"; | 
|                             objJsonResult.count = 0; | 
|                             objJsonResult.Message = "单据号重复!不允许保存!"; | 
|                             objJsonResult.data = 1; | 
|                             return objJsonResult; | 
|                         } | 
|                     } | 
|                     if (refSav == "Update") | 
|                     { | 
|                         if (BillOld.ShowBill(oItem.HInterID, ref s) == false) | 
|                         { | 
|                             objJsonResult.code = "0"; | 
|                             objJsonResult.count = 0; | 
|                             objJsonResult.Message = "此单据有误!"; | 
|                             objJsonResult.data = 1; | 
|                             return objJsonResult; | 
|                         } | 
|                         //判断是否可编辑 | 
|                         if (BillOld.omodel.HChecker != "" && BillOld.omodel.HChecker != null) | 
|                         { | 
|                             objJsonResult.code = "0"; | 
|                             objJsonResult.count = 0; | 
|                             objJsonResult.Message = "此单据已经被审核,不允许修改!"; | 
|                             objJsonResult.data = 1; | 
|                             return objJsonResult; | 
|                         } | 
|                         if (BillOld.omodel.HBillStatus > 1) | 
|                         { | 
|                             objJsonResult.code = "0"; | 
|                             objJsonResult.count = 0; | 
|                             objJsonResult.Message = "此单据处于不可编辑状态,不允许修改!"; | 
|                             objJsonResult.data = 1; | 
|                             return objJsonResult; | 
|                         } | 
|                         if (!DBUtility.Xt_BaseBillFun.Fun_AllowEditBill(BillOld, ref s)) | 
|                         { | 
|                             objJsonResult.code = "0"; | 
|                             objJsonResult.count = 0; | 
|                             objJsonResult.Message = s + ",不允许修改"; | 
|                             objJsonResult.data = 1; | 
|                             return objJsonResult; | 
|                         } | 
|   | 
|                         string sql = "select count(*) PM_CustomerProInfoBillCount from PM_CustomerProInfoBillMain  where HMainSourceInterID = " + BillOld.omodel.HInterID; | 
|                         ds = oCN.RunProcReturn(sql, "PM_CustomerProInfoBillMain"); | 
|                         if (ds != null && Int64.Parse(ds.Tables[0].Rows[0]["PM_CustomerProInfoBillCount"].ToString()) > 0) | 
|                         { | 
|                             objJsonResult.code = "0"; | 
|                             objJsonResult.count = 0; | 
|                             objJsonResult.Message = "保存失败,单据存在下游单据[特批申请单]!"; | 
|                             objJsonResult.data = 1; | 
|                             return objJsonResult; | 
|                         } | 
|                     } | 
|                     UserName = oItem.HMaker;  //制单人 | 
|                     oItem.HBillType = "4764"; | 
|                     //oItem.HBillSubType = "1401"; | 
|   | 
|                     oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year); | 
|                     oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month); | 
|                     oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd")); | 
|   | 
|                     if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "") | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "保存失败!没有单据日期,无法保存!"; | 
|                         objJsonResult.data = 1; | 
|                         return objJsonResult; | 
|                     } | 
|                     oBill.omodel = oItem; | 
|                 } | 
|                 //表体数据 | 
|                 //按 },{来拆分数组 //去掉【和】 | 
|                 msg3 = msg3.Substring(1, msg3.Length - 2); | 
|                 msg3 = msg3.Replace("\\", ""); | 
|                 msg3 = msg3.Replace("\n", "");  //\n | 
|                 //msg2 = msg2.Replace("'", "’"); | 
|                 //List<Model.ClsPM_CustomerProInfoBillSub> ls = new List<Model.ClsPM_CustomerProInfoBillSub>(); | 
|                 //ls = oListModels.getObjectByJson_ClsPM_CustomerProInfoBillSub(msg3); | 
|                 //int i = 0; | 
|                 //foreach (Model.ClsPM_CustomerProInfoBillSub oItemSub in ls) | 
|                 //{ | 
|                 //    i++; | 
|                 //    oItemSub.HEntryID = i; | 
|   | 
|                     //oItemSub.HCloseMan = "";       //行关闭 | 
|                     //oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now); | 
|                     //oItemSub.HCloseType = false;   //关闭类型 | 
|                     //oItemSub.HRemark = "";         //备注 | 
|   | 
|                     //oItemSub.HSourceInterID = 0;     // 源单主内码 | 
|                     //oItemSub.HSourceEntryID = 0;   //源单子内码 | 
|                     //oItemSub.HSourceBillNo = "";  //源单单号 | 
|                     //oItemSub.HSourceBillType = ""; //源单类型 | 
|                     //oItemSub.HRelationQty = 0;     //关联数量 | 
|                     //oItemSub.HRelationMoney = 0;   //关联金额  | 
|   | 
|                 //    if (oItemSub.HItemSubID != 0) | 
|                 //    { | 
|                 //        oBill.DetailColl.Add(oItemSub); | 
|                 //    } | 
|                 //} | 
|   | 
|                 //进行判断和控制 | 
|                 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; | 
|                 } | 
|   | 
|                 //保存 | 
|                 //保存完毕后处理 | 
|                 bool bResult; | 
|                 if (refSav == "Add") | 
|                 { | 
|                     // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|                     bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|                 } | 
|                 else if (refSav == "Update") | 
|                 { | 
|                     bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo); | 
|                 } | 
|                 else | 
|                 { | 
|                     bResult = false; | 
|                 } | 
|                 if (bResult) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 1; | 
|                     objJsonResult.Message = "保存成功!"; | 
|                     //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单"); | 
|                     objJsonResult.data = 1; | 
|                     return objJsonResult; | 
|                 } | 
|                 else | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo; | 
|                     objJsonResult.data = 1; | 
|                     return objJsonResult; | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "保存失败!" + e.ToString(); | 
|                 objJsonResult.data = 1; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|   | 
|   | 
|         /// <summary> | 
|         /// 客户项目表头信息 | 
|         /// </summary> | 
|         /// <param name="sMsg"></param> | 
|         /// <returns></returns> | 
|         [Route("PM_ProInfo/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) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "获取失败"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 else | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 1; | 
|                     objJsonResult.Message = "获取成功"; | 
|                     objJsonResult.data = dt_Main; | 
|                     return objJsonResult; | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 objJsonResult.code = "0"; | 
|                 objJsonResult.count = 0; | 
|                 objJsonResult.Message = "获取失败" + e.ToString(); | 
|                 objJsonResult.data = null; | 
|                 return objJsonResult; | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|         #region 客户项目信息 加载编辑页面 | 
|         [Route("PM_ProInfo/loadPM_CustomerProInfoBill_Edit")] | 
|         [HttpGet] | 
|         public object loadPM_CustomerProInfoBill_Edit(long HInterID) | 
|         { | 
|             try | 
|             { | 
|   | 
|                 ds = oCN.RunProcReturn("select * from h_v_PM_CustomerProInfoBill where hmainid =" + HInterID , "h_v_PM_CustomerProInfoBill"); | 
|                 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 | 
|     } | 
| } |