WMMaterialTypeService.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. using LeaRun.Application.Code;
  2. using LeaRun.Application.Entity.WarehouseManage;
  3. using LeaRun.Data;
  4. using LeaRun.Util;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace LeaRun.Application.Service.WarehouseManage
  12. {
  13. public class WMMaterialTypeService
  14. {
  15. SqlHelper sqlHelper = new SqlHelper("InstallDB");
  16. public List<MaterialTypeTreeEntiy> GetList(int level, string parentId)
  17. {
  18. switch (level)
  19. {
  20. case 0:
  21. return GetAllList(level, parentId);
  22. case 1:
  23. return GetMaterialList(level, parentId);
  24. default:
  25. return new List<MaterialTypeTreeEntiy>();
  26. }
  27. }
  28. public void SaveMeterialForm(String data)
  29. {
  30. String sql = null;
  31. MaterialTypeTreeEntiy entity = data.ToObject<MaterialTypeTreeEntiy>();
  32. String op = OperatorProvider.Provider.Current().UserName;
  33. if (string.IsNullOrEmpty(entity.Id))
  34. {
  35. sql = @"INSERT INTO WM_MaterialType (Code,Name,CreateDT,Operator,UpdateDt,IsWaterMeter) VALUES
  36. ('" + entity.Code + "','" + entity.Name + "',GETDATE(),'" + op + "',GETDATE(),0)";
  37. }
  38. else
  39. {
  40. sql = @"UPDATE InstallManage.dbo.WM_MaterialType
  41. SET Code ='"+entity.Code+@"'
  42. ,Name = '"+entity.Name+@"'
  43. ,Operator = '"+op+ @"'
  44. ,UpdateDt = GETDATE()
  45. WHERE materialId="+entity.Id+@"";
  46. }
  47. try
  48. {
  49. sqlHelper.ExecuteNonQuery(sql, CommandType.Text, null);
  50. }
  51. catch (Exception ex)
  52. {
  53. throw;
  54. }
  55. }
  56. /// <summary>
  57. /// 删除材料
  58. /// </summary>
  59. /// <param name="goodID"></param>
  60. /// <returns></returns>
  61. public int DelGoods(string goodID)
  62. {
  63. int flag;
  64. string sql = @"delete from InstallManage.dbo.WM_Goods
  65. where GoodId = " + goodID;
  66. try
  67. {
  68. flag = sqlHelper.ExecuteNoParams(sql, CommandType.Text) > 0 ? 1 : 0;
  69. }
  70. catch (Exception ex)
  71. {
  72. throw;
  73. }
  74. return flag;
  75. }
  76. /// <summary>
  77. /// 删除材料类型
  78. /// </summary>
  79. /// <param name="ItemText"></param>
  80. /// <returns></returns>
  81. public int DelMaterialType(string id)
  82. {
  83. int flag;
  84. string sql = @"delete from WM_MaterialType
  85. where materialId = " + id;
  86. try
  87. {
  88. flag = sqlHelper.ExecuteNoParams(sql, CommandType.Text) > 0 ? 1 : 0;
  89. }
  90. catch (Exception ex)
  91. {
  92. throw;
  93. }
  94. return flag;
  95. }
  96. public DataTable GetGoodsByGoodID(string goodID)
  97. {
  98. DataTable dt;
  99. string sql = @"SELECT [GoodId]
  100. ,[WarehouseId]
  101. ,[Name]
  102. ,[Specifications]
  103. ,u.CalculateUnit
  104. ,[MaxStock]
  105. ,[MinStock]
  106. ,[PurcharePrice]
  107. ,[RetailPrice]
  108. ,[MinRetaPrice]
  109. ,[StockNum]
  110. ,[CostPrice]
  111. ,[Cost]
  112. ,[UpdateDt]
  113. ,[BasePrice]
  114. ,[LabourCost]
  115. ,[MechanicalCost]
  116. ,[IsWaterMeter]
  117. ,[OutdoorMechanicalCost]
  118. ,[OutdoorLabourCost]
  119. ,[OutdoorBasePrice]
  120. ,[IsStop]
  121. ,g.[CreateDt]
  122. ,[Operator]
  123. ,[MaterialID]
  124. FROM WM_Goods g
  125. left join WM_CalculateUnit u ON g.CalculateUnit=u.UnitId
  126. where GoodId = " + goodID;
  127. try
  128. {
  129. dt = sqlHelper.ExecuteDataTable(sql, CommandType.Text, null);
  130. }
  131. catch (Exception ex)
  132. {
  133. throw;
  134. }
  135. return dt;
  136. }
  137. /// <summary>
  138. /// 删除材料类型之前,查询材料类型是否被材料引用
  139. /// </summary>
  140. /// <param name="materialName"></param>
  141. /// <returns></returns>
  142. public DataTable GetGoodsByType(string materialid)
  143. {
  144. DataTable dt;
  145. string sql = @"SELECT [GoodId]
  146. ,[WarehouseId]
  147. ,[Name]
  148. ,[Specifications]
  149. ,u.CalculateUnit
  150. ,[MaxStock]
  151. ,[MinStock]
  152. ,[PurcharePrice]
  153. ,[RetailPrice]
  154. ,[MinRetaPrice]
  155. ,[StockNum]
  156. ,[CostPrice]
  157. ,[Cost]
  158. ,[UpdateDt]
  159. ,[BasePrice]
  160. ,[LabourCost]
  161. ,[MechanicalCost]
  162. ,[IsWaterMeter]
  163. ,[OutdoorMechanicalCost]
  164. ,[OutdoorLabourCost]
  165. ,[OutdoorBasePrice]
  166. ,[IsStop]
  167. ,g.[CreateDt]
  168. ,[Operator]
  169. ,[MaterialID]
  170. FROM WM_Goods g
  171. left join WM_CalculateUnit u ON g.CalculateUnit=u.UnitId
  172. where MaterialID=(select top 1 materialId from WM_MaterialType where materialId=" + materialid + ")";
  173. try
  174. {
  175. dt = sqlHelper.ExecuteDataTable(sql, CommandType.Text, null);
  176. }
  177. catch (Exception ex)
  178. {
  179. throw;
  180. }
  181. return dt;
  182. }
  183. public DataTable SearchGoodsByKeyword(string keyWord)
  184. {
  185. DataTable dt;
  186. string sql = @"SELECT [GoodId]
  187. ,[WarehouseId]
  188. ,[Name]
  189. ,[Specifications]
  190. ,u.CalculateUnit
  191. ,[MaxStock]
  192. ,[MinStock]
  193. ,[PurcharePrice]
  194. ,[RetailPrice]
  195. ,[MinRetaPrice]
  196. ,[StockNum]
  197. ,[CostPrice]
  198. ,[Cost]
  199. ,[UpdateDt]
  200. ,[BasePrice]
  201. ,[LabourCost]
  202. ,[MechanicalCost]
  203. ,[IsWaterMeter]
  204. ,[OutdoorMechanicalCost]
  205. ,[OutdoorLabourCost]
  206. ,[OutdoorBasePrice]
  207. ,[IsStop]
  208. ,g.[CreateDt]
  209. ,[Operator]
  210. ,[MaterialID]
  211. FROM WM_Goods g
  212. left join WM_CalculateUnit u ON g.CalculateUnit=u.UnitId
  213. where Warehouseid like '%" + keyWord + "%' or Name like '%" + keyWord + "%'";
  214. try
  215. {
  216. dt = sqlHelper.ExecuteDataTable(sql, CommandType.Text, null);
  217. }
  218. catch (Exception ex)
  219. {
  220. throw;
  221. }
  222. return dt;
  223. }
  224. public void SaveMeterialDetailForm(string keyvalue, String data, string unitid)
  225. {
  226. String sql = null;
  227. MaterialGoodsEntity materialGoodsEntity = data.ToObject<MaterialGoodsEntity>();
  228. if (!string.IsNullOrEmpty(keyvalue))
  229. {
  230. materialGoodsEntity.MaterialID = GetMaterialID(keyvalue);
  231. }
  232. materialGoodsEntity.CalculateUnit = unitid;
  233. String op = OperatorProvider.Provider.Current().UserName;
  234. if (string.IsNullOrEmpty(materialGoodsEntity.GoodId.ToString()))
  235. {
  236. sql = @"INSERT INTO dbo.WM_Goods
  237. (WarehouseId
  238. ,Name
  239. ,Specifications
  240. ,CalculateUnit
  241. ,MaxStock
  242. ,MinStock
  243. ,PurcharePrice
  244. ,RetailPrice
  245. ,MinRetaPrice
  246. ,StockNum
  247. ,CostPrice
  248. ,Cost
  249. ,UpdateDt
  250. ,BasePrice
  251. ,LabourCost
  252. ,MechanicalCost
  253. ,IsWaterMeter
  254. ,OutdoorMechanicalCost
  255. ,OutdoorLabourCost
  256. ,OutdoorBasePrice
  257. ,IsStop
  258. ,CreateDt
  259. ,Operator
  260. ,MaterialID)
  261. VALUES
  262. (
  263. " + "'" + materialGoodsEntity.WarehouseId + "'," + "'" + materialGoodsEntity.Name + "'," + "'" + materialGoodsEntity.Specifications + "',"
  264. + "'" + materialGoodsEntity.CalculateUnit + "'," + "'" + materialGoodsEntity.MaxStock + "',"
  265. + "'" + materialGoodsEntity.MinStock + "'," + "'" + materialGoodsEntity.PurcharePrice + "'," + "'" +
  266. materialGoodsEntity.RetailPrice + "'," + "'" + materialGoodsEntity.MinRetaPrice + "',"
  267. + "'" + materialGoodsEntity.StockNum + "'," + "'" + materialGoodsEntity.CostPrice + "'," + "'" +
  268. materialGoodsEntity.Cost + "',GETDATE(),'" + materialGoodsEntity.BasePrice + "'," + "'" + materialGoodsEntity.LabourCost + "',"
  269. + "'" + materialGoodsEntity.MechanicalCost + "'," + "'" + materialGoodsEntity.IsWaterMeter + "'," + "'" +
  270. materialGoodsEntity.OutdoorMechanicalCost + "'," + "'" + materialGoodsEntity.OutdoorLabourCost + "',"
  271. + "'" + materialGoodsEntity.OutdoorBasePrice + "'," + "'" + materialGoodsEntity.IsStop
  272. + "',GETDATE()," + "'" + op + "'" + ",'" + materialGoodsEntity.MaterialID + "'" + " )";
  273. }
  274. else
  275. {
  276. sql = @"UPDATE dbo.WM_Goods
  277. SET WarehouseId = " + "'" + materialGoodsEntity.WarehouseId + "'" + @"
  278. ,Name = " + "'" + materialGoodsEntity.Name + "'" + @"
  279. ,Specifications = " + "'" + materialGoodsEntity.Specifications + "'" + @"
  280. ,CalculateUnit = " + "'" + materialGoodsEntity.CalculateUnit + "'" + @"
  281. ,MaxStock = " + "'" + materialGoodsEntity.MaxStock + "'" + @"
  282. ,MinStock = " + "'" + materialGoodsEntity.MinStock + "'" + @"
  283. ,PurcharePrice = " + "'" + materialGoodsEntity.PurcharePrice + "'" + @"
  284. ,RetailPrice = " + "'" + materialGoodsEntity.RetailPrice + "'" + @"
  285. ,MinRetaPrice = " + "'" + materialGoodsEntity.MinRetaPrice + "'" + @"
  286. ,StockNum = " + "'" + materialGoodsEntity.StockNum + "'" + @"
  287. ,CostPrice = " + "'" + materialGoodsEntity.CostPrice + "'" + @"
  288. ,Cost = " + "'" + materialGoodsEntity.Cost + "'" + @"
  289. ,UpdateDt = " + "GETDATE()" + @"
  290. ,BasePrice = " + "'" + materialGoodsEntity.BasePrice + "'" + @"
  291. ,LabourCost = " + "'" + materialGoodsEntity.LabourCost + "'" + @"
  292. ,MechanicalCost =" + "'" + materialGoodsEntity.MechanicalCost + "'" + @"
  293. ,IsWaterMeter = " + "'" + materialGoodsEntity.IsWaterMeter + "'" + @"
  294. ,OutdoorMechanicalCost = " + "'" + materialGoodsEntity.OutdoorMechanicalCost + "'" + @"
  295. ,OutdoorLabourCost = " + "'" + materialGoodsEntity.OutdoorLabourCost + "'" + @"
  296. ,OutdoorBasePrice = " + "'" + materialGoodsEntity.OutdoorBasePrice + "'" + @"
  297. ,IsStop = " + "'" + materialGoodsEntity.IsStop + "'" + @"
  298. ,Operator = " + "'" + op + "'" + @"
  299. WHERE GoodId=" + materialGoodsEntity.GoodId;
  300. }
  301. try
  302. {
  303. sqlHelper.ExecuteNonQuery(sql, CommandType.Text, null);
  304. }
  305. catch (Exception ex)
  306. {
  307. throw;
  308. }
  309. }
  310. public int GetMaterialID(string MaterialName)
  311. {
  312. string sql = "select materialId from InstallManage.dbo.WM_MaterialType where Name='" + MaterialName + "'";
  313. DataTable dt;
  314. try
  315. {
  316. dt = sqlHelper.ExecuteDataTable(sql, CommandType.Text, null);
  317. }
  318. catch (Exception ex)
  319. {
  320. throw;
  321. }
  322. return Convert.ToInt32(dt.Rows[0]["materialId"].ToString());
  323. }
  324. public DataTable GetCalCulateUnitDT()
  325. {
  326. string sqlUnit = "select UnitId, CalculateUnit from dbo.WM_CalculateUnit";
  327. DataTable dtUnit = sqlHelper.ExecuteDataTable(sqlUnit, CommandType.Text, null);
  328. return dtUnit;
  329. }
  330. //获取计量单位
  331. public String GetCalCulateUnit()
  332. {
  333. String json = "";
  334. String sql = "SELECT UnitId,CalculateUnit FROM WM_CalculateUnit";
  335. DataTable dt;
  336. try
  337. {
  338. dt = sqlHelper.ExecuteDataTable(sql, CommandType.Text, null);
  339. }
  340. catch (Exception ex)
  341. {
  342. throw;
  343. }
  344. return json;
  345. }
  346. //获取仓库
  347. public String GetWarehouse()
  348. {
  349. String json = "";
  350. String sql = "SELECT materialId,Name FROM WM_MaterialType";
  351. DataTable dt;
  352. try
  353. {
  354. dt = sqlHelper.ExecuteDataTable(sql, CommandType.Text, null);
  355. }
  356. catch (Exception ex)
  357. {
  358. throw;
  359. }
  360. return json;
  361. }
  362. private List<MaterialTypeTreeEntiy> GetAllList(int level, string parentId)
  363. {
  364. List<MaterialTypeTreeEntiy> list = new List<MaterialTypeTreeEntiy>();
  365. MaterialTypeTreeEntiy entity = new MaterialTypeTreeEntiy();
  366. entity.Id = "level0_0";
  367. entity.Code = "";
  368. entity.Name = "材料类别";
  369. entity.ParentId = "0";
  370. entity.Level = 0;
  371. list.Add(entity);
  372. return list;
  373. }
  374. private List<MaterialTypeTreeEntiy> GetMaterialList(int level, string parentId)
  375. {
  376. String sql = "SELECT materialId,Code,Name FROM WM_MaterialType";
  377. DataTable dt = sqlHelper.ExecuteDataTable(sql, CommandType.Text, null);
  378. List<MaterialTypeTreeEntiy> list = new List<MaterialTypeTreeEntiy>();
  379. for (int i = 0; i < dt.Rows.Count; i++)
  380. {
  381. MaterialTypeTreeEntiy entity = new MaterialTypeTreeEntiy();
  382. entity.Id = "level1_" + dt.Rows[i]["materialId"].ToString();
  383. entity.Code = dt.Rows[i]["Code"].ToString();
  384. entity.Name = dt.Rows[i]["Name"].ToString();
  385. entity.ParentId = "level0_0";
  386. entity.Level = 1;
  387. list.Add(entity);
  388. }
  389. return list;
  390. }
  391. }
  392. }