• 合并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;
                    }
                }
               
    
            }

    四种合并情况:

    出库计费等于退库计费

    出库计费大于退库计费

    出库计费小于退库计费

    只存在退库计费

  • 相关阅读:
    docker配置国内加速器
    pwm原理与stm32控制
    【C语言】赋值表达式自增自减逗号表达式
    linux下利用paho.mqtt.c进行mqtt开发 #c编程
    linux下tcp #c编程
    windows下的linux子系统虚拟串口的使用
    linux下搭建mqtt服务器(mosquitto)
    linux下paho.mqtt.c下载安装
    树莓派&mysql数据库
    vscode+mysql数据库编程
  • 原文地址:https://www.cnblogs.com/hanke123/p/5702990.html
Copyright © 2020-2023  润新知