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.CGGL 
 | 
{ 
 | 
    public class Sup_QuotePriceBillController : ApiController 
 | 
    { 
 | 
        public DBUtility.ClsPub.Enum_BillStatus BillStatus; 
 | 
        private json objJsonResult = new json(); 
 | 
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); 
 | 
        public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill(); 
 | 
        DataSet ds; 
 | 
  
 | 
        #region 供应商报价单列表 
 | 
        [Route("Sup_QuotePriceBill/Sup_QuotePriceBillList")] 
 | 
        [HttpGet] 
 | 
        public object Sup_QuotePriceBillList(string sWhere, string user) 
 | 
        { 
 | 
            try 
 | 
            { 
 | 
                List<object> columnNameList = new List<object>(); 
 | 
  
 | 
                string sql1 = "select * from h_v_Sup_QuotePriceBill where 1 = 1  "; 
 | 
                string sql = sql1 + sWhere + " order by hmainid desc"; 
 | 
                ds = oCN.RunProcReturn(sql, "h_v_Sup_QuotePriceBill"); 
 | 
  
 | 
                //添加列名 
 | 
                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.list = columnNameList; 
 | 
                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 
 | 
  
 | 
        #region 供应商报价单 保存/编辑 
 | 
        /// <summary> 
 | 
        /// 供应商报价单 保存 
 | 
        /// </summary> 
 | 
        /// <param name="msg"></param> 
 | 
        /// <returns></returns> 
 | 
        [Route("Sup_QuotePriceBill/SaveQuotePriceBill")] 
 | 
        [HttpPost] 
 | 
        public object SaveQuotePriceBill([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(); 
 | 
            string msg4 = sArray[2].ToString(); 
 | 
  
 | 
  
 | 
            string UserName = ""; 
 | 
            ListModels oListModels = new ListModels(); 
 | 
            try 
 | 
            { 
 | 
                DAL.ClsSup_QuotePriceBill oBill = new DAL.ClsSup_QuotePriceBill(); 
 | 
                List<Model.ClsSup_QuotePriceBillMain> lsmain = new List<Model.ClsSup_QuotePriceBillMain>(); 
 | 
                msg2 = msg2.Replace("\\", ""); 
 | 
                msg2 = msg2.Replace("\n", "");  //\n 
 | 
                lsmain = oListModels.getObjectByJson_ClsSup_QuotePriceBillMain(msg2); 
 | 
                foreach (Model.ClsSup_QuotePriceBillMain oItem in lsmain) 
 | 
                { 
 | 
                    //oItem.HMaker = ""; 
 | 
                    UserName = oItem.HMaker;  //制单人 
 | 
                    oItem.HBillType = "1121"; 
 | 
                    oItem.HBillSubType = "1121"; 
 | 
                    oItem.HBillStatus = 1; 
 | 
                    DBUtility.ClsPub.CurUserName = UserName; 
 | 
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year); 
 | 
  
 | 
                    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.ClsSup_QuotePriceBillSub> ls = new List<Model.ClsSup_QuotePriceBillSub>(); 
 | 
                ls = oListModels.getObjectByJson_ClsSup_QuotePriceBillSub(msg3); 
 | 
                int i = 0; 
 | 
                foreach (Model.ClsSup_QuotePriceBillSub oItemSub in ls) 
 | 
                { 
 | 
  
 | 
                    i++; 
 | 
                    oItemSub.HEntryID = i; 
 | 
                    //oItemSub.HCloseMan = "";       //行关闭 
 | 
                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now); 
 | 
                    oItemSub.HCloseType = false;   //关闭类型 
 | 
                    //oItemSub.HRemark = "";         //备注 
 | 
                    oItemSub.HSourceInterID = oItemSub.HSourceInterID;     // 源单主内码 
 | 
                    oItemSub.HSourceEntryID = oItemSub.HSourceEntryID;   //源单子内码 
 | 
                    oItemSub.HSourceBillNo = oItemSub.HSourceBillNo;  //源单单号 
 | 
                    oItemSub.HSourceBillType = oItemSub.HSourceBillType; //源单类型 
 | 
                    oItemSub.HRelationQty = 0;     //关联数量 
 | 
  
 | 
                    oBill.DetailColl.Add(oItemSub); 
 | 
  
 | 
                } 
 | 
                //进行 会计期间 结账 的判断和控制 
 | 
                string s = ""; 
 | 
                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 (oBill.omodel.HInterID == 0) 
 | 
                { 
 | 
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); 
 | 
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo); 
 | 
                } 
 | 
                if (bResult) 
 | 
                { 
 | 
                    objJsonResult.code = "0"; 
 | 
                    objJsonResult.count = 1; 
 | 
                    objJsonResult.Message = "保存成功!"; 
 | 
                    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; 
 | 
            } 
 | 
        } 
 | 
        #endregion 
 | 
  
 | 
        //#region 供应商报价单 删除 
 | 
        [Route("Sup_QuotePriceBill/DelQuotePriceBill")] 
 | 
        [HttpGet] 
 | 
        public object DelQuotePriceBill(string HInterID, string user) 
 | 
        { 
 | 
            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; 
 | 
            } 
 | 
            DAL.ClsSup_QuotePriceBill oBill = new DAL.ClsSup_QuotePriceBill(); 
 | 
            if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) 
 | 
            { 
 | 
                ds = oCN.RunProcReturn("select * from Sup_QuotePriceBillMain where HInterID=" + lngBillKey, "Sup_QuotePriceBillMain"); 
 | 
                if (int.Parse(ds.Tables[0].Rows[0]["HBillStatus"].ToString()) > 1) 
 | 
                { 
 | 
                    objJsonResult.code = "0"; 
 | 
                    objJsonResult.count = 0; 
 | 
                    objJsonResult.Message = "单据当前处于不能删除状态,不能删除!"; 
 | 
                    objJsonResult.data = null; 
 | 
                    return objJsonResult; 
 | 
                } 
 | 
  
 | 
                if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "") 
 | 
                { 
 | 
                    objJsonResult.code = "0"; 
 | 
                    objJsonResult.count = 0; 
 | 
                    objJsonResult.Message = "单据已经审核,不能删除!"; 
 | 
                    objJsonResult.data = null; 
 | 
                    return objJsonResult; 
 | 
                } 
 | 
  
 | 
                bool IsDete = oBill.DeleteBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo); 
 | 
                if (IsDete) 
 | 
                { 
 | 
                    objJsonResult.code = "0"; 
 | 
                    objJsonResult.count = 1; 
 | 
                    objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo; 
 | 
                    objJsonResult.data = null; 
 | 
                    return objJsonResult; 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
  
 | 
                    objJsonResult.code = "0"; 
 | 
                    objJsonResult.count = 0; 
 | 
                    objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo; 
 | 
                    objJsonResult.data = null; 
 | 
                    return objJsonResult; 
 | 
                } 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                objJsonResult.code = "0"; 
 | 
                objJsonResult.count = 0; 
 | 
                objJsonResult.Message = "单据未找到"; 
 | 
                objJsonResult.data = null; 
 | 
                return objJsonResult; 
 | 
            } 
 | 
        } 
 | 
        //#endregion 
 | 
    } 
 | 
} 
 |