首页 技术 正文
技术 2022年11月15日
0 收藏 986 点赞 2,499 浏览 2768 个字

俗话说,磨刀不误砍柴工,先说一下情况。点击按钮后往dgv中添加一行(行中字段含有数量),再点击一次,又添加一行。

假如这两条信息一样。则要进行叠加(数量相加)。我的思路是这样的:每次点击一次就往dgv添加一行,同时拿到行的主键ID。

当再添加一行时,就遍历dgv中的行,拿每行的主键ID和点击时的主键ID作比较,如果相同,就获取这行的数量,加到已有的行

中去,最后移除这行。否则,直接添加一行。

  private void btnzengJia_Click(object sender, EventArgs e)
{
decimal WholesalePrice = ;//定义零售总价
decimal RetailPrice = ;//定义批发总价
int newShockCount = ;//定义新库存数
if (txtYaoPinDaiMa .Text.ToString(). Trim () !=null &&txtBaoZhuangDanWei .Text.ToString().Trim ()!=""
&&txtChuKuShu .Text !="")
{
if(txtChuKuShu.Text.Trim ().Length <)
{
if (Convert.ToInt32(txtKuCunShu.Text.Trim().ToString()) >=
Convert.ToInt32(txtChuKuShu.Text.Trim().ToString()))
{//绑定数据
dgvLingYao.Rows.Add();
int dgvPlaceRowCountRow = dgvLingYao.Rows.Count - ;
dgvLingYao.Rows[dgvPlaceRowCountRow].Cells["药品名称"].Value = txtYaoPinMingCheng.Text.Trim();
dgvLingYao.Rows[dgvPlaceRowCountRow].Cells["药品规格"].Value = txtGuiGe.Text.Trim();
dgvLingYao.Rows[dgvPlaceRowCountRow].Cells["批发价"].Value = txtPiFaJia.Text.Trim();
dgvLingYao.Rows[dgvPlaceRowCountRow].Cells["零售价"].Value = txtLingShouJia.Text.Trim().ToString ();
dgvLingYao.Rows[dgvPlaceRowCountRow].Cells["包装单位"].Value = txtBaoZhuangDanWei.Text.Trim();
dgvLingYao.Rows[dgvPlaceRowCountRow].Cells["出库数量"].Value = txtChuKuShu.Text.Trim();
dgvLingYao.Rows[dgvPlaceRowCountRow].Cells["备注"].Value = txtBeiZhu.Text.Trim();
dgvLingYao.Rows[dgvPlaceRowCountRow].Cells["药品ID"].Value = intDrugID;
//计算新库存数
newShockCount = Convert.ToInt32(txtKuCunShu.Text.Trim().ToString())
- Convert.ToInt32(txtChuKuShu.Text.Trim().ToString());
txtKuCunShu.Text = newShockCount.ToString();
int updatecount = myfrmGongYaoLinYongShengQingClient.updateShockCount(intDrugID, Convert.ToInt32
(txtKuCunShu.Text.Trim().ToString()));//修改库存数
foreach (DataGridViewRow dgvr in dgvLingYao.Rows)
{
if (dgvr.Cells["批发价"].Value != null)//计算批发价总额
{
WholesalePrice += Convert.ToDecimal(dgvr.Cells["批发价"].Value) * Convert.ToInt32(dgvr.Cells["出库数量"].Value);
}
if (dgvr.Cells["零售价"].Value != null)//计算零售价总额
{
RetailPrice += Convert.ToDecimal(dgvr.Cells["零售价"].Value) * Convert.ToInt32(dgvr.Cells["出库数量"].Value);
}
}
//绑定数据到文本
LbWholesalePrices.Text = WholesalePrice.ToString(); LbRetailPrice.Text = RetailPrice.ToString();
LbMargin.Text = (WholesalePrice - RetailPrice).ToString();  
int intlock = ;//定义一个整形锁(循环数) foreach (DataGridViewRow dgvr in dgvLingYao.Rows)
{
intlock++;
if (Convert.ToInt32(dgvr.Cells["药品ID"].Value) == intDrugID)
{
if (intlock < dgvLingYao.Rows.Count)//循环到倒数第二条
{
//相加库存数
dgvr.Cells["出库数量"].Value = Convert.ToInt32(dgvr.Cells["出库数量"].Value)
+ Convert.ToInt32(dgvLingYao.Rows[dgvPlaceRowCountRow].Cells["出库数量"].Value);
dgvLingYao.Rows.RemoveAt(dgvPlaceRowCountRow);//移除相同的那行数据
}
}
}
LbRecordCount.Text = dgvLingYao.Rows.Count.ToString();
}
else
{
panel2.Visible = true;
label18.Text = "库存不足";
ShowTime = DateTime.Now;
}
}
else
{
panel2.Visible = true;
label18.Text = "出库数太大";
ShowTime = DateTime.Now;
}
}
else
{
panel2.Visible = true;
label18.Text = "填完整再增加";
ShowTime = DateTime.Now;
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,941
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,465
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,280
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,094
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,728
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,765