demo code

using System.Reflection; // 引用这个才能使用Missing字段

namespace hello
{
    public partial class Form1 : Form
    {
        Form_SelectData formSelect = null;
        public Form1()
        {        
            InitializeComponent();  
        }

public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
      //  public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
        private bool bIsConnected = false;//the boolean value identifies whether the device is connected
        private int iMachineNumber = 1;
        public XmlDocument xmldoc;
        public XmlNode xmlnode;
        public XmlElement xmlelem;
        public static string path = System.AppDomain.CurrentDomain.BaseDirectory;
        public string xmlfiles = "";
        public static string[] ary = new string[2] {"a","b"};

// public static string[] names = new string[3] { "Matt", "Joanne", "Robert" };

private void m(string s, string s1="")
          {
            if (s1=="")
            {
                MessageBox.Show(s);
            } else
            {
                MessageBox.Show(s + "\n" + s1);
            }

}

private Boolean updatexmlGB(string Module, string aname, string atitle)
        {
            Boolean rs = false;
            xmlfiles = path + Module + ".xml";

try
            {
                if (File.Exists(xmlfiles) == true)
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(xmlfiles);

XmlNodeList nodeList = xmlDoc.SelectSingleNode("List").ChildNodes;//获取Employees节点的所有子节点 
                    foreach (XmlNode xn in nodeList)//遍历所有子节点 
                    {
                        try
                        {
                            XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型
                            if (xe.Name.ToString() == aname)
                            {
                                string dt = DateTime.Now.ToString();
                                // MessageBox.Show(xe.ChildNodes[0].InnerText);
                                xe.ChildNodes[0].InnerText = atitle;// "亚胜 " + dt;//则修改
                            };
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }

}
                    xmlDoc.Save(xmlfiles);//保存。
                    //Isok = true; 
                    rs = true;
                    // MessageBox.Show("update ok");
                }
                else
                {
                    MessageBox.Show("no files");
                };
            }
            catch
            {

};
            return rs;
        }

private string readxmlGB(string Module, string aname)
        {
            string rs = "";
            xmlfiles = path + Module + ".xml";

try
            {
                if (File.Exists(xmlfiles) == true)
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(xmlfiles);

XmlNodeList nodeList = xmlDoc.SelectSingleNode("List").ChildNodes;//获取Employees节点的所有子节点 
                    foreach (XmlNode xn in nodeList)//遍历所有子节点 
                    {
                        try
                        {
                            XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型

if (xe.Name.ToString() == aname)
                            {
                                //MessageBox.Show(xe.Name + "\n" + xe.ChildNodes[0].InnerText);
                                // MessageBox.Show(xe.ChildNodes[0].InnerText);
                                rs = xe.ChildNodes[0].InnerText;
                            };
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }

/* if (xe.GetAttribute("genre") == "张三")//如果genre属性值为“张三” 
                         {
                             xe.SetAttribute("genre", "update张三");//则修改该属性为“update张三”

XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点 
                             foreach (XmlNode xn1 in nls)//遍历 
                             {
                                 XmlElement xe2 = (XmlElement)xn1;//转换类型 
                                 if (xe2.Name == "author")//如果找到 
                                 {
                                     xe2.InnerText = "亚胜";//则修改
                                 }
                             }
                         }*/
                    }

}
                else
                {
                    MessageBox.Show("no files");
                };
            }
            catch
            {

};
            return rs;
        }

private void createxmlGB(string xmlname, string root)
        {
            try
            {
                xmldoc = new XmlDocument();
                XmlDeclaration xmldecl;
                xmldecl = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null);
                xmldoc.AppendChild(xmldecl);
                xmlelem = xmldoc.CreateElement("", "List", "");
                xmldoc.AppendChild(xmlelem);
                xmldoc.Save(xmlname);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

private void createxmlutf8(string xmlname, string root)
        {
            try
            {
                xmldoc = new XmlDocument();
                XmlDeclaration xmldecl;
                xmldecl = xmldoc.CreateXmlDeclaration("1.0", "utf8", null);
                xmldoc.AppendChild(xmldecl);
                xmlelem = xmldoc.CreateElement("", "List", "");
                xmldoc.AppendChild(xmlelem);
                xmldoc.Save(xmlname);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

private Boolean writexml(string Module, string aname, string atitle)
        {
            Boolean Isok = false;
            xmlfiles = path + Module + ".xml";

try
            {
                if (File.Exists(xmlfiles) == false)
                {
                    createxmlGB(xmlfiles, Module);
                };
                
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(xmlfiles);
                XmlNode root = xmlDoc.SelectSingleNode("List");//查找<Employees> string anode, 
                
                XmlElement xe1 = xmlDoc.CreateElement(aname);//创建一个<Node>节点 
                //  xe1.SetAttribute("mark", Module);//设置该节点genre属性 
                XmlElement xesub1 = xmlDoc.CreateElement("Title");
                xesub1.InnerText = atitle;//设置文本节点 
                xe1.AppendChild(xesub1);//添加到<Node>节点中 
                root.AppendChild(xe1);//添加到<Employees>节点中 
                xmlDoc.Save(xmlfiles);
                Isok = true;
                //  MessageBox.Show("write ok");
            }
            /* else
             {
                 MessageBox.Show("no files");
             };*/

catch
            {

};
            return Isok;
        }

private Boolean writexmlGB(string Module, string aname, string avalue)
        {
            Boolean Isok = false;
            xmlfiles = path + Module + ".xml";
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                if (File.Exists(xmlfiles) == false)
                {
                    // MessageBox.Show("no files");
                    createxmlGB(xmlfiles, Module);
                    //XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(xmlfiles);
                    XmlNode root = xmlDoc.SelectSingleNode("List");
                    XmlElement xe1 = xmlDoc.CreateElement(aname);//创建一个<Node>节点 
                    //  xe1.SetAttribute("mark", Module);//设置该节点genre属性 
                    XmlElement xesub1 = xmlDoc.CreateElement("Title");
                    xesub1.InnerText = avalue;//设置文本节点 
                    xe1.AppendChild(xesub1);//添加到<Node>节点中 
                    /*  XmlElement xesub2 = xmlDoc.CreateElement("Value");
                      xesub2.InnerText = avalue;
                      xe1.AppendChild(xesub2);
                      */
                    root.AppendChild(xe1);//添加到<Employees>节点中 
                    xmlDoc.Save(xmlfiles);
                    Isok = true;
                }
                else
                {  //查有没有这个字段,如果有就修改,没有就建立
                    xmlDoc.Load(xmlfiles);
                    XmlNodeList nodeList = xmlDoc.SelectSingleNode("List").ChildNodes;//获取Employees节点的所有子节点 
                    Boolean Ishave = false;
                    //                MessageBox.Show("ok");
                    foreach (XmlNode xn in nodeList)//遍历所有子节点 
                    {
                        //  MessageBox.Show("k");                       
                            XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型
                            if (xe.Name.ToString() == aname) //如果有
                            {
                              // MessageBox.Show(xe.Name + "\n" + xe.ChildNodes[0].InnerText);                                
                                xe.ChildNodes[0].InnerText = avalue;
                               // xmlDoc.Save(xmlfiles);
                                Ishave = true;
                                break;
                            }
                    }

if (Ishave == false)
                            {
                              //  MessageBox.Show("no node");
                                XmlNode root2 = xmlDoc.SelectSingleNode("List");
                                XmlElement xe2 = xmlDoc.CreateElement(aname);
                                //  xe1.SetAttribute("mark", Module);//设置该节点genre属性 
                                XmlElement xesub2 = xmlDoc.CreateElement("Title");
                                xesub2.InnerText = avalue;//设置文本节点 
                                xe2.AppendChild(xesub2);//添加到<Node>节点中 
                                root2.AppendChild(xe2);//添加到<Employees>节点中 
                                Isok = true;
                            }
                   
                    Isok = true;
                    xmlDoc.Save(xmlfiles);
                }

}
            
            catch
            {

};
            return Isok;
        }

private Boolean writexmlGB2(string Module, string aname, string atitle)
        {
            Boolean Isok = false;
            xmlfiles = path + Module + ".xml";

try
            {
                if (File.Exists(xmlfiles) == false)
                {
                    /// MessageBox.Show("no files");
                    createxmlGB(xmlfiles, Module);
                };
                
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(xmlfiles);
                XmlNode root = xmlDoc.SelectSingleNode("List");//查找<Employees> string anode, 
                XmlElement xe1 = xmlDoc.CreateElement(aname);//创建一个<Node>节点 
                //  xe1.SetAttribute("mark", Module);//设置该节点genre属性 
                XmlElement xesub1 = xmlDoc.CreateElement("Title");
                xesub1.InnerText = atitle;//设置文本节点 
                xe1.AppendChild(xesub1);//添加到<Node>节点中 
                root.AppendChild(xe1);//添加到<Employees>节点中

xmlDoc.Save(xmlfiles);
                Isok = true;
                //   MessageBox.Show("write ok");
            }

catch
            {

};
            return Isok;
        }

private void button6_Click(object sender, EventArgs e)
        {
          // itemfun.userid = "jack";
          // itemfun.msgshow(itemfun.userid);

// FrmReport frm = new FrmReport();
           
          // frm.Show();

/*  XtraReport3 xr = new XtraReport3();
            xr.LoadLayout(@"C:\Users\Default\Desktop\DXexpress Demo\DXexpress\Web\File\Report1.repx");
            xr.ShowPreview();
            */

XtraReport3 xr = new XtraReport3();
           // xr.ShowPrintStatusDialog();
            xr.ShowPreviewDialog();//.ShowPreview();
            //this.ReportViewer1.Report = report;

// 不要这句report.ShowPreview();   
        }

private void button5_Click(object sender, EventArgs e)
        {

int x = 1024;
            //string p = DateFormat.ShortDate.ToString();
            //System.DateTime pdate = new System.DateTime();
            //取当前年月日时分秒
              string pdate = System.DateTime.Now.ToShortDateString();
              string y = string.Format("x的值是{0}, k={1}, this date is:{2}", x, x*2, pdate); 
            //StringBuilder MyStringBuilder = new StringBuilder("Hello {0} i {1} world, {}", "world", "love", "hahaha");
            itemfun.msgshow(y);

List<string> list = new List<string>();
            list.Add("baidu");
            list.Add("alibaba");
            list.Add("netease");
            list.Add("tencent");
            list.Add("中国电信");
            list.Add("中国移动");

var excelString = new StringBuilder();

foreach (var item in list)
            {
                excelString.AppendFormat("【company:{0}】: {1}, {2}", item, "i like ", item);
            }
            itemfun.msgshow(excelString.ToString());

/* List<string> cities = new List<string>();
            cities.Add("New York");
            cities.Add("Mumbai");
            cities.Add("Berlin");
            cities.Add("Istanbul");*/
            // Join strings into one CSV line
            string line = string.Join(",", list.ToArray());
            
            itemfun.msgshow(line);

//创建一个文件流,用以写入或者创建一个StreamWriter
            
            FileStream fs = new FileStream(itemfun.path+"\\list.txt", FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            sw.Flush();
            // 使用StreamWriter来往文件中写入内容 
            sw.BaseStream.Seek(0, SeekOrigin.Begin);
            for (int i = 0; i < list.Count; i++)
            {
                sw.WriteLine(list[i]);
            }
            //关闭此文件t 
            sw.Flush();
            sw.Close();
            fs.Close();

// string s = dataGridView1.CurrentCell
            /*
             *DataGridView的几个基本操作:
1、获得某个(指定的)单元格的值:
dataGridView1.Row[i].Cells[j].Value;
2、获得选中的总行数:
dataGridView1.SelectedRows.Count;
3、获得当前选中行的索引:
dataGridView1.CurrentRow.Index;
4、获得当前选中单元格的值:
dataGridView1.CurrentCell.Value;
5、取选中行的数据
string[] str = new string[dataGridView.Rows.Count];
for(int i;i<dataGridView1.Rows.Count;i++)
{
if(dataGridView1.Rows[i].Selected == true)
{
str[i] = dataGridView1.Rows[i].Cells[1].Value.ToString();
}
}
7、获取选中行的某个数据
int a = dataGridView1.SelectedRows.Index;

dataGridView1.Rows[a].Cells["你想要的某一列的索引,想要几就写几"].Value;

获得某个(指定的)单元格的值: dataGridView1.Row[i].Cells[j].Value; Row[i] 应该是Rows[i]

int a=dataGridView1.CurrentRow.Index;
string str=dataGridView1.Row[a].Cells["strName"].Value.Tostring();

selectedRows[0]当前选中的行
.cell[列索引].values 就是当前选中行的某个单元格的值

DataGridView1.SelectedCells(0).Value.ToString 取当前选择单元内容
DataGridView1.Rows(e.RowIndex).Cells(2).Value.ToString 当前选择单元第N列内容

*/
        }

private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = itemfun.querydb("select * from colorinfo");

/*      foreach (Control control in this.Controls)
            {
                //遍历所有TextBox...
               
            } */
            //
       
/*            
 string SqlString = "delete Test where Name=‘"+Name+"‘";
 int count=doSQL(SqlString);*/
        }

private void button1_Click(object sender, EventArgs e)
        {
           dataGridView1.DataSource = itemfun.querydb("select * from colorinfo"); 
        }

private void button2_Click(object sender, EventArgs e)
        {
            
            string sqlcode = "";
            for (int i = 0; i < 20; i++)
            {
                if (i < 6)
                {
                    sqlcode = "insert into colorinfo(cid,cname,tpid) values(" + i.ToString() + ",‘color" + i.ToString() + "‘,1)";
                }
                else
                {
                    sqlcode = "insert into colorinfo(cid,cname,tpid) values(" + i.ToString() + ",‘color" + i.ToString() + "‘,2)";

}
                // MessageBox.Show(sqlcode);
                 itemfun.doSQL(sqlcode);
            }

}

private void button4_Click(object sender, EventArgs e)
        {
            string s = Interaction.InputBox("请输入", "提示", "默认值", -1, -1);  //-1表示在屏幕的中间  
           // MessageBox.Show(s); 
            s = s.Trim();
            if (s != "")
            {
                if (s == "*")
                {
                    itemfun.doSQL("delete from colorinfo ");
                }
                else
                {
                    itemfun.doSQL("delete from colorinfo where cid=‘" + s + "‘");
                }
                dataGridView1.DataSource = itemfun.querydb("select * from colorinfo");
            };

}

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowindex = e.RowIndex;

string value0=""; 
 string value1 = ""; 
 string value2 = ""; 
 try 
 { 
 //获得当前行的第一列的值 
     value1 = dataGridView1.Rows[rowindex].Cells[1].Value.ToString(); 
 //获得当前行的第0列的值 
     value0 = dataGridView1.Rows[rowindex].Cells[0].Value.ToString(); 
 //获得当前行的第二列的值 
     value2 = dataGridView1.Rows[rowindex].Cells[2].Value.ToString().Trim(); 
   // MessageBox.Show("第0列的值:{0};第一列的值:{1};第二列的值:{2}",value0,value1,value2); 
    } 
 catch (Exception exc) {

}
        }

private void button7_Click(object sender, EventArgs e)
        {
            FileStream fs = new FileStream(itemfun.path + "\\list.txt", FileMode.Open, FileAccess.Read);
            List<string> list = new List<string>();
            StreamReader sr = new StreamReader(fs);
            //使用StreamReader类来读取文件 
            sr.BaseStream.Seek(0, SeekOrigin.Begin);
            // 从数据流中读取每一行,直到文件的最后一行
            string tmp = sr.ReadLine();
            while (tmp != null)
            {
                MessageBox.Show(tmp);
                list.Add(tmp);
                tmp = sr.ReadLine();
            }
            //关闭此StreamReader对象 
            sr.Close();
            fs.Close();

}

private void button9_Click(object sender, EventArgs e)
        {

}

private void button10_Click(object sender, EventArgs e)
        {
            if (txtIP.Text.Trim() == "" || txtPort.Text.Trim() == "")
            {
                MessageBox.Show("IP and Port cannot be null", "Error");
                return;
            }
            int idwErrorCode = 0;

Cursor = Cursors.WaitCursor;
            if (btnConnect.Text == "DisConnect")
            {
                axCZKEM1.Disconnect();
                bIsConnected = false;
                btnConnect.Text = "Connect";
                lblState.Text = "Current State:DisConnected";
                Cursor = Cursors.Default;
                return;
            }

bIsConnected = axCZKEM1.Connect_Net(txtIP.Text, Convert.ToInt32(txtPort.Text));
            if (bIsConnected == true)
            {
                btnConnect.Text = "DisConnect";
                btnConnect.Refresh();
                lblState.Text = "Current State:Connected";
                iMachineNumber = 1;//In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
                axCZKEM1.RegEvent(iMachineNumber, 65535);//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
            }
            else
            {
                axCZKEM1.GetLastError(ref idwErrorCode);
                MessageBox.Show("Unable to connect the device,ErrorCode=" + idwErrorCode.ToString(), "Error");
            }
            Cursor = Cursors.Default;
        }

private void button8_Click(object sender, EventArgs e)
        {
            if (bIsConnected == false)
            {
                MessageBox.Show("Please connect the device first", "Error");
                return;
            }

string sdwEnrollNumber = "";
            int idwTMachineNumber = 0;
            int idwEMachineNumber = 0;
            int idwVerifyMode = 0;
            int idwInOutMode = 0;
            int idwYear = 0;
            int idwMonth = 0;
            int idwDay = 0;
            int idwHour = 0;
            int idwMinute = 0;
            int idwSecond = 0;
            int idwWorkcode = 0;

int idwErrorCode = 0;
            int iGLCount = 0;
            int iIndex = 0;

Cursor = Cursors.WaitCursor;
            lvLogs.Items.Clear();
            axCZKEM1.EnableDevice(iMachineNumber, false);//disable the device
            if (axCZKEM1.ReadGeneralLogData(iMachineNumber))//read all the attendance records to the memory
            {
                while (axCZKEM1.SSR_GetGeneralLogData(iMachineNumber, out sdwEnrollNumber, out idwVerifyMode,
                           out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode))//get records from the memory
                {
                    iGLCount++;
                    lvLogs.Items.Add(iGLCount.ToString());
                    lvLogs.Items[iIndex].SubItems.Add(sdwEnrollNumber);//modify by Darcy on Nov.26 2009
                    lvLogs.Items[iIndex].SubItems.Add(idwVerifyMode.ToString());
                    lvLogs.Items[iIndex].SubItems.Add(idwInOutMode.ToString());
                    lvLogs.Items[iIndex].SubItems.Add(idwYear.ToString() + "-" + idwMonth.ToString() + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString());
                    lvLogs.Items[iIndex].SubItems.Add(idwWorkcode.ToString());
                    iIndex++;
                }
            }
            else
            {
                Cursor = Cursors.Default;
                axCZKEM1.GetLastError(ref idwErrorCode);

if (idwErrorCode != 0)
                {
                    MessageBox.Show("Reading data from terminal failed,ErrorCode: " + idwErrorCode.ToString(), "Error");
                }
                else
                {
                    MessageBox.Show("No data from terminal returns!", "Error");
                }
            }
            axCZKEM1.EnableDevice(iMachineNumber, true);//enable the device
            Cursor = Cursors.Default;
        }

private void button10_Click_1(object sender, EventArgs e)
        {
            if (bIsConnected == false)
            {
                MessageBox.Show("Please connect the device first", "Error");
                return;
            }
            int idwErrorCode = 0;

lvLogs.Items.Clear();
            axCZKEM1.EnableDevice(iMachineNumber, false);//disable the device
            if (axCZKEM1.ClearGLog(iMachineNumber))
            {
                axCZKEM1.RefreshData(iMachineNumber);//the data in the device should be refreshed
                MessageBox.Show("All att Logs have been cleared from teiminal!", "Success");
            }
            else
            {
                axCZKEM1.GetLastError(ref idwErrorCode);
                MessageBox.Show("Operation failed,ErrorCode=" + idwErrorCode.ToString(), "Error");
            }
            axCZKEM1.EnableDevice(iMachineNumber, true);//enable the device
        }

private void button13_Click(object sender, EventArgs e)
        {
            writexmlGB(textBox1.Text, textBox2.Text, textBox3.Text);
        }

private void button12_Click(object sender, EventArgs e)
        {
          MessageBox.Show(readxmlGB(textBox1.Text, textBox2.Text));

updatexmlGB(textBox1.Text, textBox2.Text, textBox3.Text);
            /*  writexmlGB(textBox1.Text, textBox2.Text, textBox3.Text);*/
        }

private void button11_Click(object sender, EventArgs e)
        {
            foreach (Control control in this.Controls)
            {
                //遍历所有TextBox...
                if (control is Label)
                {
                    Label l = (Label)control;//.Text = "kao";
                    // l.Text = "se";
                    writexmlGB(this.Name, l.Name, l.Text);
                }
                //遍历所有DateTimePicker...
                if (control is Button)
                {
                    Button b = (Button)control;
                    // b.Text = "bb";
                    writexmlGB(this.Name, b.Name, b.Text);
                }
                
                if (control is DataGridView)
                {
                    DataGridView dgv = (DataGridView)control;
                    // b.Text = "bb";
                    //
                    for (int i =0; i< dgv.ColumnCount; i++)
                    {
                       //MessageBox.Show( dgv.Columns[i].Name.ToString());
                        writexmlGB(this.Name, dgv.Name+"."+i.ToString(), dgv.Columns[i].Name.ToString());
                    };
                }

if (control is ListView)
                {
                       ListView lv = (ListView)control;
                       // int nColOrder = 0; lvLogs.Items[iIndex].SubItems                
                      // int cnt = lv.SubItems.Count;//行中包含的数据个数
                       //Items[nRowOrder].SubItems[nColOrder].Text
                     /*  for (int j = 1; j < lv.Items[1].SubItems.Count-1; j++)//每行中的每项
                       {
                          
                          //string ValueofEveryRow = lvi.SubItems[nColOrder].Text;
                           //
                       }*/
                       for (int i = 0; i < lv.Columns.Count; i++)
                       {
                           //处理Item 
                           writexmlGB(this.Name, lv.Name+"."+ i.ToString(), lv.Columns[i].Text.ToString());
                           
                       }
/*                    for (int x = 0; x < item.SubItems.Count; x++)
                           {
                               //处理SubItem
                               MessageBox.Show(item.SubItems[x].Text);
                           }
                      */
                   
                }
            }
        }

private void button14_Click(object sender, EventArgs e)
        {
            foreach (Control control in this.Controls)
            {
                if (control is Label)
                {
                    Label l = (Label)control;//.Text = "kao";
                    // l.Text = "se";
                    //writexml(this.Name, "Label", l.Text);
                    l.Text = readxmlGB(this.Name, l.Text);
                }
                //遍历所有DateTimePicker...
                if (control is Button)
                {
                    Button b = (Button)control;
                    b.Text = readxmlGB(this.Name, b.Text);
                   
                    // writexml(this.Name, "Button", b.Text);
                }
            }
        }

private void button15_Click(object sender, EventArgs e)
        {
            string[] aAry = { "1", "2017-03-09" };
           // string[] ary = { "1", "2008-01-01" };
            DomethClient.DomethClient.strDllN = "Order_S.dll";
            DomethClient.DomethClient.DllType = "Order_S.Order_S";
            if (DomethClient.DomethClient.Dometh("GetTableAttArray", "test2", aAry) == false)
            {
                Fun.MsImformagion(DomethClient.DomethClient.strMessage);
                return;
            }
            if (DomethClient.DomethClient.objReturns != null)
            {
                DataTable dt = (DataTable)DomethClient.DomethClient.objReturns;
                //将查询到的数据填充到表格中
                dataGridView1.DataSource = dt;
            }

}

private void button16_Click(object sender, EventArgs e)
        {
            /* if(dgvData.DataSource == null)
                return;
            string strSavePath = "";
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Excel|.xls|Excel|.xlsx";
            if (sfd.ShowDialog() == DialogResult.OK)
                strSavePath = sfd.FileName;
            else
                return;
            DataTable dt = (DataTable)dgvData.DataSource; */
            Microsoft.Office.Interop.Excel.Application myApp = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook myBook = myApp.Workbooks.Item[0];//.Item.Add(true);
            Microsoft.Office.Interop.Excel.Worksheet mySheet = (Microsoft.Office.Interop.Excel.Worksheet)myBook.Worksheets[1];
            //Microsoft.Office.Interop.Excel.Range excelRange = null;

m( mySheet.Cells[1, 1]);// = "工号";
           /* mySheet.Cells[1, 2] = "姓名";
            mySheet.Cells[1, 3] = "部门";
            mySheet.Cells[1, 4] = "考勤";
            mySheet.Cells[1, 5] = "备注";
           for (int i = 0; i < dt.Rows.Count; i++)
            {
                mySheet.Cells[i + 2, 1] = dt.Rows[i]["fPersonnelCode"].ToString();
                mySheet.Cells[i + 2, 2] = dt.Rows[i]["fPersonnelName"].ToString();
                mySheet.Cells[i + 2, 3] = dt.Rows[i]["fDeprarMentName"].ToString();
                mySheet.Cells[i + 2, 4] = dt.Rows[i]["fWTime"].ToString();
                mySheet.Cells[i + 2, 5] = dt.Rows[i]["fWorkType"].ToString();
            }
            */
            //excelRange.Borders.LineStyle = 1;
            //excelRange.Font.Size = 10;

string strVersion = myApp.Version;
           /* if (CheckIsDecimal(strVersion) && Convert.ToDecimal(strVersion) >= 12)
                myBook.SaveAs(strSavePath, Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8, Missing.Value, Missing.Value,
                                false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            else*/
           //     myBook.SaveAs(strSavePath, Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel9795, Missing.Value, Missing.Value,
          //                  false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            myBook = null;
            mySheet = null;
            myApp.Quit();
            myApp = null; 
        //}
        }

private void button17_Click(object sender, EventArgs e)
        {           
            if (DomethClient.DomethClient.Dometh("GetTableAttString", "test", "1") == false)
            {
                Fun.MsImformagion(DomethClient.DomethClient.strMessage);
                return;
            }
            if (DomethClient.DomethClient.objReturns != null)
            {
                DataTable dt = (DataTable)DomethClient.DomethClient.objReturns;
                //将查询到的数据填充到表格中
                dataGridView1.DataSource = dt;
            }
        }

private void button18_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.Application myApp = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook myBook = myApp.Workbooks._Open(@"E:\out\hello2.xls",
            Missing.Value, Missing.Value, Missing.Value, Missing.Value,
            Missing.Value, Missing.Value, Missing.Value, Missing.Value,
            Missing.Value, Missing.Value, Missing.Value, Missing.Value);

Microsoft.Office.Interop.Excel.Worksheet mySheet = (Microsoft.Office.Interop.Excel.Worksheet)myBook.Worksheets[1];
               
           mySheet.Activate();
            Microsoft.Office.Interop.Excel.Range range;
  
            try
            {
              for (int i = 1; i < 5; i++)
                {
                    for (int j = 1; j < 5; j++)
                    {
                        range = (Microsoft.Office.Interop.Excel.Range)mySheet.Cells[i, j];
                        m(range.Text.ToString().Trim());
                    }
                    
                }
                //myApp..Rangerng1 = mySheet.get_Range("A1", Type.Missing);
                //   Excel.ApplicationxApp = new Excel.ApplicationClass();

//  xApp.Visible = true;

/*
                            //得到WorkBook对象,可以用两种方式之一:下面的是打开已有的文件 
                            Excel.Workbook xBook = xApp.Workbooks._Open(@"D:\Sample.xls",
                            Missing.Value, Missing.Value, Missing.Value, Missing.Value,

Missing.Value, Missing.Value, Missing.Value, Missing.Value,

Missing.Value, Missing.Value, Missing.Value, Missing.Value);

//xBook=xApp.Workbooks.Add(Missing.Value);//新建文件的代码

//指定要操作的Sheet,两种方式:

Excel.WorksheetxSheet = (Excel.Worksheet)xBook.Sheets[1];
                            //Excel.WorksheetxSheet=(Excel.Worksheet)xApp.ActiveSheet;

//读取数据,通过Range对象 
                            Excel.Rangerng1 = xSheet.get_Range("A1", Type.Missing);
                            Console.WriteLine(rng1.Value2);

//读取,通过Range对象,但使用不同的接口得到Range 
                            Excel.Rangerng2 = (Excel.Range)xSheet.Cells[3, 1];
                            Console.WriteLine(rng2.Value2);
                */
            }
            catch
            {
                range = null;
                myBook = null;
                mySheet = null;
                myApp.Quit();
                myApp = null; 
            }
        }

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
           //currentcell当前活动单元格 columnindex 当前活动单元格的索引
           // this.textBox1.Text = dataGridView1.SelectedCells[dataGridView1.CurrentCell.ColumnIndex].ToString();
            //m(Convert.ToString());dataGridView1.CurrentCell.Value.ToString()
            //查看此单元格的值currentcell.value
            int colindex = dataGridView1.CurrentCell.ColumnIndex;
           // this.textBox1.Text = dataGridView1.CurrentCell.ColumnIndex.ToString();

if (colindex == 2)
            {
                //MessageBox.Show("3");
              // string []
               // string[] ary1 = Select_Data(colindex);
                if (formSelect == null) formSelect = new Form_SelectData();
                if (formSelect.ShowDialog() == DialogResult.OK)
            {
              /*  txtCutstomer.Text = frmMySelectPurveyer.getpurveyer()[0];
                txtCutstomerName.Text = frmMySelectPurveyer.getpurveyer()[1];
                txtContact.Text = frmMySelectPurveyer.getpurveyer()[4];
                txtPhone.Text = frmMySelectPurveyer.getpurveyer()[5];
                txtAddress.Text = frmMySelectPurveyer.getpurveyer()[3]; */
                //formSelect.rst[0];
                m("hello", formSelect.rst[0]);
            }

/* 第一种解决办法
                if (Select_Data(colindex) == true)
                {
                   // m(ary[0], ary[1]);
                  
                         //int rowindex = e.RowIndex;  = "aliba";//
                            //获得当前行的第一列的值 
                 //   this.dataGridView1.Rows[index].Cells[0];
                    dataGridView1.Rows[e.RowIndex].Cells[1].Value =ary[0];//.ToString();
                   // gridview1.Rows[i].Cells["Status"].Value
               
                }; */
            }
            else
            {
               // m(dataGridView1.CurrentCell.Value.ToString());
                //MessageBox.Show("other");
            }
            
           // this.textBox1.Text = dataGridView1.CurrentCell.Value.ToString() + dataGridView1.CurrentCell.ColumnIndex.ToString();
            //selectedcells.tostring返回类型的名字信息,而不是单元格的内容,即显示datagridviewselectedcellcollection
            // this.textBox1.Text = dataGridView1.SelectedCells.ToString();

}

private Boolean Select_Data(int colindex)
        {
            Boolean rs = false;
           
            // string[] arr = new string[2];//Array []
            //arr = new int[5]; 
            try
            {   
                Form_SelectData frm = new Form_SelectData();
                frm.ShowDialog();

rs = true;
                //List<string>
              //  arr[0] = "jack";
              //  arr[1] = "rose";
               // return false;
            }
            catch
            {
            };
            return rs;
        }

private void button19_Click(object sender, EventArgs e)
        {
            string sql2 = readxmlGB("FireMonkey","test");
            m(sql2);
            //FireMonkey
         //   string sql = "select a from db where a> ‘{0}‘ ";
            sql2 = string.Format(sql2, "1");
            m(sql2);

string[] ary = {"1","2008-01-01"};
            string sql = readxmlGB("FireMonkey", "test2");
            m(sql);
            // FireMonkey
            // string sql = "select a from db where a> ‘{0}‘ ";
            sql = string.Format(sql, ary);
            m(sql);
        }

private void button20_Click(object sender, EventArgs e)
        {
            string s = " select * from a where a={0}";
            string ss = s.Replace("{","‘{");

ss = ss.Replace("}", "}‘");
            m(s, ss);
        }

}
}

时间: 2024-10-21 19:02:50

demo code的相关文章

Google Glog Demo Code.

#include <glog/logging.h> #include <glog/raw_logging.h> #include<vector> using namespace std; void ProcessSignal(const char* data, int size) { LOG(ERROR) << __func__ << ":Error..." << std::string(data,size); }

swagger demo code

//Application 开启注解 @EnableSwagger2public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }} pom.xml <!-- Swagger --> <dependency> <groupId>io.springfox</groupId> <arti

web.py简单demo

1.准备工作 安装python/安装web.py/安装sql插件 2.python代码 1 # coding:utf-8 2 import sys 3 default_encoding = 'utf-8' 4 if sys.getdefaultencoding() != default_encoding: 5 reload(sys) 6 sys.setdefaultencoding(default_encoding) 7 import web 8 from web import form 9 i

Haffman Code

什么是Haffman编码?以后再说,嘿嘿先上实现. Python 实现: 在这个实现当中,我们并没有统计文本的字符出现频率,仅仅是为Haffman Coding的一个demo. """ Code writer : EOF Code file : haffman.py Code date : 2015.01.28 e-mail : [email protected] Code description: Here is a implementation of Haffman-Co

Google Summer of Code 2017 经验谈

Google Summer of Code (GSoC) 2018 又要开始了. 如果想实现你心中的开源梦想, 用代码让世界变得更美好. 参加GSoC可能是你进入开源的世界最好途径. GSoC是什么 Google Summer of Code是Google每年举办的一个活动. 从2005年开始到现在已经举办了十三届. Google在GSoC中的角色是一个平台和资金的提供者. 通过这个平台, 学生能够找到自己心仪的开源组织, 为了能获得实现project idea的资格而展开竞争. 申请期截止之后

react context toggleButton demo

//toggleButton demo: //code: //1.Appb.js: import React from 'react'; import {ThemeContext, themes} from './theme-context'; import ThemeTogglerButton from './theme-toggler-button'; class Appb extends React.Component { constructor(props) { super(props)

Vulkan SDK Demo 之一 熟悉

DiligentEngine的API是D3d11和D3D12风格的,vulkan也被封装成了这种风格的API. 在了解Diligent Engine是如何对vulkan进行封装之前,我准备先学习下Vulkan.知乎funchun的编程指南是中文版,英文不好,准备先看一版中文版,回头再去研习其他的内容. 1.Vulkan编程指南阅读摘要 1.1 Vulkan SDK 安装完成之后,安装目录有如下文件.在阅读编程指南的过程中,我并未采用指南中的demo code来进行研究,而是使用的SDK自带的de

LingPipe-TextClassification(文本分类)

What is Text Classification? Text classification typically involves assigning a document to a category by automated or human means. LingPipe provides a classification facility that takes examples of text classifications--typically generated by a huma

__FUNCTION__, __LINE__ 有助于debug的宏定义

__FUNCTION__, __LINE__ 今天无意之间看到一段代码,里面有这样一个片段: if (!interface) { err ("%s - error, can't find device for minor %d", __FUNCTION__, subminor); retval = -ENODEV; goto exit; } 这个__FUNCTION__干嘛的?少见(本人水平不够~),有意思~ 后面找了一下,这个是和编译器GCC相关连的宏定义,而这些宏定义的时候有助于快