VAGSuite.ctrlAirmassResult.gridView1_CustomDrawCell C# (CSharp) Метод

gridView1_CustomDrawCell() приватный Метод

private gridView1_CustomDrawCell ( object sender, DevExpress e ) : void
sender object
e DevExpress
Результат void
        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            try
            {
                if (e.CellValue != null)
                {
                    if (e.CellValue != DBNull.Value)
                    {
                        int b = 0;
                        int cellvalue = 0;
                        //if (m_isHexMode)
                        b = Convert.ToInt32(e.CellValue.ToString());
                        cellvalue = b;
                        b *= 255;
                        if (m_MaxValueInTable != 0)
                        {
                            b /= m_MaxValueInTable;
                        }
                        int red = 128;
                        int green = 128;
                        int blue = 128;
                        Color c = Color.White;
                        red = b;
                        if (red < 0) red = 0;
                        if (red > 255) red = 255;
                        if (b > 255) b = 255;
                        blue = 0;
                        green = 255 - red;
                        c = Color.FromArgb(red, green, blue);
                        SolidBrush sb = new SolidBrush(c);
                        e.Graphics.FillRectangle(sb, e.Bounds);

                        // check limiter type
                        //limitermap
                        int row = rows - (e.RowHandle + 1);
                        limitType curLimit = (limitType)limitermap.GetValue((row * columns) + e.Column.AbsoluteIndex);
                        Point[] pnts = new Point[4];
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y), 0);
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width - (e.Bounds.Height / 2), e.Bounds.Y), 1);
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y + (e.Bounds.Height / 2)), 2);
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y), 3);
                        if (curLimit == limitType.AirmassLimiter)
                        {
                            e.Graphics.FillPolygon(Brushes.Blue, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TorqueLimiterEngine)
                        {
                            e.Graphics.FillPolygon(Brushes.Yellow, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TurboSpeedLimiter)
                        {
                            e.Graphics.FillPolygon(Brushes.Black, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TorqueLimiterGear)
                        {
                            e.Graphics.FillPolygon(Brushes.SaddleBrown, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.FuelCutLimiter)
                        {
                            e.Graphics.FillPolygon(Brushes.DarkGray, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        if (comboBoxEdit2.SelectedIndex == 1)
                        {
                            // convert airmass to torque
                            if (_ECUType.Contains("EDC16"))
                            {
                                int rpm = Convert.ToInt32(y_axisvalues.GetValue(e.Column.AbsoluteIndex));
                                int torque = Convert.ToInt32(e.CellValue);
                                torque /= 10;
                                e.DisplayText = torque.ToString();
                            }
                            else
                            {
                                int rpm = Convert.ToInt32(y_axisvalues.GetValue(e.Column.AbsoluteIndex));
                                int torque = Tools.Instance.IQToTorque(Convert.ToInt32(e.CellValue), rpm, m_numberCylinders);
                                if (checkEdit6.Checked)
                                {
                                    torque = Tools.Instance.IQToTorque(Convert.ToInt32(e.CellValue), rpm, m_numberCylinders);// AirmassToTorqueLbft(Convert.ToInt32(e.CellValue), rpm);
                                }
                                torque /= 100;
                                e.DisplayText = torque.ToString();
                            }
                        }
                        else if (comboBoxEdit2.SelectedIndex == 2)
                        {
                            if (_ECUType.Contains("EDC16"))
                            {
                                int rpm = Convert.ToInt32(y_axisvalues.GetValue(e.Column.AbsoluteIndex));
                                int torque = Convert.ToInt32(e.CellValue);
                                torque /= 10;
                                double temptorque = torque * Tools.Instance.GetCorrectionFactorForRpm(rpm, m_numberCylinders);
                                torque = Convert.ToInt32(temptorque);
                                int horsepower = Tools.Instance.TorqueToPower(torque, rpm);
                                if (checkEdit5.Checked)
                                {
                                    horsepower = Tools.Instance.TorqueToPowerkW(torque, rpm);
                                }
                                e.DisplayText = horsepower.ToString();
                            }
                            else
                            {
                                //convert airmass to horsepower
                                int rpm = Convert.ToInt32(y_axisvalues.GetValue(e.Column.AbsoluteIndex));
                                int torque = Tools.Instance.IQToTorque(Convert.ToInt32(e.CellValue), rpm, m_numberCylinders);
                                int horsepower = Tools.Instance.TorqueToPower(torque, rpm);
                                if (checkEdit5.Checked)
                                {
                                    horsepower = Tools.Instance.TorqueToPowerkW(torque, rpm);
                                }
                                horsepower /= 100;
                                e.DisplayText = horsepower.ToString();
                            }
                        }
                        else
                        {
                            if (_ECUType.Contains("EDC16"))
                            {
                                // should display IQ in stead of torque
                                int rpm = Convert.ToInt32(y_axisvalues.GetValue(e.Column.AbsoluteIndex));
                                int torque = Convert.ToInt32(e.CellValue);
                                torque /= 10;
                                e.DisplayText = Tools.Instance.TorqueToIQ(torque, rpm, m_numberCylinders).ToString();
                            }
                            else
                            {
                                int airmass = Convert.ToInt32(e.CellValue);
                                airmass /= 100;
                                e.DisplayText = airmass.ToString();
                            }
                        }
                    }
                }
            }
            catch (Exception E)
            {
                Console.WriteLine(E.Message);
            }
        }