Beispiel #1
0
 private void simpleButton4_Click(object sender, EventArgs e)
 {
     if (gridView1.FocusedRowHandle > -1)
     {
         FrmAddOrEdit frm = new FrmAddOrEdit(gridView1.GetFocusedRowCellValue("Name").ToString(),
                                             gridView1.GetFocusedRowCellValue("IP").ToString(),
                                             gridView1.GetFocusedRowCellValue("Submask").ToString(),
                                             gridView1.GetFocusedRowCellValue("Getway").ToString(),
                                             gridView1.GetFocusedRowCellValue("DNS").ToString(),
                                             gridView1.GetFocusedRowCellValue("Remark").ToString());
         if (frm.ShowDialog() == DialogResult.OK)
         {
             if (File.Exists(ipfile))
             {
                 DataSet ds = new DataSet();
                 ds.ReadXml(ipfile, XmlReadMode.ReadSchema);
                 for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                 {
                     if (ds.Tables[0].Rows[i]["Id"].ToString() == gridView1.GetFocusedRowCellValue("Id").ToString())
                     {
                         ds.Tables[0].Rows[i]["Name"]    = frm.sName;
                         ds.Tables[0].Rows[i]["IP"]      = frm.sIp;
                         ds.Tables[0].Rows[i]["Getway"]  = frm.sGetway;
                         ds.Tables[0].Rows[i]["Submask"] = frm.sSubmmask;
                         ds.Tables[0].Rows[i]["DNS"]     = frm.sDns;
                         ds.Tables[0].Rows[i]["Remark"]  = frm.sRemark;
                         ds.WriteXml(ipfile, XmlWriteMode.WriteSchema);
                         LoadData();
                         break;
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            FrmAddOrEdit frm = new FrmAddOrEdit();

            if (frm.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(ipfile))
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(ipfile, XmlReadMode.ReadSchema);
                    DataRow row = ds.Tables[0].NewRow();
                    row["Id"]      = Guid.NewGuid().ToString();
                    row["Name"]    = frm.sName;
                    row["IP"]      = frm.sIp;
                    row["Getway"]  = frm.sGetway;
                    row["Submask"] = frm.sSubmmask;
                    row["DNS"]     = frm.sDns;
                    row["Remark"]  = frm.sRemark;
                    ds.Tables[0].Rows.Add(row);
                    ds.WriteXml(ipfile, XmlWriteMode.WriteSchema);
                    LoadData();
                }
                else
                {
                    DataSet   ds    = new DataSet();
                    DataTable table = new DataTable();
                    table.Columns.Add("Id");
                    table.Columns.Add("Name");
                    table.Columns.Add("IP");
                    table.Columns.Add("Getway");
                    table.Columns.Add("Submask");
                    table.Columns.Add("DNS");
                    table.Columns.Add("Remark");

                    DataRow row = table.NewRow();
                    row["Id"]      = Guid.NewGuid().ToString();
                    row["Name"]    = frm.sName;
                    row["IP"]      = frm.sIp;
                    row["Getway"]  = frm.sGetway;
                    row["Submask"] = frm.sSubmmask;
                    row["DNS"]     = frm.sDns;
                    row["Remark"]  = frm.sRemark;
                    table.Rows.Add(row);
                    ds.Tables.Add(table);
                    ds.WriteXml(ipfile, XmlWriteMode.WriteSchema);
                    LoadData();
                }
            }
        }