📄 goodslist.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace FOUPOS
{
public partial class GoodsList : Form
{
private int PageCount = 1;
//显示记录数
private int PageSize = 20;
//分页数
private int SumPageNum = 1;
//总记录数
private int SumCount = 1;
public GoodsList()
{
InitializeComponent();
}
private void GoodsList_Load(object sender, EventArgs e)
{
skinEngine1.SkinFile = "OneBlue.ssk";
BindGoods(1);
}
protected void BindGoods(int CurrentPage)
{
string str = " 1=1 ";
if (!string.IsNullOrEmpty(txtNum.Text))
{
str += " AND SNum LIKE '%" + txtNum.Text.Trim() + "%'";
}
if (!string.IsNullOrEmpty(txtName.Text))
{
str += " AND SName LIKE '%" + txtName.Text.Trim() + "%'";
}
POS.BLL.FGoods b_Goods = new POS.BLL.FGoods();
DataSet ds = b_Goods.GetList(str);
SumCount = ds.Tables[0].Rows.Count;//总记录数
lblSum.Text = "记录数:" + SumCount;
SumPageNum = POS.BLL.PageFunction.GetTotalPage(PageSize, SumCount);
//共分页数
lab_SumPage.Text = "共:" + SumPageNum.ToString() + "页";
//当前页
lab_CurrentPage_Message.Text = "当前页:" + PageCount.ToString();
lblM.Text = "每页记录数:" + PageSize;
if (SumCount > 0)
{
//取消自动创建列
dgvGoods.AutoGenerateColumns = false;
//隐藏空白列
dgvGoods.RowHeadersVisible = false;
//去掉空白行
dgvGoods.AllowUserToAddRows = false;
dgvGoods.DataSource = POS.BLL.PageFunction.GetPageContent(ds, CurrentPage, 20, SumCount);
}
}
private void btSearch_Click(object sender, EventArgs e)
{
BindGoods(1);
}
private void btnUP_Click(object sender, EventArgs e)
{
if (PageCount > 1)
{
PageCount -= 1;
//Add_Pagination(Sum_PageContent);
BindGoods(PageCount);
lab_CurrentPage_Message.Text = "当前页:" + PageCount.ToString();
}
else
{
MessageBox.Show("已到首页。");
}
}
private void btnDown_Click(object sender, EventArgs e)
{
PageCount += 1;
if (PageCount <= SumPageNum)
{
//Add_Pagination(Sum_PageContent);
BindGoods(PageCount);
lab_CurrentPage_Message.Text = "当前页:" + PageCount.ToString();
}
else
{
PageCount -= 1;
MessageBox.Show("已到最后一页。");
}
}
private void dgvGoods_DoubleClick(object sender, EventArgs e)
{
int row = dgvGoods.CurrentCell.RowIndex; //获取行索引
DataTable dt = (DataTable)dgvGoods.DataSource;
int id = Convert.ToInt32(dt.Rows[row]["ID"]);//获取ID
POS.BLL.FGoods b_Goods = new POS.BLL.FGoods();
POS.Model.FGoods m_Goods = b_Goods.GetModel(id);
UpGoods upgood = new UpGoods(m_Goods);
//upgood.TopMost = true;
upgood.ShowDialog();
}
private void btnDel_Click(object sender, EventArgs e)
{
if (dgvGoods.DataSource != null && dgvGoods.CurrentCell != null)
{
int row = dgvGoods.CurrentCell.RowIndex; //获取行索引
DataTable dt = (DataTable)dgvGoods.DataSource;
int id = Convert.ToInt32(dt.Rows[row]["ID"]);//获取ID
POS.BLL.FGoods b_Goods = new POS.BLL.FGoods();
DialogResult show = MessageBox.Show("是否确认删除!", "是否确认删除!", MessageBoxButtons.YesNo);
if (show == DialogResult.Yes)
{
b_Goods.Delete(id);
BindGoods(PageCount);
}
}
else
MessageBox.Show("没有选中商品。");
}
private void btnFirst_Click(object sender, EventArgs e)
{
BindGoods(1);
lab_CurrentPage_Message.Text = "当前页:1";
}
private void btnLast_Click(object sender, EventArgs e)
{
BindGoods(SumPageNum);
lab_CurrentPage_Message.Text = "当前页:" + SumPageNum.ToString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -