Пример #1
0
 /// <summary>
 /// 回车生成批量代码
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void txtDataFieldBatch_KeyDown(object sender, KeyEventArgs e)
 {
     string[] heads = this.txtTitleBatch.Text.Split(',', ','),
     mappings = this.txtDataFieldBatch.Text.Split(',', ',');
     if (e.KeyCode == Keys.Enter)
     {
         for (int i = 0; i < heads.Length; i++)
         {
             ExcelItem ei = new ExcelItem
             {
                 RowName  = heads[i],
                 DataType = cbbDataType.SelectedItem.ToString()
             };
             if (mappings.Length > 1)
             {
                 ei.Mapping = mappings[i];
             }
             if (string.IsNullOrEmpty(ei.Mapping)) //映射可以不写 默认是表头名
             {
                 ei.Mapping = ei.RowName;
             }
             ListBoxItem lbi = new ListBoxItem
             {
                 Value = ei,
                 Text  = ei.RowName
             };
             dataList.Items.Add(lbi);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 添加字段
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string tName     = this.txtTitleName.Text,
                   fieldName = this.txtDataField.Text;

            if (tName.IsNullOrEmpty() == false)
            {
                ExcelItem ei = new ExcelItem
                {
                    RowName  = tName,
                    DataType = cbbDataType.SelectedItem.ToString(),
                    Mapping  = fieldName
                };
                if (string.IsNullOrEmpty(ei.Mapping)) //映射可以不写 默认是表头名
                {
                    ei.Mapping = ei.RowName;
                }
                ListBoxItem lbi = new ListBoxItem
                {
                    Value = ei,
                    Text  = ei.RowName
                };
                this.dataList.Items.Add(lbi);

                this.txtTitleName.Text = this.txtDataField.Text = "";
            }
        }
Пример #3
0
        /// <summary>
        /// 添加列属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddRow_Click(object sender, EventArgs e)
        {
            if (txtRowName.Text.Length <= 0)
            {
                return;
            }
            // string str = txtRowName.Text + "," + cbDataType.SelectedItem + "," + barWidth.Value;
            ExcelItem ei = new ExcelItem
            {
                RowName  = txtRowName.Text,
                DataType = cbDataType.SelectedItem.ToString(),
                With     = barWidth.Value,
                Mapping  = this.txtMapp.Text
            };

            if (string.IsNullOrEmpty(ei.Mapping)) //映射可以不写 默认是表头名
            {
                ei.Mapping = ei.RowName;
            }
            ListBoxItem lbi = new ListBoxItem
            {
                Value = ei,
                Text  = ei.RowName
            };

            listItemData.Items.Add(lbi);

            ResertData();
        }
Пример #4
0
        public void SelectData(ExcelItem item)
        {
            var caption = _excelApp.Caption;
            var handler = FindWindow(null, caption);

            SetForegroundWindow(handler);

            _excelApp.Workbooks.Open(_excelPath);
            _excelApp.Visible = true;
            _excelApp.SheetSelectionChange += OnSheetSelectionChanged;
            _excelItem            = item;
            _excelItem.ExcelRange = _excelApp.Selection as Range;
        }
Пример #5
0
        /// <summary>
        /// 批量生成对应关系
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateMapping_Click(object sender, EventArgs e)
        {
            string headField    = this.txtExcelHead.Text,
                   mappingField = this.txtMapping.Text;

            string[] heads = headField.Split(',', ','),
            mappings = mappingField.Split(',', ',');
            if (heads.Length <= 1) //表头名必填
            {
                return;
            }
            if (mappings.Length > 1)  //映射关系可以不填  但是填了就不必须与头的个数对应
            {
                if (mappings.Length != heads.Length)
                {
                    return;
                }
            }

            for (int i = 0; i < heads.Length; i++)
            {
                ExcelItem ei = new ExcelItem
                {
                    RowName  = heads[i],
                    DataType = cbDataType.SelectedItem.ToString(),
                    With     = barWidth.Value,
                };
                if (mappings.Length > 1)
                {
                    ei.Mapping = mappings[i];
                }
                if (string.IsNullOrEmpty(ei.Mapping)) //映射可以不写 默认是表头名
                {
                    ei.Mapping = ei.RowName;
                }
                ListBoxItem lbi = new ListBoxItem
                {
                    Value = ei,
                    Text  = ei.RowName
                };
                listItemData.Items.Add(lbi);
            }

            //var builder = new ExcelCodeBuilder();
            //StringBuilder temp = builder.BuilderCode(this.txtFileName.Text, heads, mappings);
            //this.txtResult.Text = temp.ToString();
            //Clipboard.SetDataObject(temp.ToString());
        }
Пример #6
0
        /// <summary>
        /// 映射字段回车判断
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtMapp_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && listItemData.SelectedIndex >= 0)//如果输入的是回车键 且有选中项目
            {
                var temp = listItemData.SelectedItem as ListBoxItem;
                if (temp == null)
                {
                    return;
                }
                ExcelItem t = temp.Value as ExcelItem;
                if (t == null)
                {
                    return;
                }
                t.RowName  = txtRowName.Text;
                t.DataType = cbDataType.SelectedItem.ToString();
                t.With     = barWidth.Value;
                t.Mapping  = this.txtMapp.Text;

                ResertData();
            }
        }
Пример #7
0
        /// <summary>
        /// 单选点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listItemData_Click(object sender, EventArgs e)
        {
            ListBox listBox = sender as ListBox;

            if (listBox != null && listBox.SelectedIndex >= 0)
            {
                var temp = listBox.SelectedItem as ListBoxItem;
                if (temp == null)
                {
                    return;
                }
                ExcelItem t = temp.Value as ExcelItem;
                if (t == null)
                {
                    return;
                }
                this.txtRowName.Text = t.RowName;
                this.cbDataType.Text = t.DataType;
                this.barWidth.Value  = t.With;
                this.labelWidth.Text = t.With.ToString();
                this.txtMapp.Text    = t.Mapping;
            }
        }
Пример #8
0
        private void LoadExcel(List<string> excelFileList, List<ExcelItem> workSheetList)
        {
            foreach(string filePath in excelFileList)
            {
                Excel.WorkbookClass workbook;
                try
                {

                    object miss = System.Reflection.Missing.Value;
                    workbook = (Excel.WorkbookClass)ExcelApp.Workbooks.Open(filePath,
                        miss, true, miss, miss, miss, true, miss, miss, true, miss, miss, miss, miss, miss);
                }
                catch (System.Exception)
                {
                    workbook = null;
                    ExcelApp.Quit();
                }

                if (workbook == null)
                {
                    Log(ELogType.ERROR, "载入文件失败, 文件名:{0}", filePath);
                    continue;
                }

                Excel.Worksheet sheet = workbook.Worksheets.get_Item(1) as Excel.Worksheet;
                ExcelItem item = new ExcelItem();
                item.SheetName = sheet.Name;
                item.Sheet = sheet;
                item.Workbook = workbook;
                workSheetList.Add(item);
            }
        }
Пример #9
0
        /// <summary>
        /// 重写基类 生成Repeater对应代码
        /// </summary>
        /// <param name="inputSql">
        /// 0:ObjectCollection集合 类型ListBoxItem</param>
        /// <returns></returns>
        public override StringBuilder BuilderCode(params object[] inputSql)
        {
            StringBuilder codeBuilder = new StringBuilder();
            var           tempBox     = (inputSql[0] as ListBox.ObjectCollection);

            if (tempBox == null)
            {
                return(codeBuilder);
            }

            codeBuilder.AppendLine("<table class=\"resultTable\" cellspacing=\"1\" id=\"tableContent\">");
            codeBuilder.AppendLine("<tr class=\"resultTr\">");
            StringBuilder dataBindBuilder = new StringBuilder();

            foreach (ListBoxItem item in tempBox)
            {
                ExcelItem t = item.Value as ExcelItem;
                if (t == null)
                {
                    continue;
                }
                DataType dt = (DataType)Enum.Parse(typeof(DataType), t.DataType);
                switch (dt)
                {
                case DataType.全选:
                {
                    codeBuilder.AppendLine(string.Format("<td style=\"width:5%;\">{0}</td>", t.RowName));
                    break;
                }

                default:
                {
                    codeBuilder.AppendLine(string.Format("<td>{0}</td>", t.RowName));
                    break;
                }
                }
                switch (dt)
                {
                case DataType.两位小数:
                {
                    dataBindBuilder.AppendLine(string.Format("<td><%# Eval(\"{0}\", \"{{0:N2}}\")%></td>", t.Mapping));
                    break;
                }

                case DataType.标准日期:
                {
                    dataBindBuilder.AppendLine(string.Format("<td><%# Eval(\"{0}\", \"{{0:d}}\")%></td>", t.Mapping));
                    break;
                }

                case DataType.标准时间:
                {
                    dataBindBuilder.AppendLine(string.Format("<td><%# Eval(\"{0}\", \"{{0:s}}\")%></td>", t.Mapping));
                    break;
                }

                case DataType.查看编辑:
                {
                    dataBindBuilder.AppendLine(string.Format("<td><a href=\"javascript:;\" class=\"listButton detail\" onclick=\"jsView('<%# Eval(\"{0}\")%>')\">查看</a>" +
                                                             "<a href=\"javascript:;\"  class=\"listButton edit\" onclick=\"jsEdit('<%# Eval(\"{0}\")%>')\">编辑</a></td>", t.Mapping));
                    break;
                }

                case DataType.输入编辑:
                {
                    dataBindBuilder.AppendLine(string.Format("<td><input type=\"text\" value=\"<%# Eval(\"{0}\")%>\"/></td>", t.Mapping));
                    break;
                }

                case DataType.全选:
                {
                    dataBindBuilder.AppendLine(string.Format("<td><input type=\"checkbox\"  class=\"check-item\" value=\"<%# Eval(\"{0}\")%>\"/></td>", t.Mapping));
                    break;
                }

                default:
                    dataBindBuilder.AppendLine(string.Format("<td><%# Eval(\"{0}\")%></td>", t.Mapping));
                    break;
                }
            }
            codeBuilder.AppendLine("</tr>");
            codeBuilder.AppendLine("<asp:Repeater ID=\"rptDataList\" runat=\"server\">" +
                                   "<ItemTemplate>");
            codeBuilder.AppendLine("<tr class=\"alignCenter\">" + dataBindBuilder + " </tr>");
            codeBuilder.AppendLine("</ItemTemplate>" +
                                   "</asp:Repeater>" +
                                   "</table>");
            return(codeBuilder);
        }