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);
}
}
}