代码生成器的DiaLog

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using Microsoft.Win32;

namespace CodeGennera
{
 /*=========Form Begin==============*/
 public  class FrmDialog : Form
 {
  public FrmDialog()
  {
   InitializeComponent();
  }

  #region 设计器
  private GroupBox groupBox1;
  private ComboBox cmbDatabase;
  private Label label3;
  private Label label2;
  private Label label1;
  private GroupBox groupBox2;
  private Button btnLeftAll;
  private Button btnLeft;
  private Button btnRight;
  private Button btnRightAll;
  private ListBox lstSelectTable;
  private ListBox lstAllTable;
  private GroupBox groupBox3;
  private TextBox txtNameSpaceTop;
  private Label label4;
  private Label label5;
  private TextBox txtHelpName;
  private Button btnSelectPath;
  private Label label6;
  private TextBox txtPath;
  private Button btnSave;
  private TextBox txtNameSpaceHelp;
  private Label label9;
  private TextBox txtNameSpaceDal;
  private TextBox txtNameSpaceBll;
  private Label label8;
  private Label label7;
  private Button btnCreate;
  private ListBox lstTmp;
  private Label label11;
  private Label label10;

 


private System.ComponentModel.IContainer components = null;
   protected override void Dispose(bool disposing)
   {
    if (disposing && (components != null))
    {
     components.Dispose();
    }
    base.Dispose(disposing);

   }

   private void InitializeComponent()
   {
    this.groupBox1 = new System.Windows.Forms.GroupBox();
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.label3 = new System.Windows.Forms.Label();
    this.cmbDatabase = new System.Windows.Forms.ComboBox();
    this.groupBox2 = new System.Windows.Forms.GroupBox();
    this.lstAllTable = new System.Windows.Forms.ListBox();
    this.lstSelectTable = new System.Windows.Forms.ListBox();
    this.btnRightAll = new System.Windows.Forms.Button();
    this.btnRight = new System.Windows.Forms.Button();
    this.btnLeft = new System.Windows.Forms.Button();
    this.btnLeftAll = new System.Windows.Forms.Button();
    this.groupBox3 = new System.Windows.Forms.GroupBox();
    this.label4 = new System.Windows.Forms.Label();
    this.txtNameSpaceTop = new System.Windows.Forms.TextBox();
    this.txtHelpName = new System.Windows.Forms.TextBox();
    this.label5 = new System.Windows.Forms.Label();
    this.txtPath = new System.Windows.Forms.TextBox();
    this.label6 = new System.Windows.Forms.Label();
    this.btnSelectPath = new System.Windows.Forms.Button();
    this.btnSave = new System.Windows.Forms.Button();
    this.label7 = new System.Windows.Forms.Label();
    this.label8 = new System.Windows.Forms.Label();
    this.txtNameSpaceBll = new System.Windows.Forms.TextBox();
    this.txtNameSpaceDal = new System.Windows.Forms.TextBox();
    this.label9 = new System.Windows.Forms.Label();
    this.txtNameSpaceHelp = new System.Windows.Forms.TextBox();
    this.btnCreate = new System.Windows.Forms.Button();
    this.lstTmp = new System.Windows.Forms.ListBox();
    this.label10 = new System.Windows.Forms.Label();
    this.label11 = new System.Windows.Forms.Label();
    this.groupBox1.SuspendLayout();
    this.groupBox2.SuspendLayout();
    this.groupBox3.SuspendLayout();
    this.SuspendLayout();
    //
    // groupBox1
    //
    this.groupBox1.Controls.Add(this.cmbDatabase);
    this.groupBox1.Controls.Add(this.label3);
    this.groupBox1.Controls.Add(this.label2);
    this.groupBox1.Controls.Add(this.label1);
    this.groupBox1.Location = new System.Drawing.Point(32, 12);
    this.groupBox1.Name = "groupBox1";
    this.groupBox1.Size = new System.Drawing.Size(644, 69);
    this.groupBox1.TabIndex = 0;
    this.groupBox1.TabStop = false;
    this.groupBox1.Text = "选择数据库存";
    //
    // label1
    //
    this.label1.AutoSize = true;
    this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
    this.label1.Location = new System.Drawing.Point(20, 32);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(71, 12);
    this.label1.TabIndex = 0;
    this.label1.Text = "当前服务器:";
    //
    // label2
    //
    this.label2.AutoSize = true;
    this.label2.Location = new System.Drawing.Point(132, 32);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(35, 12);
    this.label2.TabIndex = 1;
    this.label2.Text = "Local";
    //
    // label3
    //
    this.label3.AutoSize = true;
    this.label3.Location = new System.Drawing.Point(374, 32);
    this.label3.Name = "label3";
    this.label3.Size = new System.Drawing.Size(71, 12);
    this.label3.TabIndex = 2;
    this.label3.Text = "选择数据库:";
    //
    // cmbDatabase
    //
    this.cmbDatabase.FormattingEnabled = true;
    this.cmbDatabase.Location = new System.Drawing.Point(495, 29);
    this.cmbDatabase.Name = "cmbDatabase";
    this.cmbDatabase.Size = new System.Drawing.Size(121, 20);
    this.cmbDatabase.TabIndex = 3;
    this.cmbDatabase.SelectedIndexChanged += new System.EventHandler(this.cmbDatabase_SelectedIndexChanged);
    //
    // groupBox2
    //
    this.groupBox2.Controls.Add(this.label11);
    this.groupBox2.Controls.Add(this.label10);
    this.groupBox2.Controls.Add(this.btnLeftAll);
    this.groupBox2.Controls.Add(this.btnLeft);
    this.groupBox2.Controls.Add(this.btnRight);
    this.groupBox2.Controls.Add(this.btnRightAll);
    this.groupBox2.Controls.Add(this.lstSelectTable);
    this.groupBox2.Controls.Add(this.lstAllTable);
    this.groupBox2.Location = new System.Drawing.Point(32, 92);
    this.groupBox2.Name = "groupBox2";
    this.groupBox2.Size = new System.Drawing.Size(644, 204);
    this.groupBox2.TabIndex = 1;
    this.groupBox2.TabStop = false;
    this.groupBox2.Text = "选择表";
    //
    // lstAllTable
    //
    this.lstAllTable.FormattingEnabled = true;
    this.lstAllTable.ItemHeight = 12;
    this.lstAllTable.Location = new System.Drawing.Point(6, 38);
    this.lstAllTable.Name = "lstAllTable";
    this.lstAllTable.Size = new System.Drawing.Size(232, 160);
    this.lstAllTable.TabIndex = 0;
    //
    // lstSelectTable
    //
    this.lstSelectTable.FormattingEnabled = true;
    this.lstSelectTable.ItemHeight = 12;
    this.lstSelectTable.Location = new System.Drawing.Point(401, 38);
    this.lstSelectTable.Name = "lstSelectTable";
    this.lstSelectTable.Size = new System.Drawing.Size(226, 160);
    this.lstSelectTable.TabIndex = 1;
    //
    // btnRightAll
    //
    this.btnRightAll.Location = new System.Drawing.Point(277, 51);
    this.btnRightAll.Name = "btnRightAll";
    this.btnRightAll.Size = new System.Drawing.Size(75, 23);
    this.btnRightAll.TabIndex = 2;
    this.btnRightAll.Text = ">>";
    this.btnRightAll.UseVisualStyleBackColor = true;
    this.btnRightAll.Click += new System.EventHandler(this.btnRightAll_Click);
    //
    // btnRight
    //
    this.btnRight.Location = new System.Drawing.Point(277, 89);
    this.btnRight.Name = "btnRight";
    this.btnRight.Size = new System.Drawing.Size(75, 23);
    this.btnRight.TabIndex = 3;
    this.btnRight.Text = ">";
    this.btnRight.UseVisualStyleBackColor = true;
    this.btnRight.Click += new System.EventHandler(this.btnRight_Click);
    //
    // btnLeft
    //
    this.btnLeft.Location = new System.Drawing.Point(277, 127);
    this.btnLeft.Name = "btnLeft";
    this.btnLeft.Size = new System.Drawing.Size(75, 23);
    this.btnLeft.TabIndex = 4;
    this.btnLeft.Text = "<";
    this.btnLeft.UseVisualStyleBackColor = true;
    this.btnLeft.Click += new System.EventHandler(this.btnLeft_Click);
    //
    // btnLeftAll
    //
    this.btnLeftAll.Location = new System.Drawing.Point(277, 166);
    this.btnLeftAll.Name = "btnLeftAll";
    this.btnLeftAll.Size = new System.Drawing.Size(75, 23);
    this.btnLeftAll.TabIndex = 5;
    this.btnLeftAll.Text = "<<";
    this.btnLeftAll.UseVisualStyleBackColor = true;
    this.btnLeftAll.Click += new System.EventHandler(this.btnLeftAll_Click);
    //
    // groupBox3
    //
    this.groupBox3.Controls.Add(this.txtNameSpaceHelp);
    this.groupBox3.Controls.Add(this.label9);
    this.groupBox3.Controls.Add(this.txtNameSpaceDal);
    this.groupBox3.Controls.Add(this.txtNameSpaceBll);
    this.groupBox3.Controls.Add(this.label8);
    this.groupBox3.Controls.Add(this.label7);
    this.groupBox3.Controls.Add(this.btnSelectPath);
    this.groupBox3.Controls.Add(this.label6);
    this.groupBox3.Controls.Add(this.txtPath);
    this.groupBox3.Controls.Add(this.label5);
    this.groupBox3.Controls.Add(this.txtHelpName);
    this.groupBox3.Controls.Add(this.txtNameSpaceTop);
    this.groupBox3.Controls.Add(this.label4);
    this.groupBox3.Location = new System.Drawing.Point(32, 305);
    this.groupBox3.Name = "groupBox3";
    this.groupBox3.Size = new System.Drawing.Size(644, 135);
    this.groupBox3.TabIndex = 2;
    this.groupBox3.TabStop = false;
    this.groupBox3.Text = "参数选择";
    //
    // label4
    //
    this.label4.AutoSize = true;
    this.label4.Location = new System.Drawing.Point(22, 32);
    this.label4.Name = "label4";
    this.label4.Size = new System.Drawing.Size(77, 12);
    this.label4.TabIndex = 0;
    this.label4.Text = "TOP命名空间:";
    //
    // txtNameSpaceTop
    //
    this.txtNameSpaceTop.Location = new System.Drawing.Point(108, 29);
    this.txtNameSpaceTop.Name = "txtNameSpaceTop";
    this.txtNameSpaceTop.Size = new System.Drawing.Size(118, 21);
    this.txtNameSpaceTop.TabIndex = 1;
    //
    // txtHelpName
    //
    this.txtHelpName.Location = new System.Drawing.Point(487, 68);
    this.txtHelpName.Name = "txtHelpName";
    this.txtHelpName.Size = new System.Drawing.Size(140, 21);
    this.txtHelpName.TabIndex = 2;
    //
    // label5
    //
    this.label5.AutoSize = true;
    this.label5.Location = new System.Drawing.Point(349, 71);
    this.label5.Name = "label5";
    this.label5.Size = new System.Drawing.Size(83, 12);
    this.label5.TabIndex = 3;
    this.label5.Text = "数据访问类名:";
    //
    // txtPath
    //
    this.txtPath.Location = new System.Drawing.Point(108, 108);
    this.txtPath.Name = "txtPath";
    this.txtPath.Size = new System.Drawing.Size(337, 21);
    this.txtPath.TabIndex = 4;
    //
    // label6
    //
    this.label6.AutoSize = true;
    this.label6.Location = new System.Drawing.Point(20, 120);
    this.label6.Name = "label6";
    this.label6.Size = new System.Drawing.Size(59, 12);
    this.label6.TabIndex = 5;
    this.label6.Text = "保存路径:";
    //
    // btnSelectPath
    //
    this.btnSelectPath.Location = new System.Drawing.Point(476, 108);
    this.btnSelectPath.Name = "btnSelectPath";
    this.btnSelectPath.Size = new System.Drawing.Size(82, 23);
    this.btnSelectPath.TabIndex = 6;
    this.btnSelectPath.Text = "选择路径";
    this.btnSelectPath.UseVisualStyleBackColor = true;
    this.btnSelectPath.Click += new System.EventHandler(this.btnSelectPath_Click);
    //
    // btnSave
    //
    this.btnSave.Location = new System.Drawing.Point(140, 446);
    this.btnSave.Name = "btnSave";
    this.btnSave.Size = new System.Drawing.Size(75, 23);
    this.btnSave.TabIndex = 3;
    this.btnSave.Text = "保存设置";
    this.btnSave.UseVisualStyleBackColor = true;
    this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
    //
    // label7
    //
    this.label7.AutoSize = true;
    this.label7.Location = new System.Drawing.Point(248, 32);
    this.label7.Name = "label7";
    this.label7.Size = new System.Drawing.Size(77, 12);
    this.label7.TabIndex = 7;
    this.label7.Text = "BLL命名空间:";
    //
    // label8
    //
    this.label8.AutoSize = true;
    this.label8.Location = new System.Drawing.Point(463, 32);
    this.label8.Name = "label8";
    this.label8.Size = new System.Drawing.Size(77, 12);
    this.label8.TabIndex = 8;
    this.label8.Text = "DAL命名空间:";
    //
    // txtNameSpaceBll
    //
    this.txtNameSpaceBll.Location = new System.Drawing.Point(332, 29);
    this.txtNameSpaceBll.Name = "txtNameSpaceBll";
    this.txtNameSpaceBll.Size = new System.Drawing.Size(100, 21);
    this.txtNameSpaceBll.TabIndex = 9;
    //
    // txtNameSpaceDal
    //
    this.txtNameSpaceDal.Location = new System.Drawing.Point(538, 29);
    this.txtNameSpaceDal.Name = "txtNameSpaceDal";
    this.txtNameSpaceDal.Size = new System.Drawing.Size(100, 21);
    this.txtNameSpaceDal.TabIndex = 10;
    //
    // label9
    //
    this.label9.AutoSize = true;
    this.label9.Location = new System.Drawing.Point(22, 71);
    this.label9.Name = "label9";
    this.label9.Size = new System.Drawing.Size(119, 12);
    this.label9.TabIndex = 11;
    this.label9.Text = "数据访问类命名空间:";
    //
    // txtNameSpaceHelp
    //
    this.txtNameSpaceHelp.Location = new System.Drawing.Point(147, 68);
    this.txtNameSpaceHelp.Name = "txtNameSpaceHelp";
    this.txtNameSpaceHelp.Size = new System.Drawing.Size(135, 21);
    this.txtNameSpaceHelp.TabIndex = 12;
    //
    // btnCreate
    //
    this.btnCreate.Location = new System.Drawing.Point(292, 447);
    this.btnCreate.Name = "btnCreate";
    this.btnCreate.Size = new System.Drawing.Size(75, 23);
    this.btnCreate.TabIndex = 4;
    this.btnCreate.Text = "生成代码";
    this.btnCreate.UseVisualStyleBackColor = true;
    this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click);
    //
    // lstTmp
    //
    this.lstTmp.FormattingEnabled = true;
    this.lstTmp.ItemHeight = 12;
    this.lstTmp.Location = new System.Drawing.Point(570, 372);
    this.lstTmp.Name = "lstTmp";
    this.lstTmp.Size = new System.Drawing.Size(120, 88);
    this.lstTmp.TabIndex = 5;
    //
    // label10
    //
    this.label10.AutoSize = true;
    this.label10.Location = new System.Drawing.Point(85, 23);
    this.label10.Name = "label10";
    this.label10.Size = new System.Drawing.Size(53, 12);
    this.label10.TabIndex = 6;
    this.label10.Text = "数据库表";
    //
    // label11
    //
    this.label11.AutoSize = true;
    this.label11.Location = new System.Drawing.Point(487, 21);
    this.label11.Name = "label11";
    this.label11.Size = new System.Drawing.Size(65, 12);
    this.label11.TabIndex = 7;
    this.label11.Text = "已选择的表";
    //
    // FrmDialog
    //
    this.AllowDrop = true;
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(718, 481);
    this.Controls.Add(this.lstTmp);
    this.Controls.Add(this.btnCreate);
    this.Controls.Add(this.btnSave);
    this.Controls.Add(this.groupBox3);
    this.Controls.Add(this.groupBox2);
    this.Controls.Add(this.groupBox1);
    this.MaximizeBox = false;
    this.MinimizeBox = false;
    this.Name = "FrmDialog";
    this.Text = "代码生成器";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.DragDrop += new System.Windows.Forms.DragEventHandler(this.FrmDialog_DragDrop);
    this.DragEnter += new System.Windows.Forms.DragEventHandler(this.FrmDialog_DragEnter);
    this.groupBox1.ResumeLayout(false);
    this.groupBox1.PerformLayout();
    this.groupBox2.ResumeLayout(false);
    this.groupBox2.PerformLayout();
    this.groupBox3.ResumeLayout(false);
    this.groupBox3.PerformLayout();
    this.ResumeLayout(false);

   }

#endregion

   private dbRoot myMeta;
   private IZeusInput zeusInput;
      public FrmDialog(dbRoot myMeta, IZeusInput zeusInput)
           {
              this.myMeta    = myMeta;
              this.zeusInput = zeusInput;
              InitializeComponent();
            }   
   #region 方法
   private void Form1_Load(object sender, EventArgs e)
   {
    //获取数据库,传给ComboBox
    this.cmbDatabase.DataSource = this.myMeta.Databases;
    //ComboBox显示数据库名
    this.cmbDatabase.DisplayMember = "Name";
    if (null != this.myMeta.DefaultDatabase)
    {
     //选中默认的数据库
     this.cmbDatabase.SelectedIndex = this.cmbDatabase.FindStringExact(this.myMeta.DefaultDatabase.Name);
    }
    this.lstTmp.Visible = false;

    RegistryKey reg;
    reg = Registry.CurrentUser;
    reg = reg.OpenSubKey("Software\\Wolf\\xiang1");
    txtPath.Text = (string)reg.GetValue("outputPath", "");
    txtNameSpaceTop.Text = (string)reg.GetValue("topNamespace", "");
    txtNameSpaceBll.Text = (string)reg.GetValue("bllNamespace", "");
    txtNameSpaceDal.Text = (string)reg.GetValue("dalNamespace", "");
    txtNameSpaceHelp.Text = (string)reg.GetValue("helpNamespace", "");
    txtHelpName.Text = (string)reg.GetValue("helpClassName", "");

    
   }
   #endregion

  private void cmbDatabase_SelectedIndexChanged(object sender, EventArgs e)
  {
   IDatabase database = this.cmbDatabase.SelectedValue as IDatabase;
   if (database != null)
   {
    
    lstTmp.DataSource = database.Tables;
    lstTmp.DisplayMember = "Name";
    lstAllTable.Items.Clear();
    lstSelectTable.Items.Clear();
    int len = lstTmp.Items.Count;
    for (int i = 0; i < len; i++)
    {

     lstTmp.SelectedIndex = i;
     string txt1 = lstTmp.Text.ToString();

     this.lstAllTable.Items.Add(txt1);
    }

   }           
  }

  private void btnCreate_Click(object sender, EventArgs e)
  {
   IDatabase database = this.cmbDatabase.SelectedValue as IDatabase;
   ArrayList selectTableList = new ArrayList();
   int len = this.lstSelectTable.Items.Count;
   for (int i = 0; i < len; i++)
   {
    lstTmp.SelectedIndex = i;
    string txt1 = lstTmp.Text.ToString();
    selectTableList.Add(txt1);
   }

   this.zeusInput["chooseDatabase"] = database.Name;
   this.zeusInput["chooseTables"] = selectTableList;
   this.zeusInput["outputPath"] = this.txtPath.Text.Trim();
   this.zeusInput["topNamespace"] = this.txtNameSpaceTop.Text.Trim();
   this.zeusInput["bllNamespace"] = this.txtNameSpaceBll.Text.Trim();
   this.zeusInput["dalNamespace"] = this.txtNameSpaceDal.Text.Trim();
   this.zeusInput["helpNamespace"] = this.txtNameSpaceHelp.Text.Trim();
   this.zeusInput["helpClassName"] = this.txtHelpName.Text.Trim();
   
   
   this.DialogResult = DialogResult.OK;
   this.Close();
  }

  //>>
  private void btnRightAll_Click(object sender, EventArgs e)
  {
   //lstSelectTable.Items.Clear();
   int allTableLen = lstAllTable.Items.Count;
   for (int i = 0; i < allTableLen; i++)
   {

     lstAllTable.SelectedIndex=i;
       string txt1= lstAllTable.Text.ToString();
    
       this.lstSelectTable.Items.Add(txt1);
   }
   lstAllTable.Items.Clear();
  
  }

  //>
  private void btnRight_Click(object sender, EventArgs e)
  {
   string txt1 = lstAllTable.Text.ToString();
   if (!String.IsNullOrEmpty(txt1))
   {
    lstAllTable.Items.Remove(txt1);
    this.lstSelectTable.Items.Add(txt1);
   }
  }

  //<
  private void btnLeft_Click(object sender, EventArgs e)
  {
   string txt1 = this.lstSelectTable.Text.ToString();
   if (!String.IsNullOrEmpty(txt1))
   {
    lstSelectTable.Items.Remove(txt1);
    this.lstAllTable.Items.Add(txt1);
   }
  }

  //<<
  private void btnLeftAll_Click(object sender, EventArgs e)
  {
   //lstSelectTable.Items.Clear();
   int len = lstSelectTable.Items.Count;
   for (int i = 0; i < len; i++)
   {

    lstSelectTable.SelectedIndex = i;
    string txt1 = lstSelectTable.Text.ToString();

    this.lstAllTable.Items.Add(txt1);
   }
   lstSelectTable.Items.Clear();
  
  }

  //保存路径
  private void btnSelectPath_Click(object sender, EventArgs e)
  {


   FolderBrowserDialog openPath = new FolderBrowserDialog();
   //openPath.RootFolder = Application.StartupPath;
   if (openPath.ShowDialog() == DialogResult.OK)
   {
    this.txtPath.Text = openPath.SelectedPath;
   }

  }

  //Save init
  private void btnSave_Click(object sender, EventArgs e)
  {
   RegistryKey reg;
   reg = Registry.CurrentUser;
   reg = reg.CreateSubKey("Software");
   reg = reg.CreateSubKey("Wolf");
   reg = reg.CreateSubKey("xiang1");

   reg.SetValue("outputPath", txtPath.Text);
   reg.SetValue("topNamespace", txtNameSpaceTop.Text);
   reg.SetValue("bllNamespace", txtNameSpaceBll.Text);
   reg.SetValue("dalNamespace", txtNameSpaceDal.Text);
   reg.SetValue("helpNamespace", txtNameSpaceHelp.Text);
   reg.SetValue("helpClassName", txtHelpName.Text);

  
  }

  
  private void FrmDialog_DragEnter(object sender, DragEventArgs e)
  {
   if (e.Data.GetDataPresent(DataFormats.FileDrop))
   {
    this.txtPath.Clear();
    e.Effect = DragDropEffects.Link;
   }
   else
   {
    e.Effect = DragDropEffects.None;
   }
  }

  private void FrmDialog_DragDrop(object sender, DragEventArgs e)
  {
   this.txtPath.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
  
  }

 }  /*=========Form End==============*/
}

posted on 2010-09-13 18:21  xrt2004  阅读(374)  评论(0编辑  收藏  举报

导航