예제 #1
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                // create an anonymous delegate
                FileExists fileExists = delegate(string p_OutputDir, string p_FileName, ref FileHandlingResult fhResult)
                {
                    // "File " + fileName +" exists.  What should I do?" [Overwrite], [Rename], [Cancel]
                    FileExistsForm fileExistsForm = new FileExistsForm();
                    fileExistsForm.Directory = p_OutputDir;
                    fileExistsForm.File      = p_FileName;
                    fileExistsForm.ShowDialog(this);
                    fhResult = fileExistsForm.Result;
                    fileExistsForm.Dispose();
                };

                ModelGenerator modelGen = new ModelGenerator(fileExists, NameSpace, chkPartial.Checked, chkPropChange.Checked, chkValidation.Checked);
                DbTableInfo    table;
                string         sTemplate;
                tsStatus.Text = "Generating ... ";
                int curPct = 0;
                tsProgressBar.Value = curPct;
                for (int i = 0; i < chkLbTables.Items.Count; i++)
                {
                    curPct = (int)((100.0 * i) / chkLbTables.Items.Count);
                    if (curPct >= tsProgressBar.Value + 5)
                    {
                        tsProgressBar.Value = curPct;
                        this.Refresh();
                    }
                    if (chkLbTables.GetItemChecked(i))
                    {
                        table = (DbTableInfo)chkLbTables.Items[i];

                        for (int j = 0; j < chkLbTemplates.Items.Count; j++)
                        {
                            if (chkLbTemplates.GetItemChecked(j))
                            {
                                sTemplate = (string)chkLbTemplates.Items[j];
                                modelGen.GenerateClass(sTemplate, table, OutputDir);
                                // cancel all
                                if (modelGen.GetFileHandlingResult() == (FileHandlingResult.Cancel | FileHandlingResult.All))
                                {
                                    tsProgressBar.Value = 0;
                                    goto loop_i;
                                }
                            }
                        }
                    }
                }
loop_i:
                tsProgressBar.Value = 100;
                tsStatus.Text       = "Code Generation Complete!";
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }
예제 #2
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                // create an anonymous delegate
                FileExists fileExists = delegate(string p_OutputDir, string p_FileName, ref FileHandlingResult fhResult)
                {
                    // "File " + fileName +" exists.  What should I do?" [Overwrite], [Rename], [Cancel]
                    FileExistsForm fileExistsForm = new FileExistsForm();
                    fileExistsForm.Directory = p_OutputDir;
                    fileExistsForm.File = p_FileName;
                    fileExistsForm.ShowDialog(this);
                    fhResult = fileExistsForm.Result;
                    fileExistsForm.Dispose();
                };

                ModelGenerator modelGen = new ModelGenerator(fileExists, NameSpace, chkPartial.Checked, chkPropChange.Checked, chkValidation.Checked);
                DbTableInfo table;
                string sTemplate;
                tsStatus.Text = "Generating ... ";
                int curPct = 0;
                tsProgressBar.Value = curPct;
                for (int i = 0; i < chkLbTables.Items.Count; i++)
                {
                    curPct = (int)((100.0 * i) / chkLbTables.Items.Count);
                    if (curPct >= tsProgressBar.Value + 5)
                    {
                        tsProgressBar.Value = curPct;
                        this.Refresh();
                    }
                    if (chkLbTables.GetItemChecked(i))
                    {
                        table = (DbTableInfo)chkLbTables.Items[i];

                        for (int j = 0; j < chkLbTemplates.Items.Count; j++)
                        {
                            if (chkLbTemplates.GetItemChecked(j))
                            {
                                sTemplate = (string)chkLbTemplates.Items[j];
                                modelGen.GenerateClass(sTemplate, table, OutputDir);
                                // cancel all
                                if (modelGen.GetFileHandlingResult() == (FileHandlingResult.Cancel | FileHandlingResult.All))
                                {
                                    tsProgressBar.Value = 0;
                                    goto loop_i;
                                }
                            }
                        }
                    }
                }
                loop_i:
                tsProgressBar.Value = 100;
                tsStatus.Text = "Code Generation Complete!";

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }