Esempio n. 1
0
        //手动匹配
        private void btnMove_Click(object sender, EventArgs e)
        {
            if (fixedFileNameList.CheckedItems.Count > 0 && excelFileListBox.CheckedItems.Count > 0)
            {
                int right = fixedFileNameList.CheckedIndices[0];
                int left  = excelFileListBox.CheckedIndices[0];
                if ((right < excelFileListBox.Items.Count) && (right != left))
                {
                    string str = excelFileListBox.Items[left].ToString();
                    excelFileListBox.Items[left]  = excelFileListBox.Items[right];
                    excelFileListBox.Items[right] = str;

                    int k = excelMapList[left].TableListIndex;
                    excelMapList[left].TableListIndex  = right;
                    excelMapList[right].TableListIndex = k;

                    ExcelMap em = excelMapList[left];
                    excelMapList[left]  = excelMapList[right];
                    excelMapList[right] = em;

                    this.excelFileListBox.SetItemCheckState(right, System.Windows.Forms.CheckState.Checked);
                    this.excelFileListBox.SetSelected(right, true);
                }
            }
        }
Esempio n. 2
0
        private void SelectDataSourceForm_Load(object sender, EventArgs e)
        {
            Log.RecordLog("-------------------------------------------------------------------------------------");
            Log.RecordLog("-----------------------------资源调查数据汇编-----------------------------------------");

            //选择excel目录
            Log.RecordLog("选择数据汇编数据目录");
            dirName = SelectDataSourceDir();
            if (dirName == "")
            {
                return;
            }

            int i = 0, j = 0;

            excelMapList.Clear();
            //获取指定目录下的非隐藏word文件
            foreach (string filePath in Directory.GetFileSystemEntries(dirName, "*.xls", SearchOption.AllDirectories))
            {
                DirectoryInfo d = new DirectoryInfo(filePath);
                if ((d.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                {
                    //string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1, (filePath.LastIndexOf(".") - filePath.LastIndexOf("\\") - 1));
                    //不能添加重复的excel文件
                    i = 0;
                    j = 0;
                    for (i = 0; i < excelMapList.Count(); i++)
                    {
                        for (j = 0; j < excelMapList[i].FilePathList.Count(); j++)
                        {
                            string fileName2 = excelMapList[i].FilePathList[j];
                            if (fileName2.Equals(filePath))
                            {
                                break;
                            }
                        }
                    }
                    //没有重复的excel
                    if (i == excelMapList.Count())
                    {
                        //看看有没有连续的excel文件
                        string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1, (filePath.LastIndexOf(".") - filePath.LastIndexOf("\\") - 1));
                        fileName = fileName.Substring(0, fileName.Length - 1);
                        int k = 0;
                        for (k = 0; k < excelMapList.Count(); k++)
                        {
                            string path = excelMapList[k].FilePathList[0];
                            string name = path.Substring(path.LastIndexOf("\\") + 1, (path.LastIndexOf(".") - path.LastIndexOf("\\") - 1));
                            name = name.Substring(0, name.Length - 1);
                            if (fileName.Equals(name))
                            {
                                break;
                            }
                        }
                        if (k < excelMapList.Count())
                        {
                            excelMapList[k].FilePathList.Add(filePath);
                        }
                        else
                        {
                            ExcelMap em = new ExcelMap();
                            em.FilePathList.Add(filePath);
                            excelMapList.Add(em);
                        }
                    }
                }
            }
            if (excelMapList.Count() == 0)
            {
                return;
            }
            i = 0;
            //左侧添加excel文件名
            foreach (ExcelMap em in excelMapList)
            {
                //根据路径获取文件名
                string fileName = em.FileName();
                excelFileListBox.Items.Add(fileName);
                em.ListBoxIndex = i++;
            }
            //保证两边的文件数目相同
            int    n       = SharedData.tableListInDB.Count() - excelMapList.Count();
            String nullStr = "null";

            while (n > 0)
            {
                ExcelMap em = new ExcelMap();
                excelMapList.Add(em);
                excelFileListBox.Items.Add(nullStr);
                n--;
            }
            //右侧添加table名
            for (i = 0; i < SharedData.tableListInDB.Count(); i++)
            {
                TableAndView tbl = SharedData.tableListInDB[i];
                fixedFileNameList.Items.Add(tbl.TableName);
                excelMapList[i].TableListIndex = i;
            }
        }