每日日报2021 12/3

大作业的相关代码的粘贴。这是我今天完成的。

namespace WindowsFormsApp1
{
public partial class Store : Form
{
List<StoreGoodsStockInfos> searchlist = new List<StoreGoodsStockInfos>();
public Store()
{
InitializeComponent();
ShopEntities db = new ShopEntities();
var result = db.StoreGoodsStockInfos.ToList();
initExcel(result);
}

private void initExcel(List<StoreGoodsStockInfos> list)
{

int listsize = list.Count();
foreach (StoreGoodsStockInfos goodsInfos in list)
{
int index = this.dgvStoreList.Rows.Add();
this.dgvStoreList.Rows[index].Cells[0].Value = goodsInfos.StoreGoodsId;
this.dgvStoreList.Rows[index].Cells[1].Value = goodsInfos.GoodsId;
this.dgvStoreList.Rows[index].Cells[2].Value = goodsInfos.StCount;
this.dgvStoreList.Rows[index].Cells[3].Value = goodsInfos.StAmount;
this.dgvStoreList.Rows[index].Cells[4].Value = goodsInfos.StPrice;
this.dgvStoreList.Rows[index].Cells[5].Value = goodsInfos.CurCount;
this.dgvStoreList.Rows[index].Cells[6].Value = goodsInfos.StockAmount;
this.dgvStoreList.Rows[index].Cells[7].Value = goodsInfos.StockUp;
this.dgvStoreList.Rows[index].Cells[8].Value = goodsInfos.StockDown;
this.dgvStoreList.Rows[index].Cells[9].Value = goodsInfos.Creator;
this.dgvStoreList.Rows[index].Cells[10].Value = goodsInfos.Createtime;

}
searchlist = list;
}

private void btnQuery_Click(object sender, EventArgs e)
{

string goodsid = txtKeyWords.Text;
if (goodsid.Equals(""))
{
ShopEntities db = new ShopEntities();
searchlist = db.StoreGoodsStockInfos.ToList();
}

else
{
ShopEntities db = new ShopEntities();
int v = Convert.ToInt32(goodsid);
searchlist = db.StoreGoodsStockInfos.Where(g => g.GoodsId == v).ToList();
}
dgvStoreList.Rows.Clear();
if (searchlist.Count == 0)
{
MessageBox.Show("未查询到符合结果!");
}
initExcel(searchlist);
}
private void tsbtnAdd_Click(object sender, EventArgs e)
{
AddForm addForm = new AddForm();
addForm.Show();
//dgvStoreList.Rows.Clear();

}

private void tsbtnEdit_Click(object sender, EventArgs e)
{
ShopEntities db = new ShopEntities();
int m = Convert.ToInt32(dgvStoreList.CurrentRow.Cells[0].Value.ToString());
//List<StoreGoodsStockInfos> sUserList1 = new List<StoreGoodsStockInfos>();
//sUserList1 = db.StoreGoodsStockInfos.Where(u => u.StoreGoodsId == m).ToList();
Update update= new Update(m);
update.Show();
}
private void tsbtnDelete_Click(object sender, EventArgs e)
{
ShopEntities db = new ShopEntities();
//int index = this.dgvStoreList.Rows.Count;
int m =Convert.ToInt32(dgvStoreList.CurrentRow.Cells[0].Value.ToString());
List<StoreGoodsStockInfos> sUserList1 = new List<StoreGoodsStockInfos>();
sUserList1= db.StoreGoodsStockInfos.Where(u => u.StoreGoodsId == m).ToList();
//db.StoreGoodsStockInfos.Remove(sUserList1[0]);
if (sUserList1 != null && sUserList1.Any())
{
foreach(StoreGoodsStockInfos item in sUserList1)
{
db.StoreGoodsStockInfos.Remove(item);
}
}
db.SaveChanges();
int rowIndex = dgvStoreList.CurrentRow.Index;
dgvStoreList.Rows.RemoveAt(rowIndex);
}


}
}

posted @ 2021-12-03 20:26  宋振兴  阅读(32)  评论(0编辑  收藏  举报