Exemple #1
0
        /// <summary>
        /// 保存转化成的表格到Excel中
        /// </summary>
        protected DataView SaveBranchesToExcel(string tbName)
        {
            AppProject pro = AppProject.GetInstance();

            if (nets.Count() == 0)
            {
                return(null);
            }
            int    columns = getColumnCount();
            string cmd     = "CREATE TABLE " + tbName + " (";

            cmd += "网络号 VARCHAR(100),";
            for (int i = 0; i < columns; i++)
            {
                cmd += string.Format("部位{0} VARCHAR(100),端子号{1} VARCHAR(100),端口类型{2} VARCHAR(100),", i, i, i);
            }
            cmd = cmd.Substring(0, cmd.Length - 1) + ")";
            using (OleDbConnection cnn = AccessAndExcelOp.GetExcelConnect(pro.OriginFileName + "(测试支路).xls"))
            {
                List <string> tbnames   = AccessAndExcelOp.GetTableNames(cnn);
                string        deleteCmd = "Drop Table " + tbName;
                if (tbnames.Contains(tbName))
                {
                    AccessAndExcelOp.ExecuteNoQueryCmd(cnn, deleteCmd);
                }
                AccessAndExcelOp.CreateTable(cnn, cmd);
                DataTable table = AccessAndExcelOp.GetTable(cnn, tbName);
                fillTable(table);
                AccessAndExcelOp.UpdateSourceTable(cnn, table);
                return(table.AsDataView());
            }
        }
        /// <summary>
        /// 保存到excel
        /// </summary>
        public System.Data.DataView SaveBranchesToExcel()
        {
            AppProject pro    = AppProject.GetInstance();
            string     tbName = "接口配置";

            if (linkerRelation.Count() == 0)
            {
                return(null);
            }
            string cmd = "CREATE TABLE 接口配置 (连接器 VARCHAR(100),连接器端口 VARCHAR(100),测试箱 VARCHAR(100),测试箱端口 VARCHAR(100),线号 VARCHAR(100))";

            using (OleDbConnection cnn = AccessAndExcelOp.GetExcelConnect(pro.OriginFileName + "(测试支路).xls"))
            {
                List <string> tbnames = AccessAndExcelOp.GetTableNames(cnn);
                if (tbnames.Contains(tbName))
                {
                    string deleteCmd = "Drop Table " + tbName;
                    AccessAndExcelOp.ExecuteNoQueryCmd(cnn, deleteCmd);
                }
                AccessAndExcelOp.CreateTable(cnn, cmd);
                DataTable table = AccessAndExcelOp.GetTable(cnn, tbName);
                foreach (var link in linkerRelation)
                {
                    DataRow row = table.NewRow();
                    row[0] = link.Key.LinkerName;
                    row[1] = link.Key.LinkerPort;
                    row[2] = link.Value.TestBoxNum;
                    row[3] = link.Value.TestBoxPort;
                    row[4] = link.Value.LineNum;
                    table.Rows.Add(row);
                }
                AccessAndExcelOp.UpdateSourceTable(cnn, table);
                return(table.AsDataView());
            }
        }