| New file |
| | |
| | | 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.IO; |
| | | using System.Text; |
| | | using System.Web; |
| | | using System.Web.Http; |
| | | using WebAPI.Controllers.SCGL.æ¥è®¡å管ç; |
| | | using WebAPI.Models; |
| | | using WebAPI.Service; |
| | | |
| | | namespace WebAPI.Controllers.åºç¡èµæ.åºç¡èµæ |
| | | { |
| | | public class Cb_OtherOutBill_CostSubjectDetailController : ApiController |
| | | { |
| | | // GET: Cb_OtherOutBill_CostSubjectDetail |
| | | public DBUtility.ClsPub.Enum_BillStatus BillStatus; |
| | | |
| | | private json objJsonResult = new json(); |
| | | SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); |
| | | DataSet ds; |
| | | [Route("Cb_OtherOutBill_CostSubjectDetail/list")] |
| | | [HttpGet] |
| | | public object list(string sWhere, string user) |
| | | { |
| | | try |
| | | { |
| | | List<object> columnNameList = new List<object>(); |
| | | //夿æ¯å¦ææ¥è¯¢æé |
| | | if (!DBUtility.ClsPub.Security_Log("Gy_CostAverageType_Query", 1, false, user)) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "æ æéæ¥è¯¢!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | if (sWhere == null || sWhere.Equals("")) |
| | | { |
| | | ds = oCN.RunProcReturn("select * from h_v_Cb_OtherOutBill_CostSubjectDetail where 1=1 order by æ¥æ desc ", "h_v_Cb_OtherOutBill_CostSubjectDetail"); |
| | | } |
| | | else |
| | | { |
| | | string sql1 = "select * from h_v_Cb_OtherOutBill_CostSubjectDetail where 1=1 "; |
| | | string sql = sql1 + sWhere + " order by æ¥æ desc"; |
| | | ds = oCN.RunProcReturn(sql, "h_v_Cb_OtherOutBill_CostSubjectDetail"); |
| | | } |
| | | |
| | | //æ·»å åå |
| | | 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 || ds != null) |
| | | //{ |
| | | objJsonResult.code = "1"; |
| | | objJsonResult.count = 1; |
| | | objJsonResult.Message = "Sucessï¼"; |
| | | objJsonResult.data = ds.Tables[0]; |
| | | objJsonResult.list = columnNameList; |
| | | return objJsonResult; |
| | | //} |
| | | //else |
| | | //{ |
| | | //objJsonResult.code = "0"; |
| | | //objJsonResult.count = 0; |
| | | //objJsonResult.Message = "æ æ°æ®"; |
| | | //objJsonResult.data = null; |
| | | //return objJsonResult; |
| | | //} |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "Exceptionï¼" + e.ToString(); |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | |
| | | |
| | | #region æä»¶ä¸ä¼ |
| | | [Route("Cb_OtherOutBill_CostSubjectDetail/CB_WipProcessTable_Excel")] |
| | | [HttpPost] |
| | | public json CB_WipProcessTable_Excel() |
| | | { |
| | | json res = new json(); |
| | | try |
| | | { |
| | | //è·åæä»¶åç§° |
| | | var file = HttpContext.Current.Request.Files[0]; |
| | | //è·åæä»¶ç©çè·¯å¾ |
| | | string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName); |
| | | //ä¿åæä»¶ |
| | | file.SaveAs(ExcelPath); |
| | | |
| | | SCGL.æ¥è®¡å管ç.NpoiHelper np = new NpoiHelper(); |
| | | DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0"); |
| | | |
| | | //å 餿件 |
| | | File.Delete(ExcelPath); |
| | | |
| | | //å建临æ¶è¡¨ |
| | | DataTable provisional = new DataTable("dt2"); |
| | | |
| | | //æ·»å åå |
| | | for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++) |
| | | { |
| | | provisional.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString()); |
| | | } |
| | | //provisional.Columns.Add("åæ®å·", typeof(string)); |
| | | |
| | | //æ·»å æ°æ® |
| | | for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++) |
| | | { |
| | | DataRow row = provisional.NewRow(); |
| | | for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++) |
| | | { |
| | | row[j] = ExcelDs.Tables[0].Rows[i][j].ToString(); |
| | | } |
| | | provisional.Rows.Add(row); |
| | | } |
| | | |
| | | //夿å |
| | | string error = JudgmentColumns(provisional); |
| | | if (error.Length > 0) |
| | | { |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = $"Excel模æ¿åå¨é误,{error}\r\n"; |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | |
| | | for (int i = 0; i <= provisional.Rows.Count - 1; i++) |
| | | { |
| | | string HDate = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["æ¥æ"].ToString()); |
| | | string HBillNo = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["åæ®ç¼å·"].ToString()); |
| | | string HWareHouse = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["åè´§ä»åº"].ToString()); |
| | | string HStockPlace = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ä»ä½"].ToString()); |
| | | |
| | | string HUseType = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["é¢æç±»å"].ToString()); |
| | | string HUseDepartment = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["颿é¨é¨"].ToString()); |
| | | |
| | | string HCostSubject = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ææ¬ç§ç®"].ToString()); |
| | | |
| | | string HCostSubjectSon = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ææ¬ç§ç®äºçº§"].ToString()); |
| | | string HSubjectProc = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ç§ç®+å·¥åº"].ToString()); |
| | | |
| | | string HMaterNumber = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ç©æç¼ç "].ToString()); |
| | | |
| | | string HMaterName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ç©æåç§°"].ToString()); |
| | | string HModel = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["è§æ ¼åå·"].ToString()); |
| | | |
| | | string HUnit = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["åä½"].ToString()); |
| | | string HQty = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["å®åæ°é"].ToString()); |
| | | |
| | | string HCostPrice = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ææ¬ä»·"].ToString()); |
| | | string HTotalPrice = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["æ»ææ¬"].ToString()); |
| | | string HLOT = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["æ¹å·"].ToString()); |
| | | string HRemark2 = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["夿³¨"].ToString()); |
| | | string HUsePerson = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["é¢æäºº"].ToString()); |
| | | string HWareHousePerson = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ä»ç®¡å"].ToString()); |
| | | string HAssetName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["èµäº§åç§°"].ToString()); |
| | | string HAssetNumber = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["èµäº§ç¼å·"].ToString()); |
| | | string HSearchProject = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ç å项ç®"].ToString()); |
| | | string HVerify = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["æ ¸å¯¹"].ToString()); |
| | | |
| | | //string remark = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["夿³¨"].ToString()); |
| | | |
| | | //è·åçå®è¡æ° |
| | | int line = i + 1; |
| | | } |
| | | |
| | | res.code = "1"; |
| | | res.count = 1; |
| | | res.Message = error; |
| | | res.data = provisional; |
| | | 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="provisional"></param> |
| | | /// <returns></returns> |
| | | private static string JudgmentColumns(DataTable provisional) |
| | | { |
| | | var error = ""; |
| | | |
| | | ////æ¥è¯¢æ²¡æçå |
| | | //if (!provisional.Columns.Contains("客æ·")) |
| | | // error += "æ²¡ææ¾å°ã客æ·ãçæ é¢,"; |
| | | |
| | | //if (!provisional.Columns.Contains("æåæå·")) |
| | | // error += "æ²¡ææ¾å°ãæåæå·ãçæ é¢,"; |
| | | return error; |
| | | } |
| | | #endregion |
| | | |
| | | #region ä¸ä¼ ä¿å |
| | | [Route("Cb_OtherOutBill_CostSubjectDetail/Excel_btnSave")] |
| | | [HttpPost] |
| | | public object Excel_btnSave([FromBody] JObject sMainSub) |
| | | { |
| | | var _value = sMainSub["sMainSub"].ToString(); |
| | | string msg1 = _value.ToString(); |
| | | string[] sArray = msg1.Split(new string[] { "&å" }, StringSplitOptions.RemoveEmptyEntries); |
| | | string msg2 = sArray[0].ToString(); |
| | | string user = sArray[1].ToString(); |
| | | string organ = sArray[2].ToString(); |
| | | json res = new json(); |
| | | |
| | | try |
| | | { |
| | | oCN.BeginTran(); |
| | | List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2); |
| | | List<Dictionary<string, string>> list = new List<Dictionary<string, string>>(); |
| | | |
| | | foreach (JObject item in Excel) |
| | | { |
| | | Dictionary<string, string> dic = new Dictionary<string, string>(); |
| | | foreach (var itm in item.Properties()) |
| | | { |
| | | dic.Add(itm.Name, itm.Value.ToString()); |
| | | } |
| | | list.Add(dic); |
| | | } |
| | | |
| | | // 4. æ¥è¯¢ç¨æ·ä¿¡æ¯ |
| | | DataSet emp = oCN.RunProcReturn($"SELECT Czybm FROM Gy_Czygl WHERE Czymc = '{user.Replace("'", "''")}'", "Gy_Czygl"); |
| | | if (emp.Tables[0].Rows.Count == 0) |
| | | { |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = "ç¨æ·ä¸åå¨ï¼"; |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | string HUserID = emp.Tables[0].Rows[0]["Czybm"].ToString(); |
| | | |
| | | StringBuilder errorMessage = new StringBuilder(); |
| | | StringBuilder insertSql = new StringBuilder(); |
| | | StringBuilder updateSql = new StringBuilder(); |
| | | string currentDate = DateTime.Today.ToString("yyyy-MM-dd"); |
| | | int HEntryID = 1; |
| | | |
| | | // éåæ°æ®å¹¶éªè¯ |
| | | for (int i = 0; i < list.Count; i++) |
| | | { |
| | | var item = list[i]; |
| | | |
| | | List<string> intFields = new List<string> |
| | | { |
| | | |
| | | }; |
| | | |
| | | bool hasError = false; |
| | | foreach (var field in intFields) |
| | | { |
| | | if (item.ContainsKey(field)) |
| | | { |
| | | string value = item[field]; |
| | | // æ£æ¥æ¯å¦ä¸ºæ´æ° |
| | | if (!string.IsNullOrWhiteSpace(value)) |
| | | { |
| | | if (!int.TryParse(value, out _)) |
| | | { |
| | | errorMessage.AppendLine($"第{i + 1}è¡æ°æ®é误ï¼å段 '{field}' çå¼ '{value}' 䏿¯ææçæ´æ°"); |
| | | hasError = true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 妿æé误ï¼è·³è¿æå
¥ |
| | | if (hasError) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | |
| | | insertSql.AppendLine($"INSERT INTO [Cb_OtherOutBill_CostSubjectDetail] ([HYear], [HPeriod], [HBillType], [HBillSubType], [HDate], [HBillNo], [HBillStatus], [HCheckItemNowID], [HCheckItemNextID], [HCheckFlowID], [HRemark], [HBacker], [HBackDate], [HChecker], [HCheckDate], [HMaker], [HMakeDate], [HUpDater], [HUpDateDate], [HCloseMan], [HCloseDate], [HCloseType], [HDeleteMan], [HDeleteDate], [HWareHouse], [HStockPlace], [HUseType], [HUseDepartment], [HCostSubject], [HCostSubjectSon], [HSubjectProc], [HMaterNumber], [HMaterName], [HModel], [HUnit], [HQty], [HCostPrice], [HTotalPrice], [HLOT], [HRemark2], [HUsePerson], [HWareHousePerson], [HAssetName], [HAssetNumber], [HSearchProject], [HVerify]) VALUES ("); |
| | | insertSql.AppendLine($" {item["年份"]}, {item["æä»½"]}, {1}, '{1}', '{item["æ¥æ"]}', '{item["åæ®ç¼å·"]}', '{1}', '{1}', '{1}', '{1}', '{item["夿³¨"]}', '{""}', '{DateTime.Now}', '{""}', '{DateTime.Now}', '{""}', '{DateTime.Now}', '{""}', '{DateTime.Now}', '{""}', '{DateTime.Now}', '{"0"}', '{""}', '{DateTime.Now}', '{item["åè´§ä»åº"]}', '{item["ä»ä½"]}', '{item["é¢æç±»å"]}', '{item["颿é¨é¨"]}', '{item["ææ¬ç§ç®"]}', '{item["ææ¬ç§ç®äºçº§"]}', '{item["ç§ç®+å·¥åº"]}', '{item["ç©æç¼ç "]}', '{item["ç©æåç§°"]}', '{item["è§æ ¼åå·"]}', '{item["åä½"]}', '{item["å®åæ°é"]}', '{item["ææ¬ä»·"]}', '{item["æ»ææ¬"]}', '{item["æ¹å·"]}', '{"excel导å
¥"}', '{item["é¢æäºº"]}', '{item["ä»ç®¡å"]}', '{item["èµäº§åç§°"]}', '{item["èµäº§ç¼å·"]}', '{item["ç å项ç®"]}', '{item["æ ¸å¯¹"]}');"); |
| | | } |
| | | |
| | | if (errorMessage.Length > 0) |
| | | { |
| | | //oCN.Rollback(); |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = "æ°æ®éªè¯å¤±è´¥ï¼\n" + errorMessage.ToString(); |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | |
| | | if (insertSql.Length == 0) |
| | | { |
| | | // oCN.Rollback(); |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = "æ²¡æææçæ´æ°æ°æ®å¯ä»¥å¯¼å
¥"; |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | |
| | | // æ§è¡æ¹éæä½ |
| | | if (insertSql.Length > 0) |
| | | { |
| | | oCN.RunProc(insertSql.ToString()); |
| | | } |
| | | |
| | | //if (updateSql.Length > 0) |
| | | //{ |
| | | // oCN.RunProc(updateSql.ToString()); |
| | | // oCN.RunProc(updateSql_sub.ToString()); |
| | | //} |
| | | |
| | | oCN.Commit(); |
| | | |
| | | res.code = "1"; |
| | | res.count = 1; |
| | | res.Message = "导å
¥æå!"; |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | //oCN.Rollback(); |
| | | LogService.Write(e); |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = "Exceptionï¼" + e.ToString(); |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | } |