| | |
| | | using System.Web; |
| | | using System.Web.Http; |
| | | using WebAPI.Models; |
| | | |
| | | using System.Web; |
| | | using WebAPI.Controllers.SCGL.æ¥è®¡å管ç; |
| | | using System.IO; |
| | | using SyntacticSugar.constant; |
| | | namespace WebAPI.Controllers.åºç¡èµæ.åºç¡èµæ |
| | | { |
| | | public class Gy_MaterTypeBillController : ApiController |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region ç©æåç±» æä»¶å¯¼å
¥ä¿å |
| | | #region ç©æåç±» æä»¶ä¸ä¼ |
| | | [Route("Gy_MaterType/Gy_MaterType_Excel")] |
| | | [HttpPost] |
| | | public object Gy_MaterType_Excel() |
| | | { |
| | | try |
| | | { |
| | | //è·åæä»¶åç§° |
| | | var file = HttpContext.Current.Request.Files[0]; |
| | | //è·åæä»¶ç©çè·¯å¾ |
| | | string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName); |
| | | //ä¿åæä»¶ |
| | | file.SaveAs(ExcelPath); |
| | | |
| | | NpoiHelper np = new NpoiHelper(); |
| | | DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0"); |
| | | |
| | | //å 餿件 |
| | | File.Delete(ExcelPath); |
| | | |
| | | //å建临æ¶è¡¨ |
| | | DataTable tb2 = new DataTable("dt2"); |
| | | |
| | | //æ·»å åå |
| | | for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++) |
| | | { |
| | | tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString()); |
| | | } |
| | | |
| | | //模æ¿ç¼ºå°å ä½éè¦ä»æ°æ®åºä¸æ¥è¯¢åºæ¥æ¾ç¤ºå¨é¡µé¢çåæ®µ |
| | | tb2.Columns.Add("HOrgID", typeof(Int32));//ç»ç»ID |
| | | tb2.Columns.Add("HParentID", typeof(Int32));//ç¶ç±»ID |
| | | |
| | | //æ·»å æ°æ® |
| | | for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++) |
| | | { |
| | | DataRow row = tb2.NewRow(); |
| | | for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++) |
| | | { |
| | | row[j] = ExcelDs.Tables[0].Rows[i][j].ToString(); |
| | | } |
| | | tb2.Rows.Add(row); |
| | | } |
| | | |
| | | |
| | | var error = ""; |
| | | |
| | | //æ¥è¯¢æ²¡æçå |
| | | if (!tb2.Columns.Contains("ç»ç»ä»£ç ")) |
| | | error += "æ²¡ææ¾å°ãç»ç»ä»£ç ãçæ é¢,"; |
| | | |
| | | if (!tb2.Columns.Contains("ç»ç»åç§°")) |
| | | error += "æ²¡ææ¾å°ãç»ç»åç§°ãçæ é¢,"; |
| | | |
| | | if (!tb2.Columns.Contains("ç©æåç±»")) |
| | | error += "æ²¡ææ¾å°ãç©æåç±»åç§°ãçæ é¢,"; |
| | | |
| | | if (!tb2.Columns.Contains("ç©æå类代ç ")) |
| | | error += "æ²¡ææ¾å°ãç©æå类代ç ãçæ é¢,"; |
| | | |
| | | if (!tb2.Columns.Contains("ç¶ç±»åç§°")) |
| | | error += "æ²¡ææ¾å°ãç¶ç±»åç§°ãçæ é¢,"; |
| | | |
| | | if (!tb2.Columns.Contains("ç¶ç±»ä»£ç ")) |
| | | error += "æ²¡ææ¾å°ãç¶ç±»ä»£ç ãçæ é¢,"; |
| | | |
| | | if (!tb2.Columns.Contains("夿³¨")) |
| | | error += "æ²¡ææ¾å°ã夿³¨ãçæ é¢,"; |
| | | |
| | | if (!tb2.Columns.Contains("å©è®°ç ")) |
| | | error += "æ²¡ææ¾å°ãå©è®°ç ãçæ é¢,"; |
| | | |
| | | if (error.Length > 0) |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = $"Excel模æ¿åå¨é误,{error}\r\n"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | for (int i = 0; i <= tb2.Rows.Count - 1; i++) |
| | | { |
| | | string HMaterTypeName = ""; |
| | | string HMaterTypeNum = ""; |
| | | string HORGNumber = ""; |
| | | string HORGName = ""; |
| | | string HParentNumber = ""; |
| | | string HParentName = ""; |
| | | |
| | | HMaterTypeName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["ç©æåç±»"].ToString()); |
| | | HMaterTypeNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["ç©æå类代ç "].ToString()); |
| | | HParentName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["ç¶ç±»åç§°"].ToString()); |
| | | HParentNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["ç¶ç±»ä»£ç "].ToString()); |
| | | HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["ç»ç»ä»£ç "].ToString()); |
| | | HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["ç»ç»åç§°"].ToString()); |
| | | |
| | | //æ£æ¥ç©æ |
| | | int index = i + 1; |
| | | |
| | | if (HORGNumber != "") |
| | | { |
| | | |
| | | //æ¥è¯¢ç»ç» |
| | | ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS"); |
| | | |
| | | if (ds.Tables[0].Rows.Count == 0) |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "第" + index + "è¡,ç»ç»ä¸åå¨ï¼"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | else |
| | | { |
| | | tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); |
| | | } |
| | | string HORGid = ds.Tables[0].Rows[0]["HItemID"].ToString(); |
| | | |
| | | if(HParentNumber!="" && HParentName != "") |
| | | { |
| | | //æ¥è¯¢ç¶ç±»id |
| | | ds = oCN.RunProcReturn("select * from Gy_MaterType where HNumber='" + HParentNumber + "' and Hname='" + HParentName + "'", "Gy_MaterType"); |
| | | |
| | | if (ds.Tables[0].Rows.Count == 0) |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "第" + index + "è¡,ç¶ç±»ä¸åå¨ï¼"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | else |
| | | { |
| | | tb2.Rows[i]["HParentID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); |
| | | } |
| | | string HParentID = ds.Tables[0].Rows[0]["HItemID"].ToString(); |
| | | } |
| | | else { |
| | | tb2.Rows[i]["HParentID"] = "0"; |
| | | } |
| | | |
| | | |
| | | //ç©æåç±»åç§° |
| | | if (HMaterTypeName == "") |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "第" + index + "è¡,ç©æåç±»åç§°ä¸è½ä¸ºç©ºï¼"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | //ç©æåç±»åç§° |
| | | if (HMaterTypeNum == HParentNumber) |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "第" + index + "è¡,ç©æç±»åç¶ç±»ä¸è½æ¯èªå·±ï¼"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | //ç©æå类代ç |
| | | if (HMaterTypeNum == "") |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "第" + index + "è¡,ç©æå类代ç ä¸è½ä¸ºç©ºï¼"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "第" + index + "è¡,ç»ç»ä»£ç 为空"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | |
| | | objJsonResult.code = CodeConstant.SUCCEED; |
| | | objJsonResult.count = CountConstant.SUCCEED; |
| | | objJsonResult.Message = error; |
| | | objJsonResult.data = tb2; |
| | | return objJsonResult; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "Exceptionï¼" + e.ToString(); |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region ç©æåç±»é¡¹ç® å¯¼å
¥(ä¿å) |
| | | [Route("Gy_MaterType/Gy_MaterType_btnSave")] |
| | | [HttpPost] |
| | | public object Gy_MaterType_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(); |
| | | try |
| | | { |
| | | if (!DBUtility.ClsPub.Security_Log("Gy_ErrType_Edit", 1, false, user)) |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "æ ä¿åæéï¼"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | oCN.BeginTran(); |
| | | int i = 1; |
| | | foreach (Dictionary<string, string> item in list) |
| | | { |
| | | string HOrgID = item["HOrgID"].ToString();//ç»ç»ID |
| | | string HName = item["ç©æåç±»"].ToString(); |
| | | string HNumber = item["ç©æå类代ç "].ToString(); |
| | | string HRemark = item["夿³¨"].ToString(); |
| | | string HHelpCode = item["å©è®°ç "].ToString(); |
| | | string HParentID = item["HParentID"].ToString(); |
| | | string sShortNumber; |
| | | sShortNumber = DBUtility.ClsPub.GetShortNumber(HNumber);//ç代ç |
| | | if (sShortNumber.Trim() == "") |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "ä¿å失败ï¼ç代ç 为空ï¼"; |
| | | objJsonResult.data = 1; |
| | | return objJsonResult; |
| | | } |
| | | int HEndFlag = 1;//æ«çº§æ å¿ |
| | | int HLevel = 1; //ç级 |
| | | DataSet ds2 = oCN.RunProcReturn("select HLevel from Gy_MaterType where HItemID =" + HParentID, "Gy_MaterType");//æç´¢ç¶ç±»ç级 |
| | | //oItem.HLevel = DBUtility.ClsPub.GetLevel(oItem.HNumber); //ç级 |
| | | if (ds2.Tables[0].Rows.Count > 0) |
| | | { |
| | | HLevel = (int)ds2.Tables[0].Rows[0]["HLevel"] + 1; |
| | | } |
| | | else |
| | | { |
| | | HLevel = 1; |
| | | } |
| | | |
| | | if (!DBUtility.ClsPub.AllowNumber(HNumber.Trim())) |
| | | { |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "ä¿å失败ï¼ä»£ç ä¸ä¸è½åºç°è¿ç»â.âå¹¶ä¸é¦ä½æ«ä½ä¸è½ä¸ºâ.âï¼"; |
| | | objJsonResult.data = 1; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | ds = oCN.RunProcReturn("select * from Gy_MaterType where HNumber='" + HNumber + "'", "Gy_MaterType"); |
| | | |
| | | if (ds.Tables[0].Rows.Count == 0) |
| | | { |
| | | oCN.RunProc("Insert into " + "Gy_MaterType" + |
| | | " (HNumber,HName,HHelpCode,HShortNumber,HParentID" + |
| | | ",HLevel,HEndFlag,HStopflag,HRemark,HMakeEmp,HMakeTime,HStopEmp,HStopTime,HUSEORGID,HCREATEORGID,HUseFlag) " + |
| | | " Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + sShortNumber + "'," + HParentID.ToString() + |
| | | "," + HLevel + "," + HEndFlag + "," + 0 + ",'" + HRemark + "','" + user + "',getdate(),'" + "" + "','" + "" + "'," + HOrgID + "," + HOrgID + ",'" + "æªæ£æµ" + "')"); |
| | | //ä¿®æ¹ä¸çº§ä¸ºéæ«çº§ä»£ç |
| | | oCN.RunProc("Update Gy_MaterType" + " set HEndflag=0 where HItemID=" + HParentID); |
| | | } |
| | | else |
| | | { |
| | | oCN.RunProc("update Gy_MaterType set HUSEORGID=" + HOrgID + ",HParentID = " + HParentID + ",HHelpCode = '" + HHelpCode + "',HRemark='" + HRemark + "' where HNumber='" + HNumber + "'"); |
| | | //ä¿®æ¹ä¸çº§ä¸ºéæ«çº§ä»£ç |
| | | oCN.RunProc("Update Gy_MaterType" + " set HEndflag=0 where HItemID=" + HParentID); |
| | | } |
| | | |
| | | i++; |
| | | } |
| | | |
| | | oCN.Commit(); |
| | | |
| | | objJsonResult.code = CodeConstant.SUCCEED; |
| | | objJsonResult.count = CountConstant.SUCCEED; |
| | | objJsonResult.Message = "导å
¥æå!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LogService.Write(e); |
| | | objJsonResult.code = CodeConstant.FAIL; |
| | | objJsonResult.count = CountConstant.FAIL; |
| | | objJsonResult.Message = "Exceptionï¼" + e.ToString(); |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | #endregion |
| | | #endregion |
| | | |
| | | |
| | | #region ç©æåç±» å é¤ |
| | | [Route("Gy_MaterType/DeleteMaterType")] |