//接受参数事件
 private void MidModule_EventSend(object sender, object data, object e)
 {
     if (sender != null)
     {
         Model.EventInfo einfo = e as Model.EventInfo;
         if (einfo.Title != "修改字段数据")
         {
             return;
         }
         Form fr = sender as Form;
         if (fr.Text == "对象资源管理器")
         {
             dinfo = data as DbDataInfo;
             DbDataTypeEnum ddt = DbDataType.GetDbDataType(dinfo.NameType);
             if (ddt != DbDataTypeEnum.表)
             {
                 MessageBox.Show("请选择表。");
                 return;
             }
             string msg = "数据库:" + dinfo.DbName;
             if (DbDataType.GetDbDataType(dinfo.NameType).ToString() != "数据库")
             {
                 msg = msg + " " + DbDataType.GetDbDataType(dinfo.NameType).ToString() + ":" + dinfo.Name;
             }
             lb_DbMessage.Text = msg;
             QueryData();
         }
     }
 }
Exemplo n.º 2
0
        private void getdgv_left_Data(string tableName)
        {
            DataBaseInfo   info      = GetDbInfo(dinfo.DbLinkID);
            string         tablename = dinfo.Name;
            TableInfo      table     = null;
            DbDataTypeEnum ddt       = DbDataType.GetDbDataType(dinfo.NameType);

            switch (ddt)
            {
            case DbDataTypeEnum.表:
                table = info.Tables[tablename];
                break;

            case DbDataTypeEnum.视图:
                table = info.View[tablename];
                break;
            }

            if (table == null)
            {
                MessageBox.Show("获取数据失败。");
            }

            dgv_left.DataSource = table.Fields;
            dgv_right.Rows.Clear();
            filedSettingsList = null;
        }
        private void QueryData()
        {
            DataBaseInfo   info      = null; GetDbInfo();
            TableInfo      table     = null;
            string         tablename = dinfo.Name;
            DbDataTypeEnum ddt       = DbDataType.GetDbDataType(dinfo.NameType);

            switch (ddt)
            {
            case DbDataTypeEnum.表:
                info  = GetDbInfo();
                table = info.Tables[tablename];
                break;

            case DbDataTypeEnum.视图:
                info  = GetDbInfo();
                table = info.View[tablename];
                break;
            }
            if (table == null)
            {
                MessageBox.Show("请选择一个表或视图");
                return;
            }
            dataGridView1.DataSource = table.Fields;
        }
Exemplo n.º 4
0
        private DataBaseInfo GetDbInfo(int DbLinkId)
        {
            IDbLink    dal    = new DbLink();
            DbLinkInfo dlinfo = dal.DbLinkGetInfo(DbLinkId);

            IDataBase      dbDal         = new CurrencyDal.CodeMaker.DataBase();
            string         rstmsg        = "";
            string         tableName     = "";
            List <string>  tableNameList = new List <string>();
            DbDataTypeEnum dtype         = DbDataType.GetDbDataType(dinfo.NameType);

            if (dtype == DbDataTypeEnum.表)
            {
                tableName = dinfo.Name;

                //oracle数据库表名大写
                if (dlinfo.DbType == 2)
                {
                    tableName = tableName.ToUpper();
                }

                tableNameList.Add(tableName);
            }
            DataBaseInfo dbinfo = dbDal.DataBaseGetInfo(dlinfo, tableNameList, out rstmsg);

            return(dbinfo);
        }
Exemplo n.º 5
0
        private void tv_Db_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            try
            {
                tv_Db.SelectedNode = e.Node;
                DbDataInfo info = null;
                if (tv_Db.SelectedNode != null)
                {
                    string str1 = tv_Db.SelectedNode.Text;
                    info = tv_Db.SelectedNode.Tag as DbDataInfo;
                }

                //if ((sender as TreeView) != null)
                //{ tv_Db.SelectedNode = tv_Db.GetNodeAt(e.X, e.Y); }

                if (e.Button == MouseButtons.Right && info != null)
                {
                    Point p = PointToScreen(new Point(e.X + 10, e.Y + 35));
                    cms.Items.Clear();
                    DbDataTypeEnum dtype = DbDataType.GetDbDataType(info.NameType);
                    switch (dtype)
                    {
                    case DbDataTypeEnum.务器:
                        break;

                    case DbDataTypeEnum.数据库:
                        GetDbMenu(cms, info);
                        break;

                    case DbDataTypeEnum.表:
                        GetTableMenu(cms, info);
                        break;

                    case DbDataTypeEnum.视图:
                        GetViewMenu(cms, info);
                        break;

                    case DbDataTypeEnum.存储过程:
                        break;
                    }
                    cms.Show(p);
                }

                if (e.Button == MouseButtons.Left && info != null)
                {
                    Model.EventInfo einfo = new Model.EventInfo();
                    einfo.Title = "表单代码生成器";
                    Common.MidModule.SendData(this, info, einfo);//发送参数值
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 6
0
        private void LinkToolScriptBtn_Click(object sender, EventArgs e)
        {
            try
            {
                dal = new DbLink();

                ToolStripButton tbtn  = sender as ToolStripButton;
                string          title = tbtn.Text;

                if (title == "刷新")
                {
                    QueryData();
                    return;
                }

                DbDataInfo dinfo = tv_Db.SelectedNode.Tag as DbDataInfo;
                if (dinfo == null)
                {
                    MessageBox.Show("请选择服务器。");
                    return;
                }
                DbDataTypeEnum ddt = DbDataType.GetDbDataType(dinfo.NameType);
                if (ddt != DbDataTypeEnum.数据库)
                {
                    MessageBox.Show("请选择服务器。");
                    return;
                }
                switch (title)
                {
                case "连接":
                    GetdbData(dinfo);
                    break;

                case "断开":
                    tv_Db.SelectedNode.Nodes.Clear();
                    break;

                case "重连接":
                    GetdbData(dinfo);
                    break;

                case "注销":
                    if (dal.DbLink_Del(dinfo.DbLinkID) == 1)
                    {
                        tv_Db.Nodes.Remove(tv_Db.SelectedNode);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取数据库失败," + ex.Message);
            }
        }
Exemplo n.º 7
0
        private DataBaseInfo GetDbInfo(int ID)
        {
            IDbLink    dal    = new DbLink();
            DbLinkInfo dlinfo = dal.DbLinkGetInfo(ID);

            IDataBase      dbDal         = new  CurrencyDal.CodeMaker.DataBase();
            string         rstmsg        = "";
            List <string>  tableNameList = new List <string>();
            string         tableName     = "";
            DbDataTypeEnum dtype         = DbDataType.GetDbDataType(dinfo.NameType);

            if (dtype == DbDataTypeEnum.表)
            {
                tableName = dinfo.Name;
                tableNameList.Add(tableName);
            }
            DataBaseInfo dbinfo = dbDal.DataBaseGetInfo(dlinfo, tableNameList, out rstmsg);

            //DataBaseInfo2 info = new DataBaseInfo2();

            //try
            //{
            //switch (dlinfo.DbType)
            //{

            //    case 1:
            //        System.Data.Common.DbConnection connSql = new System.Data.SqlClient.SqlConnection();
            //        connSql.ConnectionString = "Data Source=" + dlinfo.DataSource + ";Initial Catalog=" + dlinfo.DbName + ";User ID=" + dlinfo.UserName + ";Password="******"Data Source=" + dlinfo.DbName + ";User ID=" + dlinfo.UserName + ";Password="******"";
            //        info.GetOracleDb(connOracle);
            //        break;
            //    case 3:
            //        string ConnString = dlinfo.DataSource;
            //        info.LoadFromAccess2000(ConnString);
            //        break;

            //}
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("操作失败。" + ex.Message);
            //}

            return(dbinfo);
        }
Exemplo n.º 8
0
        public static DbDataTypeEnum GetDbDataType(int id)
        {
            DbDataTypeEnum ddt = DbDataTypeEnum.务器;

            switch (id)
            {
            case (int)DbDataTypeEnum.务器:
                ddt = DbDataTypeEnum.务器;
                break;

            case (int)DbDataTypeEnum.数据库:
                ddt = DbDataTypeEnum.数据库;
                break;

            case (int)DbDataTypeEnum.表:
                ddt = DbDataTypeEnum.表;
                break;

            case (int)DbDataTypeEnum.视图:
                ddt = DbDataTypeEnum.视图;
                break;

            case (int)DbDataTypeEnum.存储过程:
                ddt = DbDataTypeEnum.存储过程;
                break;

            case (int)DbDataTypeEnum.列:
                ddt = DbDataTypeEnum.列;
                break;

            case (int)DbDataTypeEnum.参数:
                ddt = DbDataTypeEnum.参数;
                break;
            }
            return(ddt);
        }
Exemplo n.º 9
0
        private string GetCodeByXslt(out string rstmsg)
        {
            rstmsg = "";
            string Content = "";

            DataBaseInfo   info      = GetDbInfo(dinfo.DbLinkID);
            string         xml       = null;
            string         tablename = dinfo.Name;
            TableInfo      table     = null;
            DbDataTypeEnum ddt       = DbDataType.GetDbDataType(dinfo.NameType);

            switch (ddt)
            {
            case DbDataTypeEnum.表:
                table = info.Tables[tablename];
                break;

            case DbDataTypeEnum.视图:
                table = info.View[tablename];
                break;
            }

            if (table == null)
            {
                MessageBox.Show("获取数据失败。");
                return(Content);
            }
            try
            {
                #region 生成设置
                if (dgv_right.Rows.Count > 0)
                {
                    if (dgv_right.Rows[0].Cells["rName"].Value != null && dgv_right.Rows.Count != 1)
                    {
                        IList <FieldInfo> olist = table.Fields.GetList();
                        table.Fields.Clear();

                        for (int i = 0; i < dgv_right.Rows.Count; i++)
                        {
                            if (dgv_right.Rows[i].Cells["rName"].Value != null)
                            {
                                string name        = dgv_right.Rows[i].Cells["rName"].Value == null ? "" : dgv_right.Rows[i].Cells["rName"].Value.ToString().Trim();
                                string description = dgv_right.Rows[i].Cells["rDescription"].Value == null ? "" : dgv_right.Rows[i].Cells["rDescription"].Value.ToString().Trim();
                                string PrimaryKey  = dgv_right.Rows[i].Cells["rPrimaryKey"].Value == null ? "" : dgv_right.Rows[i].Cells["rPrimaryKey"].Value.ToString().Trim();
                                string IsIdentity  = dgv_right.Rows[i].Cells["rIsIdentity"].Value == null ? "" : dgv_right.Rows[i].Cells["rIsIdentity"].Value.ToString().Trim();
                                string Nullable    = dgv_right.Rows[i].Cells["rNullable"].Value == null ? "" : dgv_right.Rows[i].Cells["rNullable"].Value.ToString().Trim();
                                string FieldType   = dgv_right.Rows[i].Cells["rFieldType"].Value == null ? "" : dgv_right.Rows[i].Cells["rFieldType"].Value.ToString().Trim();

                                var wlist = olist.Where(t => t.Name == name).ToList();
                                if (wlist.Count > 0)
                                {
                                    var winfo = wlist[0];
                                    winfo.Description = description;
                                    table.Fields.Add(winfo);
                                }
                                else if (name != "")
                                {
                                    FieldInfo nfinfo = new FieldInfo();
                                    nfinfo.Name        = name;
                                    nfinfo.Description = description;
                                    nfinfo.PrimaryKey  = PrimaryKey == "" ? false : Convert.ToBoolean(PrimaryKey);
                                    nfinfo.IsIdentity  = IsIdentity == "" ? false : Convert.ToBoolean(IsIdentity);
                                    nfinfo.Nullable    = Nullable == "" ? false : Convert.ToBoolean(Nullable);
                                    nfinfo.FieldType   = FieldType;

                                    table.Fields.Add(nfinfo);
                                }
                            }
                        }
                    }
                }
                #endregion

                xml = GetXMLString(table);
            }
            catch (Exception ex)
            {
                MessageBox.Show("失败。" + ex.Message);
            }

            IUpLoadFile    ufDal   = new AccessDal.CodeMaker.UpLoadFile();
            UpLoadFileInfo upfInfo = new UpLoadFileInfo();
            upfInfo = ufDal.UpLoadFileGetInfo("Cm_Templet", templetInfo.ID);
            string path = "";
            if (upfInfo != null && upfInfo.FileID != 0)
            {
                path = AppDomain.CurrentDomain.BaseDirectory + upfInfo.FilePath + "\\" + upfInfo.UniqueName;
            }

            //获取模板
            string templet    = Common.FileHandle.ReadFile(path);
            string strtemplet = ReplaceLable(templet);
            string fpath      = AppDomain.CurrentDomain.BaseDirectory + @"CodeMaker\Temp_" + upfInfo.UniqueName;
            //保存临时模板
            Common.FileHandle.WirteCreateFile(strtemplet, fpath);

            try
            {
                // 启动了XSLT模板,执行XSLT转换
                //System.Xml.Xsl.XslTransform transform = new System.Xml.Xsl.XslTransform();
                System.Xml.Xsl.XslCompiledTransform transform = new System.Xml.Xsl.XslCompiledTransform();
                transform.Load(fpath);
                System.IO.StringWriter writer = new System.IO.StringWriter();
                System.Xml.XmlDocument doc    = new System.Xml.XmlDocument();
                doc.LoadXml(xml);
                //transform.Transform(doc, null, writer, null);
                transform.Transform(doc, null, writer);
                writer.Close();
                Content = writer.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("生成失败," + ex.Message);
            }
            //删除临时模板
            Common.FileHandle.DeleteFile(fpath);

            //Content = ReplaceLable(Content);

            Content = Content.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
            Content = Content.Replace("&lt;", "<");
            Content = Content.Replace("&gt;", ">");

            Content = Content.Replace("&amp;", "&");
            return(Content);
        }