码迷,mamicode.com
首页 > Windows程序 > 详细

合并datagridview 条件合并行数据

时间:2016-07-25 13:06:24      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

        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;
                }
            }
           

        }

四种合并情况:

出库计费等于退库计费

出库计费大于退库计费

出库计费小于退库计费

只存在退库计费

合并datagridview 条件合并行数据

标签:

原文地址:http://www.cnblogs.com/hanke123/p/5702990.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!