Exemplo n.º 1
0
        /// <summary>
        /// 获取DataBaseManager的实例
        /// </summary>
        /// <returns>DataBaseManager的实例</returns>
        public static DataBaseManager GetDataBaseManager()
        {
            if (manager == null) // 对象未初始化
            {
                manager = new DataBaseManager();
            }

            return manager;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取DataBaseManager的实例
        /// </summary>
        /// <returns>DataBaseManager的实例</returns>
        public static DataBaseManager GetDataBaseManager()
        {
            if (manager == null) // 对象未初始化
            {
                manager = new DataBaseManager();
            }

            return(manager);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 编辑文本事件
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件</param>
        private void editText(object sender, EventArgs e)
        {
            ButtonItem buttonItem = sender as ButtonItem;
            TextBox    textBox    = buttonItem.Tag as TextBox;

            System.Data.SqlClient.SqlConnection conn = DataBaseManager.GetDataBaseManager().Connection;
            string result = doit.show(textBox.Text, ref conn, Helper.ClientPath);

            textBox.Text = result;
        }
Exemplo n.º 4
0
        public void Reload()
        {
            if (IsChanged)
            {
                throw (new Exception("文件改变后reload无效"));
            }
            DataBaseManager dbm = DataBaseManager.GetDataBaseManager();
            string          strServerContent = dbm.GetScriptData(this.m_id);

            if (strServerContent != null)
            {
                this.ScriptCode = strServerContent;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            dataBaseManager = DataBaseManager.GetDataBaseManager();
            lsTable         = dataBaseManager.GetLSInformation();
            scriptTable     = dataBaseManager.GetScriptInformation();

            if ((lsTable != null) && (scriptTable != null)) // 数据表非空
            {
                // 添加下拉框内容
                List <string> lsClassification = dataBaseManager.GetLSClassification();
                foreach (string s in lsClassification)
                {
                    comboBoxEx1.Items.Add(s);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            dataBaseManager = DataBaseManager.GetDataBaseManager();
            lsTable = dataBaseManager.GetLSInformation();
            scriptTable = dataBaseManager.GetScriptInformation();

            if((lsTable != null) && (scriptTable != null)) // 数据表非空
            {
                // 添加下拉框内容
                List<string> lsClassification = dataBaseManager.GetLSClassification();
                foreach(string s in lsClassification)
                {
                    comboBoxEx1.Items.Add(s);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void Init()
        {
            DataBaseManager databaseManager = DataBaseManager.GetDataBaseManager();

            if (idList != null)
            {
                Hashtable infoTable = databaseManager.OutputScriptData(idList, false);

                if (infoTable != null)
                {
                    foreach (string key in infoTable.Keys)
                    {
                        string       content  = infoTable[key].ToString();
                        FileListItem listItem = new FileListItem(key, clietFolder, content);
                        listFiles.Items.Add(listItem, true);
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void treeViewQureyResult_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Nodes.Count != 0)
            {
                return;
            }
            string label = e.Node.Tag.ToString();
            string data  = labelTable[label] as string;

            if (data == null)
            {
                data = DataBaseManager.GetDataBaseManager().GetScriptHistoryData(label);
                labelTable[label] = data;
            }

            if (data == null)
            {
                data = "";
            }
            tbxData.Text = data;
        }
Exemplo n.º 9
0
        /// <summary>
        /// 编辑面板关闭
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void frmEdit_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (IsChanged)
            {
                if (MessageBox.Show(string.Format(" 内容已改变是否保存?", m_filename), "保存脚本",
                                    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    // 保存前查错
                    MainForm mainForm = this.MdiParent as MainForm;
                    string   strOut   = mainForm.ScriptCheck(luaEditBox.Text);

                    if (strOut != null)
                    {
                        strOut = strOut.TrimEnd('\n');
                    }

                    if (!string.IsNullOrEmpty(strOut))
                    {
                        MessageBox.Show(string.Format("{0} 脚本中包含错误:\r\n{1}", m_filename, strOut), "脚本检查",
                                        MessageBoxButtons.OK, MessageBoxIcon.Question);
                        TreePhOpera.SetNodeColorByID(mainForm.treePh, this.ID, Color.Red);
                    }
                    else
                    {
                        TreePhOpera.SetNodeColorByID(mainForm.treePh, this.ID, Color.Black);
                    }

                    // 保存
                    DoSave();
                }
                else
                {
                    // 不保存
                    DataBaseManager databaseManager = DataBaseManager.GetDataBaseManager();
                    databaseManager.UnLockScript(this.ID);

                    this.isLocked = false;
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 用户改变选择
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件</param>
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = listBox1.SelectedIndex;

            if (index < 0 || index >= labelList.Count) // 越界
            {
                return;
            }
            string label = labelList[index];
            string data  = labelTable[label] as string;

            if (data == null)
            {
                data = DataBaseManager.GetDataBaseManager().GetScriptHistoryData(label);
                labelTable[label] = data;
            }

            if (data == null)
            {
                data = "";
            }
            textBoxX1.Text = data;
        }
Exemplo n.º 11
0
        /// <summary>
        /// 保存脚本
        /// </summary>
        /// <returns>是否保存成功</returns>
        public bool DoSave()
        {
            bool saveSuccess = false;

            if (IsChanged) // 需要保存
            {
                string scriptName = m_filename;

                if (scriptName.IndexOf('\\') != -1)
                {
                    scriptName = scriptName.Substring(scriptName.LastIndexOf('\\') + 1);
                }

                switch (scriptType)
                {
                case "databaseFile":     // 数据库脚本文件
                {
                    DataBaseManager databaseManager = DataBaseManager.GetDataBaseManager();
                    string          strView         = "";
                    bool            bret            = databaseManager.SaveScriptData(this.FileName, this.NewScriptCode, out strView);

                    if (bret)
                    {
                        if (strView != this.NewScriptCode)
                        {
                            this.ScriptCode = databaseManager.GetBeforeOpen(strView, FileName);
                        }

                        this.ScriptCode = this.NewScriptCode;


                        this.Text = scriptName;
                        databaseManager.UnLockScript(this.ID);
                        bret          = true;
                        this.isLocked = false;
                    }

                    saveSuccess = bret;

                    break;
                }

                case "localFile":     // 本地脚本文件
                {
                    Helper.WriteStringToFile(NewScriptCode, m_filename);
                    this.ScriptCode = this.NewScriptCode;
                    this.Text       = scriptName;
                    saveSuccess     = true;

                    break;
                }

                default:
                {
                    break;
                }
                }
            }

            return(saveSuccess);
        }
Exemplo n.º 12
0
        private void btnReplace_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("替换结果将不直接写入数据库,而且不能恢复,确认继续操作?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
            {
                return;
            }

            SetControlsEnabled(false);
            if (treePreview.Nodes.Count == 0)
            {
                MessageBox.Show("请先搜索出文件,再针对文件进行替换!");
                SetControlsEnabled(true);
                return;
            }

            DataBaseManager dbm = DataBaseManager.GetDataBaseManager();

            //第1步 检查锁
            foreach (TreeNode tn_file in treePreview.Nodes)
            {
                if (!tn_file.Checked)
                {
                    continue;
                }
                Hashtable ht_file = tn_file.Tag as Hashtable;
                string    strID   = ht_file["id"].ToString();
                if (dbm.IsScriptLocked(strID))
                {
                    //文件锁了
                    MessageBox.Show("失败:文件[" + tn_file.Text + "]被正在被人编辑,无法启动替换。");
                    SetControlsEnabled(true);
                    return;
                }
            }

            //第2步 检查在选择过程中,选中项的服务器端数据变过没有
            foreach (TreeNode tn_file in treePreview.Nodes)
            {
                if (!tn_file.Checked)
                {
                    continue;
                }
                Hashtable ht_file        = tn_file.Tag as Hashtable;
                string    strFileContent = ht_file["strFileContent"].ToString();
                string    strID          = ht_file["id"].ToString();
                if (strFileContent != dbm.GetScriptData(strID))
                {
                    //服务器端变过了
                    MessageBox.Show("失败:查找之后,替换之前,文件内容已变更,所以无法替换,请重新启动替换程序!");
                    SetControlsEnabled(true);
                    return;
                }
            }

            //第3步 锁定选择项
            foreach (TreeNode tn_file in treePreview.Nodes)
            {
                if (!tn_file.Checked)
                {
                    continue;
                }
                Hashtable ht_file = tn_file.Tag as Hashtable;
                string    strID   = ht_file["id"].ToString();
                if (!dbm.LockScript(strID))
                {
                    MessageBox.Show("失败:检查一致性的过程中有人锁定了脚本,请迅速保存所有文件后重新运行脚本编辑器再次替换。");
                    SetControlsEnabled(true);
                    return;
                }
            }

            //第4步 替换选择项
            string strResult  = "";
            string strFind    = findTextBox.Text;
            string strReplace = replaceTextBox.Text;

            foreach (TreeNode tn_file in treePreview.Nodes)
            {
                if (!tn_file.Checked)
                {
                    continue;
                }
                Hashtable ht_file    = tn_file.Tag as Hashtable;
                string    strContent = "";
                foreach (TreeNode tnz in tn_file.Nodes)
                {
                    Hashtable ht_nodez = tnz.Tag as Hashtable;
                    strContent += ht_nodez["line_before"].ToString();
                    if (!tnz.Checked)
                    {
                        strContent += strFind;
                    }
                    else
                    {
                        strContent += strReplace;
                    }
                }
                strContent += ht_file["line_last"].ToString();
                string strView = "";
                bool   ret     = dbm.SaveScriptData(tn_file.Text, strContent, out strView);
                strResult += tn_file.Text + (ret ? "...OK\n" : "...NG\n");
            }

            //第5步 解锁选择项
            foreach (TreeNode tn_file in treePreview.Nodes)
            {
                if (!tn_file.Checked)
                {
                    continue;
                }
                Hashtable ht_file = tn_file.Tag as Hashtable;
                string    strID   = ht_file["id"].ToString();
                if (!dbm.UnLockScript(strID))
                {
                    MessageBox.Show(strResult + "成功:替换完成后解锁失败,原因不明,请联系管理员");
                    SetControlsEnabled(true);
                    return;
                }
            }

            MessageBox.Show("替换完成!");//\n" + strResult);
            treePreview.Nodes.Clear();
            wbPriview.DocumentText = "";
            SetControlsEnabled(true);
        }