Example #1
0
        public static List <TypeColumnName> GetColunmsList()
        {
            var d = GetCommonData();

            var typeNameList = new List <TypeColumnName>();
            int i            = 0;

            d.ColumnsList.ForEach(r =>
            {
                WebUploadColunm webuploadColunm;
                string className = FormControl.Textbox;

                if (i == 0)
                {
                    webuploadColunm = new WebUploadColunm(true, r);
                }
                else if (i == 1)
                {
                    webuploadColunm = new WebUploadColunm(true, r, UploadType.Img);
                }
                else if (i == 2)
                {
                    className       = FormControl.Combobox;
                    webuploadColunm = new WebUploadColunm();
                }
                else
                {
                    webuploadColunm = new WebUploadColunm();
                }

                if (i == 3)
                {
                    className = FormControl.Combo;
                }
                typeNameList.Add(new TypeColumnName()
                {
                    ColumnName = r,
                    AttrType   = d.ColumnsTypeList[i],
                    Comments   = d.ColumnsNameList[i],
                    IsRequired = i % 2 == 0 ? "1" : "0",
                    DataLength = 50 + i
                });
                i++;
            });
            return(typeNameList);
        }
Example #2
0
        public void TestJson()
        {
            var a = new WebUploadColunm(true, UploadType.Img);

            string jsonStrings = JsonConvert.SerializeObject(a);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //表中字段名
                List <string> columnsList = this.Columns.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None).Where(s => !string.IsNullOrEmpty(s)).Select(u => u.Trim()).ToList();
                //中文名
                List <string> columnsNameList = this.ColumnsName.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None).Where(s => !string.IsNullOrEmpty(s)).Select(u => u.Trim()).ToList();
                //字段填充到HTML中的内容
                List <string> columnsHtmlList = this.ColumnsHtml.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None).Select(u => u.Trim()).ToList();
                //字段类型
                List <string> columnsTypeList = this.ColumnsType.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None).Where(s => !string.IsNullOrEmpty(s)).Select(
                    u =>
                {
                    string conlumsType = u.Trim().ToLower();
                    //将传入的参数按程序中的类型进行转换
                    return(TypeHelper.TypeChangeDictionary.FirstOrDefault(r => conlumsType.Contains(r.Key)).Value);
                }).ToList();

                if (columnsList.Count != columnsTypeList.Count || columnsList.Count != columnsNameList.Count)
                {
                    throw new ArgumentException("字段之间个数不匹配!");
                }
                //生成每个字段对应的中文名-类型-以及是否必填,是否Combobox等内容
                List <TypeColumnName> typeNameList = new List <TypeColumnName>();
                for (int i = 0; i < columnsList.Count; i++)
                {
                    if (columnsList[i].Contains("$") && columnsList[i].Contains("#"))
                    {
                        throw new ArgumentException("无法同时上传图片和文件!");
                    }
                    string columnName = columnsList[i].Replace("*", "").Replace("#", "").Replace("$", "").Replace("%", "").Replace("@", "");
                    //*是必填
                    //#是上传图片
                    //$是上传文件
                    //%是跨行
                    //@是下拉框
                    WebUploadColunm webuploadColunm;
                    if (columnsList[i].Contains("#"))
                    {
                        webuploadColunm = new WebUploadColunm(true, columnName, UploadType.Img);
                    }
                    else if (columnsList[i].Contains("$"))
                    {
                        webuploadColunm = new WebUploadColunm(true, columnName, UploadType.File);
                    }
                    else
                    {
                        webuploadColunm = new WebUploadColunm();
                    }

                    typeNameList.Add(new TypeColumnName()
                    {
                        ColumnName = columnName,
                        AttrType   = columnsTypeList[i],
                        Comments   = columnsNameList[i],
                        IsRequired = columnsList[i].Contains("*") ? "1" : "0",
                        DataLength = 100,
                        IsCombobox = columnsList[i].Contains("@") ? true : false,
                        IsColspan3 = columnsList[i].Contains("%") ? "1" : "0"
                    });
                }

                ViewFileModel vf = new ViewFileModel
                {
                    CreateTime      = DateTime.Now,
                    EmailAddress    = this.EmailAddress.Text,
                    Author          = this.UserName.Text,
                    TableName       = this.TableName.Text,
                    ProjectName     = this.ProjectName.Text,
                    TypeColumnNames = typeNameList,
                    IdType          = _idType,
                    TemplateFolder  = @"..\..\Templates",
                    OutputFolder    = outputsFolder.Text ?? @"..\..\Outputs"
                };

                var bussiness = new AddNewBussinessWpfHelper(vf);

                bussiness.Execute();

                MessageBox.Show("操作成功!");
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }