电子技术电子技术
 
电池分档算法
牛逼大仙 2017-5-22 16:07:11
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //测试电池数据
            double jy = 10;
            double nz = 20;
            double rl = 10;
            double dy = 30;
            double yc = 30;

            bool jyng = false;
            bool nzng = false;
            bool rlng = false;
            bool dyng = false;
            bool ycng = false;

            //7行5列设置最小值和设置最大值数据初始化
            //给数组赋datatable中的值
            //档位8行
            //设置最大参数5列,设置最小参数5列,1.jy 2.nz 3.rl 4.dy 5.yc
                                            //绝缘 内阻 容量 电压 压差
                                        //1行  00   01   02   03   04
                                        //2行  10   11   12   13   14          
                                        //3行  20   21   22   23   24                                  
                                        //4行  30   31   32   33   34                    
                                        //5行  40   41   42   43   44                    
                                        //6行  50   51   52   53   54        
                                        //7行  60   61   62   63   64            
                                        //8行  70   71   72   73   74            
                
            int[,] numbermax = new int[8, 5] { { 11, 12, 13, 14, 15 },
                                               { 21, 22, 23, 24, 25 },
                                               { 31, 32, 33, 34, 35 },
                                               { 41, 42, 43, 44, 45 },
                                               { 51, 52, 53, 54, 55 },
                                               { 61, 62, 63, 64, 65 },
                                               { 71, 72, 73, 74, 75 },
                                               { 81, 82, 83, 84, 85 } };
            int[,] numbermin = new int[8, 5] { { 1, 2, 3, 4, 5 } ,
                                               { 11, 12, 13, 14, 15 },
                                               { 21, 22, 23, 24, 25 },
                                               { 31, 32, 33, 34, 35 },
                                               { 41, 42, 43, 44, 45 },
                                               { 51, 52, 53, 54, 55 },
                                               { 61, 62, 63, 64, 65 },
                                               { 71, 72, 73, 74, 75 } };
            for(int a=0;a<8;a++)
                if (jy < numbermax[a,0] && jy > numbermin[a,0])//第一列
                {
                    if (nz < numbermax[a,1] && nz > numbermin[a,1])//第二列
                    {
                        if (rl < numbermax[a,2] && rl > numbermin[a,2 ])//第三列
                        {
                            if (dy < numbermax[a,3] && dy > numbermin[a,3])//第四列
                            {
                                if (yc < numbermax[a,4] && yc > numbermin[a,4])//第五列
                                {
                                    //如果第一行五个都满足那么就将此电池置为OK
                                    
                                    textBox1.Text = "电池第"+(a+1).ToString()+"档ok";
                                    break;
                                }
                                else
                                {
                                    if (a == 7)
                                    {
                                        textBox1.Text = "电池第8档ng";
                                    }
                                    else
                                    {
                                        ycng = true;
                                        
                                    }
                                }
                            }
                            else
                            {
                                dyng = true;
                                
                                
                            }
                        }
                        else
                        {
                            rlng = true;
                            
                            
                        }
                    }
                    else
                    {
                        nzng = true;
                        
                        
                    }
                }
                else
                {
                    jyng = true;
                    
                    
                }

            if (jyng == true) { textBox1.Text = "绝缘ng"; }
            if (nzng == true) { textBox1.Text = "内阻ng"; }
            if (rlng == true) { textBox1.Text = "容量ng"; }
            if (dyng == true) { textBox1.Text = "电压ng"; }
            if (ycng == true) { textBox1.Text = "压差ng"; }

        }
    }
}

想参与大家的讨论?现在就 登录 或者 注册

万流景仰
专栏收藏夹发私信
学术分 13科创币 4013总主题 738 帖总回复 964 楼拥有证书:会员 笔友 机友 学者
注册于 2008-05-17 10:48最后登录 2018-10-26 19:49

个人简介

天津某大专毕业,对数据采集和测控略懂。自己还有许多地方不懂,向各位多学习。

nkc production server  https://github.com/kccd/nkc.git

科创研究院 (c)2001-2018

蜀ICP备11004945号-2 川公网安备51010802000058号