Beispiel #1
0
        private void btnGen_Click(object sender, EventArgs e)
        {
            m_SelTables.Clear();
            int iRow = 0;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                int iCol = 0;
                foreach (DataGridViewCell cell in row.Cells)
                {
                    if (iCol == 0)
                    {
                        bool ifcheck1 = Convert.ToBoolean(cell.FormattedValue);
                        if (ifcheck1)
                        {
                            TableName tb = m_tables[iRow];
                            m_SelTables.Add(tb);
                        }
                    }

                    iCol++;
                }

                iRow++;
            }


            CreateFileHelper.Create(m_SelTables, txtPath.Text.Trim());

            MessageBox.Show("代码类文件生成完成,请到文件夹:" + txtPath.Text.Trim() + "中查看");
        }
Beispiel #2
0
        /// <summary>
        /// 创建文件目录和文件
        /// </summary>
        /// <param name="tables">所有表</param>
        /// <param name="fileDir">文件目录</param>
        public static void Create(List <TableName> tables, string fileDir)
        {
            CreateDirectory(fileDir);
            foreach (TableName table in tables)
            {
                //实体类名称
                string entityName = GenVarName(table.Name);
                //实体类文件名
                string filePath = fileDir + entityName + ".cs";
                //文件是否存在
                bool exists = File.Exists(filePath);

                //创建文件
                FileStream   fs = new FileStream(filePath, exists ? FileMode.Open : FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs);

                //生成代码
                string code = CreateFileHelper.BuilderCode(table.Name);

                //写入代码到文件
                sw.WriteLine(code);

                sw.Close();
                fs.Close();
            }
        }
Beispiel #3
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)//当单击复选框,同时处于组合编辑状态时
            {
                DataGridViewCell cell     = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
                bool             ifcheck1 = Convert.ToBoolean(cell.FormattedValue);
                bool             ifcheck2 = Convert.ToBoolean(cell.EditedFormattedValue);

                if (ifcheck1 != ifcheck2)
                {
                    TableName tb = m_tables[e.RowIndex];
                    reLoadColumns(tb.Name);
                    string code = CreateFileHelper.BuilderCode(tb.Name);
                    code           = code.Replace("\n", "\r\n");
                    txtSyntax.Text = code;
                }
            }
        }