合并datagridview 条件合并行数据

        public void HeBing()
        {
            int rowsCount;
            int CellCount;
            rowsCount = FG1.Rows.Count;
            CellCount = FG1.Columns.Count;
            for (int a = 0; a < rowsCount; a++)
            { 
                string F_OnlyCode = FG1.Rows[a].Cells[1].Value.ToString();
                string F_Code = FG1.Rows[a].Cells[2].Value.ToString();
                double quanty = double.Parse(FG1.Rows[a].Cells[5].Value.ToString());
                if (quanty < 0)
                { 
                    for (int b = 0; b < rowsCount; b++)
                    {  
                        string F_Code1 = FG1.Rows[b].Cells[2].Value.ToString();
                        double quanty1 = double.Parse(FG1.Rows[b].Cells[5].Value.ToString());
                        string f_Onlycode = FG1.Rows[b].Cells[1].Value.ToString();
                        if (F_Code == F_Code1 && f_Onlycode != F_OnlyCode )
                        { 
                            //  出库计费等于退费
                            if (quanty1 == -quanty)
                            {
                                //FG1.Rows.RemoveAt(a);
                                FG1.Rows[a].Visible = false;

                                for (int c = 0; c < FG1.Rows.Count; c++)
                                {
                                    if (FG1.Rows[c].Cells[2].Value.ToString() == F_Code)
                                    {
                                        FG1.Rows[c].Visible = false;
                                       
                                    }
                                }
                            }
    
                            //出库计费大于退费
                            if (quanty1 > -quanty && quanty1 != quanty)
                            {
                                FG1.Rows[b].Cells[5].Value = (quanty - (-quanty1)).ToString("F3");
                                this.FG1.Rows[b].DefaultCellStyle.BackColor = Color.Aqua;
                                FG1.Rows[a].Visible = false;

                            }//出库计费小于退费
                            if (quanty1 < -quanty && quanty1 != quanty)
                            {

                                this.FG1.Rows[b].Cells[5].Value = ((quanty1) + (quanty)).ToString("F3");
                                //this.FG1.Rows.RemoveAt(a);
                                FG1.Rows[a].Visible = false;
                            }
                            if (quanty1 == quanty && quanty < 0 && quanty != quanty)
                            {
                                FG1.Rows[a].DefaultCellStyle.BackColor = Color.Aqua;
                            }
                          
                        }
                       
                    }
                }

            } 
            //只存在退费信息
            for (int u = 0; u < rowsCount; u++)
            {
                if (double.Parse(FG1.Rows[u].Cells[5].Value.ToString()) < 0)
                { 
                this.FG1.Rows[u].DefaultCellStyle.BackColor = Color.Red;
                }
            }
           

        }

四种合并情况:

出库计费等于退库计费

出库计费大于退库计费

出库计费小于退库计费

只存在退库计费

转载于:https://www.cnblogs.com/hanke123/p/5702990.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值