public FormImportSapProgram()
        {
            InitializeComponent();
            this.cboxSystemList1.DataSource = ConfigFileTool.SAPGlobalSettings.GetSAPClientList();
            this.cboxSystemList1.Text = ConfigFileTool.SAPGlobalSettings.GetDefaultSapCient();
            Alsing.SourceCode.SyntaxDefinition sl = new Alsing.SourceCode.SyntaxDefinitionLoader().Load("SyntaxFiles\\abap.syn");

            this.cbxDbSources.DataSource = ConfigFileTool.SAPGlobalSettings.GetManagerDbList();
            this.m_dbName = ConfigFileTool.SAPGlobalSettings.GetDefaultCodeManagerDb();
            db = new Codedb(m_dbName);
            this.cbxDbSources.Text = this.m_dbName;
            this.cbxDbSources.SelectedIndexChanged += cbxDbSources_SelectedIndexChanged;

            //this.txtObject.Text = "PROG";

            this.syntaxBoxControl1.Document.Parser.Init(sl);
            this.backgroundWorker1.WorkerReportsProgress = true;
            this.backgroundWorker1.WorkerSupportsCancellation = true;
            this.backgroundWorker1.DoWork += backgroundWorker1_DoWork;
            this.backgroundWorker1.ProgressChanged += backgroundWorker1_ProgressChanged;
            this.backgroundWorker1.RunWorkerCompleted += backgroundWorker1_RunWorkerCompleted;

            // DataTable dt = null;
            dt = new DataTable("TRDIR");
            dt.Columns.AddRange(new DataColumn[]{
            new DataColumn("Index",typeof(int)),
            new DataColumn("Select",typeof(bool)),
            new DataColumn("CodeId",typeof(String)),
            new DataColumn("Header",typeof(String)),
            new DataColumn("Length",typeof(String)),
            new DataColumn("Lines",typeof(String)),
             			new DataColumn("NAME",typeof(String)),// ABAP Program Name
            //new DataColumn("PROG",typeof(String)),// ABAP 程序名
            new DataColumn("CLAS",typeof(String)),// 程序类别
            new DataColumn("SUBC",typeof(String)),//   程序类型
            new DataColumn("APPL",typeof(String)),// 应用程序
            new DataColumn("CDAT",typeof(String)),// 创建日期
            new DataColumn("VERN",typeof(String)),// 版本号
            new DataColumn("RMAND",typeof(String)),// 集团
            new DataColumn("RLOAD",typeof(String)),// 主语言
            new DataColumn("UNAM",typeof(String)),// 最后修改人
            new DataColumn("UDAT",typeof(String)),// 更改日期
            new DataColumn("UTIME",typeof(String)),// 字典: 最后修改时间
            new DataColumn("DATALG",typeof(Int32)),// ABAP/4: 程序组件的长度
            new DataColumn("VARCL",typeof(String)),// 区分大小写
             });
            // dt.Columns["Index"].AutoIncrement = true;
            dt.Columns["Select"].DefaultValue = false;
            this.dataGridView1.DataSource = dt;
            this.dataGridView1.CellDoubleClick += dataGridView1_CellDoubleClick;
            this.dataGridView1.CurrentCellChanged += dataGridView1_CurrentCellChanged;
        }
        public void CodeSaveTest()
        {
            Code code = new Code();
            code.Content = "wfwefwef\r\n";
            code.Version = "210";
            code.Desc = "hello";
            code.VersionList.Add(new CodeVersion() { Content = "xhes", Version = code.Version });
            Codedb codedb = new Codedb();

            codedb.SaveCode(code);

            codedb.SaveVersion(code);

               // code = codedb.getCodebyId(10);
        }
        public FormCodeEditor(String dbName = null)
        {
            InitializeComponent();
            this.cbxDbSources.DataSource = null;
            this.cbxDbSources.DataSource = ConfigFileTool.SAPGlobalSettings.GetManagerDbList();
            this.cbxDbSources.SelectedIndexChanged += cbxDbSources_SelectedIndexChanged;
            if (dbName == null)
            {
                DbName = dbName = ConfigFileTool.SAPGlobalSettings.GetDefaultCodeManagerDb();

            }
            else
            {
                DbName = dbName;
                this.cbxDbSources.Text = DbName;
            }

            db = new Codedb(DbName);

            if (_code == null)
            {
                _code = new Code();
                _code.Title = "新建文档*";
            }

            RefreshDisplay();
            this.txtTreeText.DoubleClick += txtTreeText_DoubleClick;
            DirectoryInfo directory = new DirectoryInfo("SyntaxFiles\\");
            FileInfo[] files = directory.GetFiles();
            this.cbxCategory.DataSource = null;
            this.cbxCategory.Items.Clear();
            foreach (var item in files)
            {
                var newName = item.Name.Replace(".syn", "");
                newName = newName.Replace(".Syn", "");
                this.cbxCategory.Items.Add(newName);
            }
            this.syntaxBoxControl1.Document.Change += Document_Change;
            this.syntaxBoxControl1.Document.ModifiedChanged += Document_ModifiedChanged;
        }
 public void CodeSelectTest()
 {
     Codedb codedb = new Codedb();
      //   Code code = codedb.getCodebyId(10);
 }
        void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return;
            }
            var cell = dataGridView1[e.ColumnIndex, e.RowIndex];
            if (cell != null && cell.Value != null)
            {
                this.syntaxBoxControl1.Document.Text = cell.Value.ToString();

                if (!string.IsNullOrWhiteSpace(cell.Value.ToString()))
                {

                    if (dt.Columns[e.ColumnIndex].ColumnName == "CodeId")
                    {
                        try
                        {
                            Code code = new Codedb().GetCode(cell.Value.ToString());
                            if (code != null)
                            {
                                FormCodeEditor frm = new FormCodeEditor();
                                frm.code = code;
                                frm.Show();
                            }
                        }
                        catch (Exception ee)
                        {

                            MessageBox.Show(ee.Message);
                        }
                    }
                }
            }
        }
        void cbxDbSources_SelectedIndexChanged(object sender, EventArgs e)
        {
            var cbx = sender as ComboBox;
            m_dbName = cbx.Text;

            db = new Codedb(m_dbName);

            //throw new NotImplementedException();
        }
        void cbxDbSources_SelectedIndexChanged(object sender, EventArgs e)
        {
            var cbx = sender as ComboBox;
            m_dbName = cbx.Text;

            db = new Codedb(m_dbName);
            db_changed = true;
            this.TreeId = null;

            if (_code != null)
            {
                _code.Id = null;
                _code.TreeId = null;

            }

            //throw new NotImplementedException();
        }
        void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }
                var cell = dataGridView1[e.ColumnIndex, e.RowIndex];
                var cell2 = dataGridView1["NAME", e.RowIndex];
                if (cell != null && cell.Value != null)
                {
                    this.syntaxBoxControl1.Document.Text = cell.Value.ToString();

                    if (!string.IsNullOrWhiteSpace(cell.Value.ToString()))
                    {

                        if (dt.Columns[e.ColumnIndex].ColumnName == "CodeId")
                        {
                            try
                            {
                                Code code = new Codedb().GetCode(cell.Value.ToString());
                                if (code != null)
                                {
                                    FormCodeEditor frm = new FormCodeEditor();
                                    frm.code = code;
                                    frm.Show();
                                }
                            }
                            catch (Exception ee)
                            {

                                MessageBox.Show(ee.Message);
                            }
                        }
                        else if (dt.Columns[e.ColumnIndex].ColumnName == "NAME")
                        {
                            var x = LoadOneObject(cell.Value.ToString());
                            var arr = x.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                            dataGridView1["Header", e.RowIndex].Value = x;
                            dataGridView1["Lines", e.RowIndex].Value = arr.Count();
                            dataGridView1["Length", e.RowIndex].Value = Util.FileUtil.FormatFileSize(x.Length);
                            this.syntaxBoxControl1.Document.Text = x;
                        }
                    }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }