📄 search.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace BookStore.Forms
{
public partial class Search : Form
{
private DataTable headTable;
private DataTable tempTable;
private ArrayList tempCustomer;
private ArrayList tempEmployee;
public Search()
{
InitializeComponent();
SetStatusContrl();
}
//搜索
private void btn_Search_Click(object sender, EventArgs e)
{
if (cb_Search.Text.ToString() == "销售日期")
{
SearchByDate();
}
else if (cb_Search.Text.ToString() == "销售人员")
{
SearchByEmployee();
}
else if (cb_Search.Text.ToString() == "制单人")
{
SearchByUser();
}
else if (cb_Search.Text.ToString() == "客户姓名")
{
SearchByCustomerName();
}
}
//按日期搜索
private void SearchByDate()
{
try
{
string str = this.tb_Search.Text.ToString();
string select = "select SellID,CustomerID,EmployeeID,TotalPrice,Time,TotalTax,NoTax from Sells where Time like '" + str + "%'";
tempTable = DataAccess.Narnu.GetDataTableBySql(select);
SetData();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
//按销售人员搜索
private void SearchByEmployee()
{
try
{
string str = this.tb_Search.Text.ToString();
string select = "select SellID,CustomerID,EmployeeID,TotalPrice,Time,TotalTax,NoTax from Sells where EmployeeID=" + str;
tempTable = DataAccess.Narnu.GetDataTableBySql(select);
SetData();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
//按制单人搜索
private void SearchByUser()
{
try
{
string str = this.tb_Search.Text.ToString();
string select = "select SellID,CustomerID,EmployeeID,TotalPrice,Time,TotalTax,NoTax from Sells where ZDR=" + str;
tempTable = DataAccess.Narnu.GetDataTableBySql(select);
SetData();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
//按客户姓名搜索
private void SearchByCustomerName()
{
try
{
string str = this.tb_Search.Text.ToString();
string select = "select CustomerID from Customers where Name='" + str+"'";
str = DataAccess.Narnu.GetObjectBySqlString(select).ToString().Trim();
select = "select SellID,CustomerID,EmployeeID,TotalPrice,Time,TotalTax,NoTax from Sells where CustomerID=" + str;
tempTable = DataAccess.Narnu.GetDataTableBySql(select);
SetData();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
//设置headTable的格式
private void SetStatusContrl()
{
headTable = new DataTable();
headTable.Columns.Add("销售单号", typeof(int));
headTable.Columns.Add("客户姓名", typeof(string));
headTable.Columns.Add("销售员", typeof(string));
headTable.Columns.Add("金额", typeof(decimal));
headTable.Columns.Add("销售时间", typeof(DateTime));
headTable.Columns.Add("税额", typeof(decimal));
headTable.Columns.Add("税后金额", typeof(decimal));
}
//根据tempTable设置headTable的数据
private void SetData()
{
tempCustomer = new ArrayList();
tempEmployee = new ArrayList();
for (int i = 0; i < tempTable.Rows.Count; i++)
{
try
{
string select = "select Name from Customers where CustomerID=" + tempTable.Rows[i][1].ToString().Trim();
tempCustomer.Add(DataAccess.Narnu.GetObjectBySqlString(select).ToString().Trim());
select = "select Name from Employees where EmployeeID=" + tempTable.Rows[i][2].ToString().Trim();
tempEmployee.Add(DataAccess.Narnu.GetObjectBySqlString(select).ToString().Trim());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
this.headTable.Rows.Clear();
for (int i = 0; i < tempTable.Rows.Count; i++)
{
headTable.Rows.Add(headTable.NewRow());
headTable.Rows[i][0] = tempTable.Rows[i][0];
headTable.Rows[i][1] = tempCustomer[i].ToString();
headTable.Rows[i][2] = tempEmployee[i].ToString();
headTable.Rows[i][3] = tempTable.Rows[i][3];
headTable.Rows[i][4] = tempTable.Rows[i][4];
headTable.Rows[i][5] = tempTable.Rows[i][5];
headTable.Rows[i][6] = tempTable.Rows[i][6];
}
this.dg_Search.DataSource = headTable;
}
//提示
private void cb_Search_SelectedIndexChanged(object sender, EventArgs e)
{
if (cb_Search.Text.ToString() == "销售日期")
{
tb_Search.Text = "";
lbl_Info.Text="请输入日期格式,如1990年1月1日,请输入1990-1-1!";
}
else if (cb_Search.Text.ToString() == "销售人员")
{
tb_Search.Text = "";
lbl_Info.Text = "请输入销售人员的代号!";
}
else if (cb_Search.Text.ToString() == "制单人")
{
tb_Search.Text = "";
lbl_Info.Text = "请输入制单人的标号!";
}
else if (cb_Search.Text.ToString() == "客户姓名")
{
tb_Search.Text = "";
lbl_Info.Text = "请输入客户姓名!";
}
}
//
private void dg_Search_DoubleClick(object sender, EventArgs e)
{
try
{
int CurrentRowNum = this.dg_Search.CurrentCell.RowNumber;
SellListFrm.headInfo[0] = this.headTable.Rows[CurrentRowNum][0].ToString().Trim();
SellListFrm.headInfo[1] = this.headTable.Rows[CurrentRowNum][1].ToString().Trim();
SellListFrm.headInfo[2] = this.headTable.Rows[CurrentRowNum][2].ToString().Trim();
SellListFrm.headInfo[3] = this.headTable.Rows[CurrentRowNum][3].ToString().Trim();
SellListFrm.headInfo[4] = this.headTable.Rows[CurrentRowNum][4].ToString().Trim();
SellListFrm.headInfo[5] = this.headTable.Rows[CurrentRowNum][5].ToString().Trim();
SellListFrm.headInfo[6] = this.headTable.Rows[CurrentRowNum][6].ToString().Trim();
this.Close();
}
catch
{
return;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -