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);
}
}
}
demo code的更多相关文章
- penpyxl basic function demo code
Openpyxl basic function demo code demo code: #!/usr/bin/env python # -*- coding: utf-8 -*- "&qu ...
- RAD Studio Demo Code和几个国外FMX网站 good
FireMonkey X – Amazing overview of FireMonkey FMX Feeds – All your FireMonkey news in one place FMX ...
- ps2keyboard demo code for 8052
#pragma code symbols debug objectextend #include <reg51.h> /* special function register declar ...
- ( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in D:\demo\code\yolo\index\index.php on li
sql语句为:$sql="select count(*) from com where a_id=$v['id']"; 出现以下错误: 原因: 变量没有用花括号引起来 改为: $ ...
- npm install 安装报错:npm ERR! EPERM npm ERR! -4048 npm ERR! Error: EPERM: operation not permitted, unlink 'D:\test\demo\code\materialT\node_modules\.staging'
更新项目依赖包,删除掉package-lock.json.node_modules,运行npm install,报如上错误信息,查询资料说是没有权限,本人用管理员身份打开powershell,运行np ...
- swagger demo code
//Application 开启注解 @EnableSwagger2public class Application { public static void main(String[] args) ...
- c++ demo code
/* //多继承 #include <iostream> using namespace std; class Sofa { public: Sofa(); ~Sofa(); void s ...
- 创建简单的表单Demo
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- react context toggleButton demo
//toggleButton demo: //code: //1.Appb.js: import React from 'react'; import {ThemeContext, themes} f ...
- Google Summer of Code 2017 经验谈
Google Summer of Code (GSoC) 2018 又要开始了. 如果想实现你心中的开源梦想, 用代码让世界变得更美好. 参加GSoC可能是你进入开源的世界最好途径. GSoC是什么 ...
随机推荐
- ctfshow_web入门 sql注入(web171~248)
sql注入 这是算是学习+做题+记录的一个笔记吧,而且基本都是看着Y4师傅的博客做的 由于是做过sqli靶场,所以这个就记录快点了.如果靶场没遇到的,也会做笔记. union 联合注入 web171 ...
- 如何将项目打包成apk或exe程序
一. 打包成exe 确认已经安装了pyinstaller,然后依次执行下面指令 pyinstaller -F setup.py 打包exe pyinstaller -F -w setup.py 不带控 ...
- 【CQOI2011】动态逆序对
分析 近乎裸的 \(cdq\) 分治数点问题 我们考虑一个数被删去,它对删后区间逆序对个数的影响就是减去现存序列中前面比它大的个数再减去现存序列中后面比它小的个数 那么我们考虑如何处理时间限制 既然是 ...
- js根据指定字段数据去重
//根据id去重 function unique(arr1) { const res = new Map(); return arr1.filter((a) => !res.has(a.id) ...
- 设备区分判断IPAD,H5,PC
HTML: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...
- uniapp 自定义 picker
前言 我们在开发的过程中经常会遇到现有插件无法满足需求的情况,毕竟不是组件库不能满足项目所有需求,这时就需要我们自己去构建组件. 写这篇博文也是记录我平时开发的,以后可能会用得到的东西.希望大家看到本 ...
- ABP微服务系列学习-对接前端界面
前面我们把后端的微服务架子基本搭建完成并成功启动了,现在我们可以对接前端界面了.这里我们直接用ABP模板里面的Angular的前端界面. 创建应用程序模板 使用ABPCli创建一个应用程序模板,前端选 ...
- Abp返回时间格式化
private void ConfigureDateTime() { Configure<MvcNewtonsoftJsonOptions>(options => { options ...
- Electron 打包 (electron-builder)
本文只测试了Windows 10 下打包Windows基础安装包 更多花哨的配置,请戳官方文档 https://www.electron.build/ www.electron.build/ 构建基 ...
- CLIP 改进工作串讲(下)学习笔记
1.图像生成 1.1CLIPasso(semantically-aware object sketching) 将物体的照片变成简笔画的形式,希望即使有最少的线条,也能识别出来物体. 问题定义,在纸上 ...