示例#1
0
        /// <summary>
        ///  控件值给DataLink
        /// </summary>
        /// <param name="dbType"></param>
        /// <param name="dbConn"></param>
        /// <param name="txtHostName"></param>
        /// <param name="txtUserName"></param>
        /// <param name="txtPwd"></param>
        /// <param name="txtPort"></param>
        /// <param name="txtServerName"></param>
        /// <param name="labServerName"></param>
        /// <returns></returns>
        public static DataLink ControlsToData(string dbType, TextBox txtHostName, TextBox txtUserName, TextBox txtPwd,
                                              TextBox txtPort, TextBox txtServerName, Label labServerName, bool isLink = false, TextBox txtLinkName = null)
        {
            var item = new DataLink();

            item.dbType      = dbType;
            item.hostName    = txtHostName.Text.Trim();
            item.userName    = txtUserName.Text.Trim();
            item.userPwd     = txtPwd.Text.Trim();
            item.port        = txtPort.Text.Trim();
            item.serverValue = txtServerName.Text.Trim();
            item.serverName  = labServerName.Content.ToString();

            if (isLink)
            {
                if (txtLinkName.Text.Trim() == "")
                {
                    item.linkName = GetLinkName(AppCache.GetBuildLink());
                }
                else
                {
                    item.linkName = txtLinkName.Text.Trim();
                }
            }

            return(item);
        }
示例#2
0
 /// <summary>
 /// 显示视图结构
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Show_View(object sender, RoutedEventArgs e)
 {
     if (!AppCache.ExistsView(AppCache.GetBuildLink()))
     {
         AppCache.SetViewList(DataSchema.ViewList(AppCache.GetBuildLink()) ?? new List <BaseTable>(), AppCache.GetBuildLink());
     }
     Dtable.DataContext = AppCache.GetViewList(AppCache.GetBuildLink());
 }
示例#3
0
        /// <summary>
        /// 生成CHM
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Bulid_Chm(object sender, RoutedEventArgs e)
        {
            try
            {
                var path = string.Format("{0}chm", AppDomain.CurrentDomain.BaseDirectory);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                if (txtFile != "")
                {
                    path = txtFile;
                }

                //生成list
                var list = new List <ChmModel>();
                foreach (var item in Dtable.Items)
                {
                    var box = Common.GetTemplateColumn <System.Windows.Controls.CheckBox>(Dtable, 0, "tabBox", item);

                    if (box != null && box.IsChecked == true)
                    {
                        var model = new ChmModel();
                        model.tabComments = (item as BaseTable).tabComments;
                        model.tabName     = (item as BaseTable).tabName;
                        model.columns     = DataSchema.ColumnList(AppCache.GetBuildLink(), model.tabName) ?? new List <BaseColumn>();
                        model.columns     = model.disColType(model.columns);

                        list.Add(model);
                    }
                }

                if (list.Count == 0)
                {
                    CodeBox.Show("请选择要生成表", this);
                    return;
                }


                Chm.CreateHhp(path);
                Chm.CreateHhc(path, list);
                Chm.CreateHhk(path, list);
                Chm.Compile(path, list);

                CodeBox.Show("生成成功", this);
            }
            catch (Exception ex)
            {
                CodeBox.Show("生成失败", this);
            }
        }
示例#4
0
        /// <summary>
        /// 编辑表备注
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Dtable_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            var list = AppCache.GetTableList(AppCache.GetBuildLink());
            var item = e.Row.Item as BaseTable;
            var temp = list.Find(a => a.tabName == item.tabName);

            list.Remove(temp);
            list.Add(item);
            AppCache.SetTableList(list, AppCache.GetBuildLink());

            DataSchema.UpdateTabComments(e.Row.Item as BaseTable, AppCache.GetBuildLink());
        }
示例#5
0
        /// <summary>
        /// 加载
        /// </summary>
        public SetLink()
        {
            InitializeComponent();
            Common.InitWindows(this);

            if (Common.GetConfigLink().Count != 0)
            {
                dbTypeLink.ItemsSource = Common.GetConfigLink();
            }

            if (AppCache.GetBuildLink() != null)
            {
                InitLinkInfo();
            }
        }
示例#6
0
        /// <summary>
        /// 显示列结构
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Dtable_Selected(object sender, RoutedEventArgs e)
        {
            var item = (sender as System.Windows.Controls.DataGrid).SelectedItem as BaseTable;

            if (item != null)
            {
                //列checkbox全选为不选择
                var tempCol = Dcolumn.Columns[0] as DataGridTemplateColumn;
                var box     = tempCol.Header as System.Windows.Controls.CheckBox;
                box.IsChecked = false;

                //绑定新列的数据源
                Dcolumn.ItemsSource = DataSchema.ColumnList(AppCache.GetBuildLink(), item.tabName) ?? new List <BaseColumn>();
            }
        }
示例#7
0
        /// <summary>
        /// 编辑列备注
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Dcolumn_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            var table = Dtable.SelectedItem as BaseTable;

            if (table != null)
            {
                var list = DataSchema.ColumnList(AppCache.GetBuildLink(), table.tabName) ?? new List <BaseColumn>();
                var item = e.Row.Item as BaseColumn;

                var temp = list.Find(a => a.colId == item.colId);
                list.Remove(temp);
                list.Add(item);
                AppCache.SetTableColumn(list, DataSchema.GetColumnKey(AppCache.GetBuildLink(), table.tabName));
            }

            DataSchema.UpdateColComments(e.Row.Item as BaseColumn, Dtable.SelectedItem as BaseTable, AppCache.GetBuildLink());
        }
示例#8
0
 /// <summary>
 /// 初始化连接信息
 /// </summary>
 private void InitLinkInfo()
 {
     Common.DataToControls(AppCache.GetBuildLink(), ref txtHostName, ref txtUserName, ref txtPwd, ref txtPort, ref txtServerName, ref labServerName, ref txtLinkName);
     Common.ComboBoxSelect(boxDbType, AppCache.GetBuildLink().dbType);
     Common.ComboBoxSelect(dbTypeLink, AppCache.GetBuildLink().linkName, true);
 }
示例#9
0
        /// <summary>
        /// 生成建表语句
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Bulid_Table(object sender, RoutedEventArgs e)
        {
            var bat  = new StringBuilder();
            var path = string.Format("{0}sql", AppDomain.CurrentDomain.BaseDirectory);

            if (txtFile != "")
            {
                path = txtFile + "\\sql";
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            foreach (var item in Dtable.Items)
            {
                var box = Common.GetTemplateColumn <System.Windows.Controls.CheckBox>(Dtable, 0, "tabBox", item);

                if (box != null && box.IsChecked == true)
                {
                    var sql = new StringBuilder();
                    sql.AppendFormat("create table {0}(\r\n", (item as BaseTable).tabName);
                    var field = DataSchema.ColumnList(AppCache.GetBuildLink(), (item as BaseTable).tabName) ?? new List <BaseColumn>();
                    var i     = 0;
                    field.ForEach(a => {
                        if (AppCache.GetBuildLink().dbType == DataDbType.MySql)
                        {
                            if (a.isNull == "是")
                            {
                                sql.AppendFormat("\t{0} {1}{2} comment {3}\r\n", a.colName, a.showType, i == field.Count - 1 ? "" : ",", a.colComments.Replace("'", ""));
                            }
                            else
                            {
                                sql.AppendFormat("\t{0} {1} not null{2} comment {3}\r\n", a.colName, a.showType, i == field.Count - 1 ? "" : ",", a.colComments.Replace("'", ""));
                            }
                        }
                        else
                        {
                            if (a.isNull == "是")
                            {
                                sql.AppendFormat("\t{0} {1}{2}\r\n", a.colName, a.showType, i == field.Count - 1 ? "" : ",");
                            }
                            else
                            {
                                sql.AppendFormat("\t{0} {1} not null{2}\r\n", a.colName, a.showType, i == field.Count - 1 ? "" : ",");
                            }
                        }
                        i++;
                    });

                    if (AppCache.GetBuildLink().dbType == DataDbType.MySql)
                    {
                        sql.AppendFormat(")comment={0} ", (item as BaseTable).tabComments.Replace("'", ""));
                        bat.AppendFormat("mysql -h {0} -u {1} -p {2} < @{3}.sql\r\n", AppCache.GetBuildLink().hostName, AppCache.GetBuildLink().userName, AppCache.GetBuildLink().userPwd, (item as BaseTable).tabName);
                    }
                    else
                    {
                        sql.Append(") ");
                    }

                    if (AppCache.GetBuildLink().dbType == DataDbType.SqlServer)
                    {
                        field.ForEach(a => {
                            if (a.colComments != "")
                            {
                                sql.AppendFormat("execute sp_addextendedproperty 'MS_Description','{0}','user','dbo','table','{1}','column','{2}';\r\n", a.colComments.Replace("'", ""), (item as BaseTable).tabName, a.colName);
                            }
                        });
                        sql.AppendFormat("execute sp_addextendedproperty 'MS_Description','{0}','user','dbo','table','{1}',null,null;\r\n", (item as BaseTable).tabComments.Replace("'", ""), (item as BaseTable).tabName);

                        bat.AppendFormat("sqlcmd -U {0} -P {1} -i @{2}.sql\r\n", AppCache.GetBuildLink().userName, AppCache.GetBuildLink().userPwd, (item as BaseTable).tabName);
                    }

                    if (AppCache.GetBuildLink().dbType == DataDbType.Oracle)
                    {
                        sql.Append("\r\n tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage(initial 64K minextents 1 maxextents unlimited);\r\n");

                        field.ForEach(a => {
                            if (a.colComments != "")
                            {
                                sql.AppendFormat("comment on column {0}.{1} is '{2}'; \r\n", (item as BaseTable).tabName, a.colName, a.colComments.Replace("'", ""));
                            }
                        });
                        sql.AppendFormat("comment on table {0} is '{1}';\r\n", (item as BaseTable).tabName, (item as BaseTable).tabComments.Replace("'", ""));

                        bat.AppendFormat("sqlplus {0}/{1}@{2} @{3}.sql> CreateTable.log\r\n", AppCache.GetBuildLink().userName, AppCache.GetBuildLink().userPwd, AppCache.GetBuildLink().serverValue, (item as BaseTable).tabName);
                    }

                    File.WriteAllText(string.Format("{0}/{1}.sql", path, (item as BaseTable).tabName), sql.ToString(), Encoding.UTF8);
                }
            }

            bat.Append("exit;");

            if (AppCache.GetBuildLink().dbType == DataDbType.Oracle)
            {
                File.WriteAllText(string.Format("{0}/Oracle.bat", path), bat.ToString(), Encoding.UTF8);
            }

            if (AppCache.GetBuildLink().dbType == DataDbType.MySql)
            {
                File.WriteAllText(string.Format("{0}/MySql.bat", path), bat.ToString(), Encoding.UTF8);
            }

            if (AppCache.GetBuildLink().dbType == DataDbType.SqlServer)
            {
                File.WriteAllText(string.Format("{0}/SqlServer.bat", path), bat.ToString(), Encoding.UTF8);
            }

            CodeBox.Show("生成成功", this);
        }
示例#10
0
        /// <summary>
        /// 生成实体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Build_Model(object sender, RoutedEventArgs e)
        {
            var list = new List <EntityInfo>();

            //生成list
            foreach (var item in Dtable.Items)
            {
                var box = Common.GetTemplateColumn <System.Windows.Controls.CheckBox>(Dtable, 0, "tabBox", item);

                if (box != null && box.IsChecked == true)
                {
                    var entiy = new EntityInfo();
                    entiy.table       = item as BaseTable;
                    entiy.language    = language.SelectionBoxItem.ToString();
                    entiy.columns     = DataSchema.ColumnList(AppCache.GetBuildLink(), entiy.table.tabName) ?? new List <BaseColumn>();
                    entiy.columns     = entiy.disColType(entiy.columns, entiy.language);
                    entiy.isSerialize = (bool)isSerialize.IsChecked;
                    entiy.isCheck     = (bool)isCheck.IsChecked;
                    entiy.isMap       = (bool)isMap.IsChecked;
                    entiy.isModel     = (bool)isModel.IsChecked;
                    entiy.isOldModel  = (bool)isOldModel.IsChecked;

                    if (DataDbType.Oracle == AppCache.GetBuildLink().dbType)
                    {
                        entiy.param = ":";
                    }

                    if (DataDbType.MySql == AppCache.GetBuildLink().dbType)
                    {
                        entiy.param = "?";
                    }

                    if (DataDbType.SqlServer == AppCache.GetBuildLink().dbType)
                    {
                        entiy.param = "@";
                    }

                    if (!entiy.isCheck && !entiy.isSerialize && !entiy.isMap && !entiy.isModel && !entiy.isOldModel)
                    {
                        CodeBox.Show("请选择模板", this);
                        return;
                    }

                    list.Add(entiy);
                }
            }

            if (list.Count == 0)
            {
                CodeBox.Show("请选择要生成表", this);
                return;
            }

            //执行生成实体
            list.ForEach(a => {
                //命名空间
                a.nameSpace = txtNameSpace.Text.Trim();

                //生成路径
                if (txtFile != "")
                {
                    a.modelFile = txtFile;
                }

                //语言
                a.language = language.SelectionBoxItem.ToString();

                if (a.isMap)
                {
                    Common.BuildCodeModel(a, "xml");
                }

                else
                {
                    Common.BuildCodeModel(a);
                }
            });

            CodeBox.Show(string.Format("生成完成"), this);
        }
示例#11
0
 /// <summary>
 /// 更新视图结构
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ReLoad_View(object sender, RoutedEventArgs e)
 {
     AppCache.SetViewList(DataSchema.ViewList(AppCache.GetBuildLink(), true) ?? new List <BaseTable>(), AppCache.GetBuildLink());
     Dtable.DataContext = AppCache.GetViewList(AppCache.GetBuildLink());
 }