Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
QuestionI have a search button and datagrid in c# and SQL Pin
antonio_dsanchez11-Oct-16 11:16
antonio_dsanchez11-Oct-16 11:16 
AnswerRe: I have a search button and datagrid in c# and SQL Pin
Dave Kreskowiak11-Oct-16 11:23
mveDave Kreskowiak11-Oct-16 11:23 
AnswerRe: I have a search button and datagrid in c# and SQL Pin
antonio_dsanchez11-Oct-16 11:31
antonio_dsanchez11-Oct-16 11:31 
GeneralRe: I have a search button and datagrid in c# and SQL Pin
Swinkaran11-Oct-16 16:00
professionalSwinkaran11-Oct-16 16:00 
GeneralRe: I have a search button and datagrid in c# and SQL Pin
Pete O'Hanlon11-Oct-16 20:35
mvePete O'Hanlon11-Oct-16 20:35 
QuestionClosest standard value Pin
Pavlex410-Oct-16 10:44
Pavlex410-Oct-16 10:44 
AnswerRe: Closest standard value Pin
Pete O'Hanlon10-Oct-16 19:31
mvePete O'Hanlon10-Oct-16 19:31 
GeneralRe: Closest standard value Pin
Pavlex410-Oct-16 23:38
Pavlex410-Oct-16 23:38 
C#
private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "4")
            {
                if (textBox1.Text == "0")
                {
                    MessageBox.Show("Otpornost mora biti veca od nule!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if(comboBox2.Text=="")
                {
                    MessageBox.Show("Izaberi vrednost tolerancije!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                var colours = new string[] { "Black", "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Grey","White", "Silver", "Gold" };
                var factorDictionary = new Dictionary<char, double>() { { 'p', 0.000000000001 }, { 'n', 0.000000001 }, { 'u', 0.000001 }, { 'm', 0.001 }, { 'R', 1 }, { 'K', 1000 }, { 'M', 1000000 }, { 'G', 1000000000 } };
                string res = string.Empty;
 
                while (string.IsNullOrEmpty(res))
                {
                    res = textBox1.Text;
                }
 
                var lastChar = res.Last();
                var isUnitCorrect = factorDictionary.ContainsKey(lastChar);
                var value = res.Substring(0, res.Length - 1);
                var isValueCorrect = !value.Any(x => !char.IsDigit(x));
 
                if (isUnitCorrect && isValueCorrect)
                {
                    double mul = factorDictionary[lastChar];
                    double val = double.Parse(value) * mul;
                    int third = 0;
 
                    if (val < 0.1)
                    {
                        MessageBox.Show("Otpornost ne moze da bude manja od 0.1 oma!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (val < 1)
                    {
                        val *= 100;
                        third = 10;
                    }
                    else if (val < 10)
                    {
                        val *= 10;
                        third = 11;
                    }
 
                    res = val.ToString();
 
                    if (res.Count() > 24)
                    {
                        MessageBox.Show("Pogresna vrednost!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
 
                    else
                    {
                        label15.BackColor = Color.FromName(colours[res[0] - '0']);
                        label16.BackColor = Color.FromName(colours[res[1] - '0']);
                        label17.BackColor = Color.FromName(colours[third != 0 ? third : res.Count() - 2]);
                        label6.Text = textBox1.Text;
                        textBox2.Text = colours[res[0] - '0'];
                        textBox3.Text = colours[res[1] - '0'];
                        textBox4.Text = colours[third != 0 ? third : res.Count() - 2];
                    }
                    if (comboBox1.Text == "4")
                    {
                        if (comboBox2.Text == "E24 (5%)")
                        {
                            label18.BackColor = Color.Gold;
                            textBox5.Text = "Gold";
                        }
                        if (comboBox2.Text == "E12 (10%)")
                        {
                            label18.BackColor = Color.Silver;
                            textBox5.Text = "Silver";
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Invalid value!", "Otpornost", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

Rant[REPOST] Closest standard value Pin
Richard Deeming11-Oct-16 2:14
mveRichard Deeming11-Oct-16 2:14 
AnswerRe: Closest standard value Pin
Ralf Meier11-Oct-16 21:02
mveRalf Meier11-Oct-16 21:02 
GeneralRe: Closest standard value Pin
Pavlex423-Oct-16 8:43
Pavlex423-Oct-16 8:43 
QuestionAndroid Studio: How can disable My applications in mobile when i run my application? Pin
Dr Kasa10-Oct-16 3:54
Dr Kasa10-Oct-16 3:54 
AnswerRe: Android Studio: How can disable My applications in mobile when i run my application? Pin
Pete O'Hanlon10-Oct-16 4:11
mvePete O'Hanlon10-Oct-16 4:11 
AnswerRe: Android Studio: How can disable My applications in mobile when i run my application? Pin
OriginalGriff10-Oct-16 4:11
mveOriginalGriff10-Oct-16 4:11 
GeneralRe: Android Studio: How can disable My applications in mobile when i run my application? Pin
Eddy Vluggen10-Oct-16 4:38
professionalEddy Vluggen10-Oct-16 4:38 
GeneralRe: Android Studio: How can disable My applications in mobile when i run my application? Pin
OriginalGriff10-Oct-16 4:42
mveOriginalGriff10-Oct-16 4:42 
GeneralRe: Android Studio: How can disable My applications in mobile when i run my application? Pin
Eddy Vluggen10-Oct-16 5:02
professionalEddy Vluggen10-Oct-16 5:02 
GeneralRe: Android Studio: How can disable My applications in mobile when i run my application? Pin
OriginalGriff10-Oct-16 5:53
mveOriginalGriff10-Oct-16 5:53 
QuestionLong Path Exception when adding attachments Pin
NJdotnetdev10-Oct-16 3:00
NJdotnetdev10-Oct-16 3:00 
AnswerRe: Long Path Exception when adding attachments Pin
F-ES Sitecore10-Oct-16 3:16
professionalF-ES Sitecore10-Oct-16 3:16 
AnswerRe: Long Path Exception when adding attachments Pin
NJdotnetdev12-Oct-16 4:35
NJdotnetdev12-Oct-16 4:35 
GeneralRe: Long Path Exception when adding attachments Pin
Eddy Vluggen12-Oct-16 7:03
professionalEddy Vluggen12-Oct-16 7:03 
GeneralRe: Long Path Exception when adding attachments Pin
NJdotnetdev17-Oct-16 2:23
NJdotnetdev17-Oct-16 2:23 
Questionan "injection" problem/challenge Pin
BillWoodruff9-Oct-16 22:45
professionalBillWoodruff9-Oct-16 22:45 
AnswerRe: an "injection" problem/challenge Pin
Richard Deeming10-Oct-16 3:21
mveRichard Deeming10-Oct-16 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.