예제 #1
0
        private void Run()
        {
            StatusLabel1.Text = "正在生成...";
            //Hashtable keys = GetKeyFields();
            //ArrayList fieldlist=GetFieldlist();
            string tempxslt = @"Template\temp.xslt"; //临时xslt文件

            try
            {
                string      strContent = txtTemplate.Text;
                XmlDocument xdoc       = new XmlDocument();
                xdoc.LoadXml(strContent);
                xdoc.Save(@"Template\temp.xslt");
            }
            catch (System.Exception ex)
            {
                StatusLabel1.Text = "模版格式有误:" + ex.Message;
                return;
            }

            string strcode = "";

            try
            {
                BuilderTemp bt = new BuilderTemp(dbobj, dbname, tablename, GetFieldlist(), GetKeyFields(), tempxslt);
                strcode = bt.GetCode();
            }
            catch (System.Exception ex)
            {
                StatusLabel1.Text = "代码转换失败!" + ex.Message;
                return;
            }
            string       filename = @"Template\tempcode.cs";
            StreamWriter sw       = new StreamWriter(filename, false, Encoding.Default);//,false);

            sw.Write(strcode);
            sw.Flush();
            sw.Close();
            StatusLabel1.Text = "生成成功。";
            mainfrm.AddSinglePage(new CodeEditor(filename, "cs"), "Class1.cs");
        }
예제 #2
0
        public void Run()
        {
            StatusLabel1.Text = "正在生成...";
            //Hashtable keys = GetKeyFields();
            //ArrayList fieldlist = GetFieldlist();
            string tempxslt = @"Template\temp.xslt"; //临时xslt文件

            try
            {
                string strContent = txtTemplate.Text;
                if (strContent.Trim() == "")
                {
                    MessageBox.Show("模版内容为空,请先在模版管理器里选择模版!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    StatusLabel1.Text = "就绪";
                    return;
                }
                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml(strContent);
                xdoc.Save(tempxslt);
            }
            catch (System.Exception ex)
            {
                StatusLabel1.Text = "模版格式有误:" + ex.Message;
                return;
            }

            string strcode = "";

            try
            {
                BuilderTemp bt = new BuilderTemp(dbobj, dbname, tablename, GetFieldlist(), GetKeyFields(), tempxslt);
                strcode = bt.GetCode();

                //删除临时文件
                if (File.Exists(tempxslt))
                {
                    File.Delete(tempxslt);
                }
                string xmlDoc = @"Template\temp.xml"; //临时数据文件temp.xml
                if (File.Exists(xmlDoc))
                {
                    File.Delete(xmlDoc);
                }
            }
            catch (System.Exception ex)
            {
                StatusLabel1.Text = "代码转换失败!" + ex.Message;
                return;
            }
            txtCode.Text = strcode;
            this.tabControl1.SelectedIndex = 1;

            //string filename = @"Template\tempcode.cs";
            //StreamWriter sw = new StreamWriter(filename, false, Encoding.Default);//,false);
            //sw.Write(strcode);
            //sw.Flush();
            //sw.Close();

            StatusLabel1.Text = "生成成功。";
            //mainfrm.AddSinglePage(new CodeEditor(filename), "Class1.cs");
        }
예제 #3
0
 private void ThreadWork()
 {
     try
     {
         this.SetBtnDisable();
         int count  = this.listTable2.Items.Count;
         int count2 = this.listBoxTemplate.Items.Count;
         this.SetlblStatuText("0");
         this.dbset.Folder = this.txtFolder.Text.Trim();
         DataTable tablesExProperty = this.dbobj.GetTablesExProperty(this.dbname);
         CodeInfo  codeInfo         = null;
         bool      flag             = false;
         if (this.radbtn_TempMerger.Checked)
         {
             this.SetprogressBar1Max(count2);
             this.SetprogressBar1Val(1);
             for (int i = 0; i < count2; i++)
             {
                 string text  = this.listBoxTemplate.Items[i].ToString();
                 string text2 = this.TemplateFolder + "\\" + text;
                 if (File.Exists(text2))
                 {
                     StringBuilder stringBuilder = new StringBuilder();
                     string        objectype     = this.isProc ? "proc" : "table";
                     for (int j = 0; j < count; j++)
                     {
                         string text3            = this.listTable2.Items[j].ToString();
                         string tableDescription = text3;
                         if (tablesExProperty != null)
                         {
                             try
                             {
                                 DataRow[] array = tablesExProperty.Select("objname='" + text3 + "'");
                                 if (array.Length > 0 && array[0]["value"] != null)
                                 {
                                     tableDescription = array[0]["value"].ToString();
                                 }
                             }
                             catch
                             {
                             }
                         }
                         List <ColumnInfo> fieldlist;
                         if (this.isProc)
                         {
                             fieldlist = this.dbobj.GetColumnList(this.dbname, text3);
                         }
                         else
                         {
                             fieldlist = this.dbobj.GetColumnInfoList(this.dbname, text3);
                         }
                         List <ColumnInfo> keyList  = this.dbobj.GetKeyList(this.dbname, text3);
                         List <ColumnInfo> fKeyList = this.dbobj.GetFKeyList(this.dbname, text3);
                         try
                         {
                             codeInfo = new CodeInfo();
                             BuilderTemp builderTemp = new BuilderTemp(this.dbobj, this.dbname, text3, tableDescription, fieldlist, keyList, fKeyList, text2, this.dbset, objectype);
                             codeInfo = builderTemp.GetCode();
                             if (codeInfo.ErrorMsg != null && codeInfo.ErrorMsg.Length > 0)
                             {
                                 flag = true;
                                 if (codeInfo.ErrorMsg.IndexOf("无法将类型为“Maticsoft.CodeEngine.TableHost”的对象强制转换为类型“Maticsoft.CodeEngine.ProcedureHost”") > 0)
                                 {
                                     stringBuilder.AppendLine(codeInfo.Code + Environment.NewLine + "/*代码生成时出现错误: 无法将表和视图与存储过程的模板进行匹配,请选择正确的模板!*/");
                                 }
                                 else
                                 {
                                     if (codeInfo.ErrorMsg.IndexOf("无法将类型为“Maticsoft.CodeEngine.ProcedureHost”的对象强制转换为类型“Maticsoft.CodeEngine.TableHost”") > 0)
                                     {
                                         stringBuilder.AppendLine(codeInfo.Code + Environment.NewLine + "/*代码生成时出现错误: 无法将存储过程与表和视图的模板进行匹配,请选择正确的模板!*/");
                                     }
                                     else
                                     {
                                         stringBuilder.AppendLine(string.Concat(new string[]
                                         {
                                             codeInfo.Code,
                                             Environment.NewLine,
                                             "/*------ 代码生成时出现错误: ------",
                                             Environment.NewLine,
                                             codeInfo.ErrorMsg,
                                             "*/"
                                         }));
                                     }
                                 }
                             }
                             else
                             {
                                 stringBuilder.AppendLine(codeInfo.Code);
                             }
                         }
                         catch (Exception ex)
                         {
                             flag = true;
                             stringBuilder.AppendLine(ex.Message);
                         }
                     }
                     this.SetprogressBar1Val(i + 1);
                     this.SetlblStatuText((i + 1).ToString());
                     string path = Path.Combine(this.txtTargetFolder.Text, text.ToString());
                     string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
                     string text4 = this.txtTargetFolder.Text;
                     if (!Directory.Exists(text4))
                     {
                         Directory.CreateDirectory(text4);
                     }
                     if (this.isProc)
                     {
                         string path2 = Path.Combine(text4, this.dbname + codeInfo.FileExtension);
                         File.AppendAllText(path2, stringBuilder.ToString(), Encoding.UTF8);
                     }
                     else
                     {
                         string path3 = Path.Combine(text4, fileNameWithoutExtension + codeInfo.FileExtension);
                         File.WriteAllText(path3, stringBuilder.ToString(), Encoding.UTF8);
                     }
                 }
             }
         }
         else
         {
             this.SetprogressBar1Max(count);
             this.SetprogressBar1Val(1);
             for (int k = 0; k < count; k++)
             {
                 string text5             = this.listTable2.Items[k].ToString();
                 string tableDescription2 = text5;
                 if (tablesExProperty != null)
                 {
                     try
                     {
                         DataRow[] array2 = tablesExProperty.Select("objname='" + text5 + "'");
                         if (array2.Length > 0 && array2[0]["value"] != null)
                         {
                             tableDescription2 = array2[0]["value"].ToString();
                         }
                     }
                     catch
                     {
                     }
                 }
                 List <ColumnInfo> fieldlist2;
                 if (this.isProc)
                 {
                     fieldlist2 = this.dbobj.GetColumnList(this.dbname, text5);
                 }
                 else
                 {
                     fieldlist2 = this.dbobj.GetColumnInfoList(this.dbname, text5);
                 }
                 List <ColumnInfo> keyList2  = this.dbobj.GetKeyList(this.dbname, text5);
                 List <ColumnInfo> fKeyList2 = this.dbobj.GetFKeyList(this.dbname, text5);
                 foreach (object current in this.listBoxTemplate.Items)
                 {
                     string text6 = this.TemplateFolder + "\\" + current.ToString();
                     if (File.Exists(text6))
                     {
                         string text7      = "";
                         string objectype2 = this.isProc ? "proc" : "table";
                         try
                         {
                             codeInfo = new CodeInfo();
                             BuilderTemp builderTemp2 = new BuilderTemp(this.dbobj, this.dbname, text5, tableDescription2, fieldlist2, keyList2, fKeyList2, text6, this.dbset, objectype2);
                             codeInfo = builderTemp2.GetCode();
                             if (codeInfo.ErrorMsg != null && codeInfo.ErrorMsg.Length > 0)
                             {
                                 flag = true;
                                 if (codeInfo.ErrorMsg.IndexOf("无法将类型为“Maticsoft.CodeEngine.TableHost”的对象强制转换为类型“Maticsoft.CodeEngine.ProcedureHost”") > 0)
                                 {
                                     text7 = codeInfo.Code + Environment.NewLine + "/*代码生成时出现错误: 无法将表和视图与存储过程的模板进行匹配,请选择正确的模板!*/";
                                 }
                                 else
                                 {
                                     if (codeInfo.ErrorMsg.IndexOf("无法将类型为“Maticsoft.CodeEngine.ProcedureHost”的对象强制转换为类型“Maticsoft.CodeEngine.TableHost”") > 0)
                                     {
                                         text7 = codeInfo.Code + Environment.NewLine + "/*代码生成时出现错误: 无法将存储过程与表和视图的模板进行匹配,请选择正确的模板!*/";
                                     }
                                     else
                                     {
                                         text7 = string.Concat(new string[]
                                         {
                                             codeInfo.Code,
                                             Environment.NewLine,
                                             "/*------ 代码生成时出现错误: ------",
                                             Environment.NewLine,
                                             codeInfo.ErrorMsg,
                                             "*/"
                                         });
                                     }
                                 }
                             }
                             else
                             {
                                 text7 = codeInfo.Code;
                             }
                         }
                         catch (Exception ex2)
                         {
                             flag   = true;
                             text7 += ex2.Message;
                         }
                         string path4 = Path.Combine(this.txtTargetFolder.Text, current.ToString());
                         string fileNameWithoutExtension2 = Path.GetFileNameWithoutExtension(path4);
                         string text8 = Path.Combine(Path.GetDirectoryName(path4), fileNameWithoutExtension2);
                         if (!Directory.Exists(text8))
                         {
                             Directory.CreateDirectory(text8);
                         }
                         if (this.isProc)
                         {
                             string path5 = Path.Combine(text8, this.dbname + codeInfo.FileExtension);
                             File.AppendAllText(path5, text7, Encoding.UTF8);
                         }
                         else
                         {
                             string path6 = Path.Combine(text8, text5 + codeInfo.FileExtension);
                             File.WriteAllText(path6, text7, Encoding.UTF8);
                         }
                     }
                 }
                 this.SetprogressBar1Val(k + 1);
                 this.SetlblStatuText((k + 1).ToString());
             }
         }
         this.SetBtnEnable();
         if (flag)
         {
             MessageBox.Show(this, "代码生成完成,但有错误,请查看生成代码!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else
         {
             MessageBox.Show(this, "代码生成成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
     }
     catch (Exception ex3)
     {
         LogInfo.WriteLog(ex3);
         MessageBox.Show(ex3.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
     }
 }
예제 #4
0
        public void Run()
        {
            this.StatusLabel1.Text = "正在生成...";
            try
            {
                string text = this.txtTemplate.Text;
                if (text.Trim() == "")
                {
                    MessageBox.Show("模版内容为空,请先在模版管理器里选择模版!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.StatusLabel1.ForeColor = System.Drawing.Color.Black;
                    this.StatusLabel1.Text      = "就绪";
                    return;
                }
                if (this.Templatefilename == null || this.Templatefilename.Length == 0)
                {
                    this.Templatefilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template\\TemplateFile\\temp~.cmt");
                }
                File.WriteAllText(this.Templatefilename, text, Encoding.UTF8);
            }
            catch (Exception ex)
            {
                this.StatusLabel1.ForeColor = System.Drawing.Color.Red;
                this.StatusLabel1.Text      = "模版格式有误:" + ex.Message;
                return;
            }
            string   strContent = "";
            CodeInfo codeInfo   = new CodeInfo();

            try
            {
                BuilderTemp builderTemp = new BuilderTemp(this.dbobj, this.dbname, this.tablename, this.tableDescription, this.GetFieldlist(), this.GetKeyFields(), this.GetFKeyFields(), this.Templatefilename, this.dbset, this.objtype);
                codeInfo = builderTemp.GetCode();
                if (codeInfo.ErrorMsg != null && codeInfo.ErrorMsg.Length > 0)
                {
                    strContent = string.Concat(new string[]
                    {
                        codeInfo.Code,
                        Environment.NewLine,
                        "/*------ 代码生成时出现错误: ------",
                        Environment.NewLine,
                        codeInfo.ErrorMsg,
                        "*/"
                    });
                }
                else
                {
                    strContent = codeInfo.Code;
                }
            }
            catch (Exception ex2)
            {
                this.StatusLabel1.ForeColor = System.Drawing.Color.Red;
                this.StatusLabel1.Text      = "代码转换失败!" + ex2.Message;
                return;
            }
            this.SettxtContent(codeInfo.FileExtension.Replace(".", ""), strContent);
            this.tabControl1.SelectedIndex = 1;
            if (codeInfo.ErrorMsg != null && codeInfo.ErrorMsg.Length > 0)
            {
                this.StatusLabel1.ForeColor = System.Drawing.Color.Red;
                this.StatusLabel1.Text      = "代码生成失败!";
                return;
            }
            this.StatusLabel1.ForeColor = System.Drawing.Color.Green;
            this.StatusLabel1.Text      = "代码生成成功。";
        }