bom树形结构 表设计_BOM表格的数据库导入--一种树形结构

这个博客详细介绍了如何处理BOM(Bill of Materials)树形结构的数据库导入,包括从Excel文件读取数据,处理重复项,存储物号信息,以及通过递归保存数据到BOM表中的过程。文章涉及了使用NPOI库操作Excel,以及通过.NET进行数据处理和存储的相关代码示例。
摘要由CSDN通过智能技术生成

1 usingSystem;2 usingSystem.Collections;3 usingSystem.Collections.Generic;4 usingSystem.Configuration;5 usingSystem.Data;6 usingSystem.Data.OleDb;7 usingSystem.Web;8 usingSystem.IO;9 usingSystem.Linq;10 usingNPOI.HSSF.UserModel;11 usingSystem.Text;12 usingSystem.Web.UI.WebControls;13 usingSystem.Xml.Schema;14

15

16 namespaceMd.Api.Web17 {18 ///

19 ///ExcelFileUploadHQL 的摘要说明20 ///

21 public classExcelFileUploadHQL : IHttpHandler22 {23 private static int CompID { get; set; }24 private static int CreateUser { get; set; }25 private static int ProjectID { get; set; }26 private static string ProjectCode { get; set; }27

28 private stringPath29 {30 get

31 {32 string path = ConfigurationManager.AppSettings["filepath"];33

34 try

35 {36 path =HttpContext.Current.Server.MapPath(path);37 }38 catch(Exception)39 {40 }41 returnpath;42 }43 }44

45 ///

46 ///接收请求47 ///

48 ///

49 public voidProcessRequest(HttpContext context)50 {51 string result = "";52 context.Response.ContentType = "text/plain";53 HttpPostedFile postFile = context.Request.Files["Filedata"];54 CompID = Convert.ToInt32(context.Request["CompID"] + "");55 CreateUser = Convert.ToInt32(context.Request["CreateUser"] + "");56 ProjectID = Convert.ToInt32(context.Request["ProjectID"] + "");57 ProjectCode = context.Request["ProjectCode"] + "";58

59 string excelName =postFile.FileName;60 string savePath = "";61

62 try

63 {64

65 /*文件是否有内容*/

66 if (postFile != null && postFile.ContentLength > 0)67 {68 if (string.IsNullOrEmpty(excelName))69 {70 excelName = Guid.NewGuid().ToString("N") +System.IO.Path.GetExtension(postFile.FileName);71 }72

73 if (!File.Exists(Path))74 {75 System.IO.Directory.CreateDirectory(Path);76 }77

78 string Mess = "";79 savePath = Path +excelName;80 postFile.SaveAs(savePath);81

82 if (Mess != "")83 {84 //错误输出

85 context.Response.Write("false@" +Mess);86 }87

88 Mess =DealExcelForHangQiLun(LoadDataFromExcel(savePath));89 if (string.IsNullOrEmpty(Mess))90 {91 Mess = "导入成功!" + "@true";92 }93 result = "true@" +Mess;94 }95 }96 catch(Exception ex)97 {98 result = "false@上传失败!" +ex.ToString();99 }100 context.Response.Write(result);101 }102

103 public static stringDealExcelForHangQiLun(DataSet ds)104 {105 try

106 {107 string errorRow = "";108 string repeatstr = "";109 int clevel = 0;110 Dictionary goodsdictionary = new Dictionary();111

112 if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)113 {114 //获取Excel 最大层级并分级

115 Dictionary&

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值