Пример #1
0
        public void SaveRequest(RequestData rd)
        {
            XmlDocument xmlRequest = new XmlDocument();
            if (File.Exists(_requestPath))
                xmlRequest.Load(_requestPath);
            else
            {
                xmlRequest.LoadXml("<AlgoQuest></AlgoQuest>");
                xmlRequest.Save(_requestPath);
            }
            XmlNodeList nodeList = xmlRequest.SelectNodes(String.Format("//Request[Name='{0}']",rd.Name));
            if (nodeList.Count == 1)
            {
                ((XmlElement)nodeList[0]).GetElementsByTagName("SQL")[0].InnerText = rd.Content;
                ((XmlElement)nodeList[0]).GetElementsByTagName("Comment")[0].InnerText = rd.Comment;
            }
            else
            {
                XmlElement elemRequest = xmlRequest.CreateElement("Request");
                XmlElement elemName = xmlRequest.CreateElement("Name");
                elemName.InnerText = rd.Name;
                XmlElement elemSql = xmlRequest.CreateElement("SQL");
                elemSql.InnerText = rd.Content;
                XmlElement elemComment = xmlRequest.CreateElement("Comment");
                elemComment.InnerText = rd.Comment;

                elemRequest.AppendChild(elemName);
                elemRequest.AppendChild(elemSql);
                elemRequest.AppendChild(elemComment);
                xmlRequest.DocumentElement.AppendChild(elemRequest);
            }
            xmlRequest.Save(_requestPath);
        }
Пример #2
0
        public List<RequestData> GetRequest()
        {
            List<RequestData> requestList = new List<RequestData>(); ;

            XmlDocument xmlRequest = new XmlDocument();
            if (File.Exists(_requestPath))
                xmlRequest.Load(_requestPath);
            else
            {
                try
                {
                    xmlRequest.LoadXml("<AlgoQuest></AlgoQuest>");
                    xmlRequest.Save(_requestPath);
                }
                catch (IOException)
                {
                }
            }

            XmlNodeList xmlRequestList = xmlRequest.SelectNodes("//Request");

            foreach (XmlNode node in xmlRequestList)
            {
                RequestData rd = new RequestData();
                rd.Name = ((XmlElement)node).GetElementsByTagName("Name")[0].InnerText;
                rd.Content = ((XmlElement)node).GetElementsByTagName("SQL")[0].InnerText;
                rd.Comment = ((XmlElement)node).GetElementsByTagName("Comment")[0].InnerText;
                requestList.Add(rd);
            }

            return requestList;
        }
Пример #3
0
 public FrmSaveRequest(RequestData rd, List<RequestData> requestList)
 {
     InitializeComponent();
     _rd = rd;
     _requestList = requestList;
     tbRequestName.Text = _rd.Name;
     tbRequestComment.Text = _rd.Comment;
 }
Пример #4
0
        private void tsbSave_Click(object sender, EventArgs e)
        {
            RequestData rd = new RequestData();
            if (tlcRequest.SelectedItem != null)
                rd = (RequestData)tlcRequest.SelectedItem;

            rd.Content = rtbEditor.Text;

            FrmSaveRequest frmSaveRequest = new FrmSaveRequest(rd, _requestList);
            DialogResult dr = frmSaveRequest.ShowDialog(this);
            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                _requests.SaveRequest(rd);
                populateRequestList();
            }
        }