Пример #1
0
        // 从文件中装载创建一个TemplateCollection对象
        // parameters:
        //		bIgnorFileNotFound	是否不抛出FileNotFoundException异常。
        //							如果==true,函数直接返回一个新的空TemplateCollection对象
        // Exception:
        //			FileNotFoundException	文件没找到
        //			SerializationException	版本迁移时容易出现
        public static TemplateCollection Load(
            string strFileName,
            bool bIgnorFileNotFound)
        {
            Stream             stream    = null;
            TemplateCollection templates = null;

            try
            {
                stream = File.Open(strFileName, FileMode.Open);
            }
            catch (FileNotFoundException ex)
            {
                if (bIgnorFileNotFound == false)
                {
                    throw ex;
                }

                templates = new TemplateCollection();
                // templates.m_strFileName = strFileName;

                // 让调主有一个新的空对象可用
                return(templates);
            }


            BinaryFormatter formatter = new BinaryFormatter();

            templates = (TemplateCollection)formatter.Deserialize(stream);
            stream.Close();
            // templates.m_strFileName = strFileName;


            return(templates);
        }
Пример #2
0
        void FillList()
        {
            this.listView_objects.Items.Clear();


            if (this.FileName == "")
            {
                return;
            }

            try
            {
                templates = TemplateCollection.Load(this.FileName, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ExceptionUtil.GetAutoText(ex));
                return;
            }

            for (int i = 0; i < templates.Count; i++)
            {
                Template t = templates[i];

                ListViewItem item = new ListViewItem(t.Object.Name, t.Object.Type);
                item.Tag = t;

                item.SubItems.Add(this.Url);

                this.listView_objects.Items.Add(item);
            }
        }
Пример #3
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            if (this.textBox_exportFileName.Text == "")
            {
                MessageBox.Show(this, "尚未指定输出文件名");
                return;
            }

            string             strError  = "";
            TemplateCollection templates = null;

            this.Cursor = Cursors.WaitCursor;
            int nRet = BuildTemplates(out templates,
                                      out strError);

            this.Cursor = Cursors.Arrow;
            if (nRet == -1)
            {
                goto ERROR1;
            }

            try
            {
                templates.Save(this.textBox_exportFileName.Text);
            }
            catch (Exception ex)
            {
                strError = ExceptionUtil.GetAutoText(ex);
                goto ERROR1;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
Пример #4
0
        int BuildTemplates(out TemplateCollection templates,
                           out string strError)
        {
            strError = "";

            templates = new TemplateCollection();

            for (int i = 0; i < this.listView_objects.Items.Count; i++)
            {
                ListViewItem item = this.listView_objects.Items[i];
                if (item.Checked == false)
                {
                    continue;
                }

                if (item.ImageIndex == ResTree.RESTYPE_FOLDER ||
                    item.ImageIndex == ResTree.RESTYPE_FILE)
                {
                    continue;
                }

                string strDbName = item.Text;
                string strUrl    = item.SubItems[1].Text;

                DatabaseObjectTree tree = new DatabaseObjectTree();
                tree.Initial(MainForm.Servers,
                             MainForm.Channels,
                             MainForm.stopManager,
                             strUrl,
                             strDbName);
                //

                RmsChannel channel = MainForm.Channels.GetChannel(strUrl);
                if (channel == null)
                {
                    goto ERROR1;
                }
                List <string[]> logicNames = null;
                string          strType;
                string          strSqlDbName;
                string          strKeysDef;
                string          strBrowseDef;

                long nRet = channel.DoGetDBInfo(
                    strDbName,
                    "all",
                    out logicNames,
                    out strType,
                    out strSqlDbName,
                    out strKeysDef,
                    out strBrowseDef,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                Template template = new Template();
                template.LogicNames = logicNames;
                template.Type       = strType;
                template.SqlDbName  = strSqlDbName;
                template.KeysDef    = strKeysDef;
                template.BrowseDef  = strBrowseDef;

                template.Object = tree.Root;

                templates.Add(template);
            }

            return(0);

ERROR1:
            return(-1);
        }