Пример #1
0
        private void WriteUI_Field(StreamWriter sWriter)
        {
            var table = (DataTable)this.gridColumns.DataSource;
            CsType cstype = new CsType();
            foreach (DataRow dr in table.Rows)
            {
                var field = dr["ColumnName"].ToString();
                if (field == "CreateAt") continue;
                if (field == "statu") continue;
                var ftype = dr["ColumnType"].ToString();

                var fieldToString = field;
                var whatType = cstype.GetLower(ftype);
                if (whatType != "string") fieldToString += ".ToString()";
                var outline = string.Format("            txt{0}.Text = info.{1};", field, fieldToString);
                sWriter.Write(outline + Environment.NewLine);
            }
        }
Пример #2
0
 private void WriteField_Members(StreamWriter sWriter)
 {
     var table = (DataTable)this.gridColumns.DataSource;
     CsType cstype = new CsType();
     foreach (DataRow dr in table.Rows)
     {
         var field = dr["ColumnName"].ToString();
         var ftype = dr["ColumnType"].ToString();
         if (field == "CreateAt") continue;
         if (field == "statu") continue;
         var what = cstype.GetLower(ftype);
         var outline = string.Format("\t\tpublic {0} {1} {{ get; set; }}", what, field);
         sWriter.Write(outline + Environment.NewLine);
     }
 }
Пример #3
0
        private void WriteField_UI(StreamWriter sWriter)
        {
            var table = (DataTable)this.gridColumns.DataSource;
            CsType cstype = new CsType();
            foreach (DataRow dr in table.Rows)
            {
                var field = dr["ColumnName"].ToString();
                if (field == "CreateAt" || field == "ID" || field == "statu") continue;
                var ftype = dr["ColumnType"].ToString();

                var fieldParse = string.Format("txt{0}.Text;", field);
                var whatType = cstype.GetLower(ftype);
                if (whatType != "string")
                    fieldParse = string.Format("{0}.Parse(txt{1}.Text);", whatType, field);
                //if (whatType == "DateTime?")
                //    fieldParse = string.Format("txt合同签订日.Text == \"\" ? (DateTime?)null : DateTime.Parse(txt合同签订日.Text);", whatType, field);
                var outline = string.Format("            info.{0} = {1}", field, fieldParse);
                sWriter.Write(outline + Environment.NewLine);
            }
        }
Пример #4
0
        //UI界面上的数据转换成实体类, 这个是针对DataGridViewRow来写的,
        private void btn_Row_To_Entity_Click(object sender, EventArgs e)
        {
            var tablename = txtTableName.Text;
            var table = (DataTable)this.gridColumns.DataSource;
            CsType cstype = new CsType();
            var sb = new StringBuilder();
            sb.Append(string.Format(" {0} info = new {0}();\n", tablename));

            foreach (DataRow dr in table.Rows)
            {
                var field = dr["ColumnName"].ToString();
                if (field == "CreateAt" || field == "statu") continue;
                var ftype = dr["ColumnType"].ToString();

                var fieldParse = string.Format("dr.Cells[\"{0}\"].Value.ToString();", field);
                var whatType = cstype.GetLower(ftype);
                if (whatType != "string")
                    fieldParse = string.Format("{0}.Parse(dr.Cells[\"{1}\"].Value.ToString());", whatType, field);

                sb.Append(string.Format("info.{0} = {1}\n", field, fieldParse));
            }
            txtUI_Entity.Text = sb.ToString();
        }