📄 frmproductdate.cs
字号:
new System.Data.Common.DataColumnMapping("规格", "规格"),
new System.Data.Common.DataColumnMapping("单位", "单位"),
new System.Data.Common.DataColumnMapping("上日库存", "上日库存"),
new System.Data.Common.DataColumnMapping("当日生产", "当日生产"),
new System.Data.Common.DataColumnMapping("生产累计", "生产累计"),
new System.Data.Common.DataColumnMapping("当日报废", "当日报废"),
new System.Data.Common.DataColumnMapping("报废累计", "报废累计"),
new System.Data.Common.DataColumnMapping("当日转库", "当日转库"),
new System.Data.Common.DataColumnMapping("当日销售", "当日销售"),
new System.Data.Common.DataColumnMapping("销售累计", "销售累计"),
new System.Data.Common.DataColumnMapping("当日库存", "当日库存")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 产成品编号, 仓库, 拼音编码, 产成品名, 规格, 单位, 上日库存, 当日生产, 生产累计, 当日报废, 报废累计, 当日转库, 当日销售, 销" +
"售累计, 当日库存 FROM 产成品库存";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=WINDOWSXP;packet size=4096;user id=sa;data source=\".\";persist secu" +
"rity info=False;initial catalog=jxcbook";
//
// FrmProductDate
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(680, 414);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.panel1);
this.Name = "FrmProductDate";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "产成品库存查询(即时)";
this.Load += new System.EventHandler(this.FrmProductDate_Load);
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
private void FrmProductDate_Load(object sender, System.EventArgs e)
{//显示所有记录
//Open Connection.
SqlConnection conn = new SqlConnection("workstation id=localhost;Integrated Security=SSPI;database=jxcbook");
//Set the DataAdapter's query.
da = new SqlDataAdapter("select * from 产成品库存", conn);
ds = new DataSet();
//Fill the DataSet.
da.Fill(ds, "产成品库存");
//Set the source table.
dtSource = ds.Tables["产成品库存"];
}
private void button1_Click(object sender, System.EventArgs e)
{//查询记录
try
{
this.ds.Clear();
string StrSQL=" FROM 产成品库存 WHERE ";
if (comboBox1.Text.Trim() != "")
StrSQL+="仓库 like '"+comboBox1.Text.Trim()+ "%' and ";
if (textBox1.Text.Trim() != "")
StrSQL+="产成品编号 like '"+textBox1.Text.Trim()+ "%' and ";
if(StrSQL !="")
StrSQL=StrSQL.Substring(0,StrSQL.Length-5);
this.sqlDataAdapter1.SelectCommand.CommandText="Select * "+StrSQL;
this.sqlDataAdapter1.SelectCommand.Connection=this.sqlConnection1;
this.sqlConnection1.Open();
this.sqlDataAdapter1.SelectCommand.ExecuteNonQuery();
this.sqlDataAdapter1.Fill(this.ds);
this.dataGrid1.DataSource=this.dtSource;
System.Data.SqlClient.SqlCommand MyCommandAmt=new System.Data.SqlClient.SqlCommand("SELECT COUNT(*) "+StrSQL,this.sqlConnection1);
this.label3.Text="一共查询到:"+MyCommandAmt.ExecuteScalar().ToString()+"条记录符合要求";
System.Data.SqlClient.SqlCommand MyCommandSum=new System.Data.SqlClient.SqlCommand("SELECT SUM(上日库存) "+StrSQL,this.sqlConnection1);
this.label4.Text="上日库存总计为:"+MyCommandSum.ExecuteScalar().ToString();
System.Data.SqlClient.SqlCommand MyCommandAvg=new System.Data.SqlClient.SqlCommand("SELECT SUM(当日库存) "+StrSQL,this.sqlConnection1);
this.label4.Text+=" , 当日库存总计为:"+MyCommandAvg.ExecuteScalar().ToString();
this.sqlConnection1.Close();
// Set the start and max records.
pageSize = Convert.ToInt32(txtPageSize.Text);
maxRec = dtSource.Rows.Count;
PageCount = maxRec / pageSize;
//Adjust the page number if the last page contains a partial page.
if ((maxRec % pageSize) > 0)
{
PageCount += 1;
}
// Initial seeings
currentPage = 1;
recNo = 0;
// Display the content of the current page.
LoadPage();
}
catch(Exception Err)
{
MessageBox.Show("查询数据集记录操作失败:"+Err.Message,"信息提示",
MessageBoxButtons.OK,MessageBoxIcon.Information);
if(this.sqlConnection1.State==ConnectionState.Open)
{
this.sqlConnection1.Close();
}
}
}
private void FrmProductDate_Closed(object sender, System.EventArgs e)
{//关闭程序
if(this.sqlConnection1.State==ConnectionState.Open)
{
this.sqlConnection1.Close();
}
}
private void LoadPage()
{
int i;
int startRec;
int endRec;
DataTable dtTemp;
//Clone the source table to create a temporary table.
dtTemp = dtSource.Clone();
if (currentPage == PageCount)
{
endRec = maxRec;
}
else
{
endRec = pageSize * currentPage;
}
startRec = recNo;
//Copy rows from the source table to fill the temporary table.
for (i = startRec; i < endRec; i++)
{
if(i<=0)
{
MessageBox.Show("没有查询到任何数据!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
break;
}
else
{
dtTemp.ImportRow(dtSource.Rows[i]);
recNo += 1;
}
}
dataGrid1.DataSource = dtTemp;
DisplayPageInfo();
}
private void DisplayPageInfo()
{
txtDisplayPageNo.Text = "总页数: " + currentPage.ToString() + "/ " + PageCount.ToString();
}
private bool CheckFillButton()
{
// Check if the user clicks the "Fill Grid" button.
if (pageSize == 0)
{
MessageBox.Show("Set the Page Size, and then click the Fill Grid button!");
return false;
}
else
{
return true;
}
}
private void btnFillGrid_Click(object sender, System.EventArgs e)
{
// Set the start and max records.
pageSize = Convert.ToInt32(txtPageSize.Text);
maxRec = dtSource.Rows.Count;
PageCount = maxRec / pageSize;
//Adjust the page number if the last page contains a partial page.
if ((maxRec % pageSize) > 0)
{
PageCount += 1;
}
// Initial seeings
currentPage = 1;
recNo = 0;
// Display the content of the current page.
LoadPage();
this.button1.Enabled=true;
this.btnFirstPage.Enabled=true;
this.btnLastPage.Enabled=true;
this.btnPreviousPage.Enabled=true;
this.btnNextPage.Enabled=true;
this.comboBox1.Enabled=true;
this.textBox1.Enabled=true;
this.label1.Enabled=true;
this.label2.Enabled=true;
this.label3.Enabled=true;
this.label4.Enabled=true;
this.btnFillGrid.Enabled=false;
this.btnFillGrid.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(1)));
}
private void btnFirstPage_Click(object sender, System.EventArgs e)
{
if (CheckFillButton() == false)
{
return;
}
//Check if you are already at the first page.
if (currentPage == 1)
{
MessageBox.Show("已经是首页了!");
return;
}
currentPage = 1;
recNo = 0;
LoadPage();
}
private void btnNextPage_Click(object sender, System.EventArgs e)
{
//If the user did not click the "Fill Grid" button, then return.
if (CheckFillButton() == false)
{
return;
}
//Check if the user clicks the "Fill Grid" button.
if (pageSize == 0)
{
MessageBox.Show("Set the Page Size, and then click the Fill Grid button!");
return;
}
currentPage += 1;
if (currentPage > PageCount)
{
currentPage = PageCount;
//Check if you are already at the last page.
if (recNo == maxRec)
{
MessageBox.Show("已经是最后一页了!");
return;
}
}
LoadPage();
}
private void btnPreviousPage_Click(object sender, System.EventArgs e)
{
if (CheckFillButton() == false)
{
return;
}
if (currentPage == PageCount)
{
recNo = pageSize * (currentPage - 2);
}
currentPage -= 1;
//Check if you are already at the first page.
if (currentPage < 1)
{
MessageBox.Show("已经到头了!");
currentPage = 1;
return;
}
else
{
recNo = pageSize * (currentPage - 1);
}
LoadPage();
}
private void btnLastPage_Click(object sender, System.EventArgs e)
{
if (CheckFillButton() == false)
{
return;
}
//Check if you are already at the last page.
if (recNo == maxRec)
{
MessageBox.Show("已经到底了!");
return;
}
currentPage = PageCount;
recNo = pageSize * (currentPage - 1);
LoadPage();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -