Exemplo n.º 1
0
 private void SaveXML(string FileName, DataGridView GridView)
 {
     LRSecurity lrSecurity = new LRSecurity();
     try
     {
         if (File.Exists(FileName))
         {
             File.Delete(FileName);
         }
         if (GridView.Rows.Count == 0) return;
         StreamWriter fs;
         fs = new StreamWriter(FileName, true, Encoding.UTF8);
         fs.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
         fs.WriteLine("<root>");
         fs.WriteLine("</root>");
         fs.Flush();
         fs.Close();
         XMLReadWrite xml = new XMLReadWrite();
         string sRow = "", sCol = "", sValue = "";
         for (int i = 0; i < GridView.Rows.Count; i++)
         {
             sRow = "Row" + i.ToString();
             for (int j = 0; j < GridView.Columns.Count - 1; j++)
             {
                 sCol = "Columns" + j.ToString();
                 if (j == 3)
                 {
                     sValue = lrSecurity.DESEncrypt(GridView.Rows[i].Cells[j].Value.ToString());
                 }
                 else
                 {
                     if (GridView.Rows[i].Cells[j].Value != null)
                         sValue = GridView.Rows[i].Cells[j].Value.ToString();
                     else
                         sValue = GridView.Rows[i].Cells[j].EditedFormattedValue.ToString();
                 }
                 xml.WriteXML(FileName, sRow, sCol, sValue);
             }
         }
     }
     catch (Exception g)
     { throw g; }
 }
Exemplo n.º 2
0
 //得到要更新的AP信息
 private void GetInfo(DataGridView GridView, string FileName)
 {
     LRSecurity lrSecurity = new LRSecurity();
     try
     {
         GridView.Rows.Clear();
         GridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
         GridView.ColumnHeadersDefaultCellStyle.BackColor = Color.CadetBlue;
         GridView.RowsDefaultCellStyle.BackColor = Color.Bisque;
         GridView.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;
         if (!File.Exists(FileName))
         {
             return;
         }
         XmlDocument xmlDoc = new XmlDocument();
         xmlDoc.Load(FileName);
         XmlNodeList nodeList = xmlDoc.SelectSingleNode("root").ChildNodes;
         int i = 0, j = 0;
         foreach (XmlNode _xn in nodeList)
         {
             GridView.Rows.Add();
             XmlNodeList lnodeList = _xn.ChildNodes;
             j = 0;
             foreach (XmlNode _lxn in lnodeList)
             {
                 XmlElement _xe = (XmlElement)_lxn;
                 if (j == 3)
                 {
                     //密碼
                     GridView.Rows[i].Cells[j].Value = lrSecurity.DESDecrypt(_xe.InnerText);
                 }
                 else
                 {
                     GridView.Rows[i].Cells[j].Value = _xe.InnerText;
                 }
                 j = j + 1;
                 //if (j == 4 && Type=="1") break;
             }
             i = i + 1;
         }
     }
     catch (Exception g)
     {
         throw g;
     }
 }