예제 #1
0
        private void btnBindingSource_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("BindingSource bindSource = new BindingSource();");
            //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);

               var bind= string.Format("this.txt{0}.DataBindings.Add(\"Text\", bindSource, \"{0}\", true);\r\n", field );
                sb.Append(bind);
               // sb.Append(string.Format("info.{0} = {1}\n", field, fieldParse));
            }
            txtBindSource.Text = sb.ToString();

            // BindingSource bindSource = new BindingSource();
        }
예제 #2
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);
            }
        }
예제 #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
 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);
     }
 }
예제 #5
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();
        }