Ejemplo n.º 1
0
 private void menuItem1_Click(object sender, EventArgs e)
 {
     totalResult();
     inputPanel1.Enabled = false;
     if (cmboxReshte.SelectedItem != null)
     {
         results frm = new results();
         frm.Controls[0].Text = "درصد کل" + " :" + average.ToString() + " %";
         frm.ShowDialog();
     }
     pictureBox5.Refresh();
 }
Ejemplo n.º 2
0
        private void btnCalc_Click_1(object sender, EventArgs e)
        {
            inputPanel1.Enabled = false;
            if (tabControl1.SelectedIndex == 4)
            {
                try
                {
                    string percentstobesent = string.Empty;
                    foreach (string str in smsom)
                    {
                        if (str != "empty")
                        {
                            percentstobesent += str + ",";
                        }
                    }
                    if (cmboxReshte.SelectedIndex == 0)
                    {
                       foreach (string str in smsekhrz)
                        {
                            if (str != "empty")
                            {
                                percentstobesent += str + ",";
                            }
                        }
                    }
                    else if (cmboxReshte.SelectedIndex == 1)
                    {
                        foreach (string str in smsekhtj)
                        {
                            if (str != "empty")
                            {
                                percentstobesent += str + ",";
                            }
                        }
                    }
                    percentstobesent = percentstobesent.Substring(0, percentstobesent.Length - 1);
                    SmsMessage msg = new SmsMessage();
                    string strno = textBox1.Text;
                    string strtext;
                    if (textBox2.Text != "Text to be sent to your friend...")
                    {
                        strtext = textBox2.Text + "(" + percentstobesent + ")";
                    }
                    else { strtext = "(" + percentstobesent + ")"; }
                    Cursor.Current = Cursors.WaitCursor;
                    if (textBox1.Text != null)
                    {
                        strno = textBox1.Text;
                    }
                    msg.To.Add(new Recipient(strno));
                    msg.RequestDeliveryReport = true; //requests as default
                    msg.Body = strtext.Trim();
                    msg.Send();
                }
                catch (InvalidSmsRecipientException ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                }
                catch (ServiceCenterException ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                }
                catch (SmsException ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                }
                catch (InvalidOperationException ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                }
                finally { Cursor.Current = Cursors.Default; }
            }
            else if (tabControl1.SelectedIndex == 0)
            {
                float grade;
                try
                {
                    if (cmboxReshte.SelectedItem == null)
                    {
                        if (txtTrue.Text == "0" && txtFalse.Text == "0" && txtNA.Text == "0")
                        {
                            results frm = new results();
                            frm.Controls[0].Text = "درصد شما" + " :" + "0" + " %";//label
                            frm.ShowDialog();
                        }
                        else
                        {
                            int _true = Int32.Parse(txtTrue.Text);
                            int _false = Int32.Parse(txtFalse.Text);
                            int _na = Int32.Parse(txtNA.Text);
                            float soorat = (_true * 3) - _false;
                            float makhraj = (_true + _false + _na) * 3;
                            grade = (soorat / makhraj) * 100;
                            results frm = new results();
                            frm.Controls[0].Text = "درصد شما" + " :" + grade.ToString() + " %";//label
                            frm.ShowDialog();
                        }
                    }
                    if (txtTrue.Text == "0" && txtFalse.Text == "0" && txtNA.Text == "0")
                    {
                        if (radOm.Checked == true || radEkh.Checked == true)
                        {
                            results frm = new results();
                            if (radOm.Checked == true)
                            {
                                frm.Controls[0].Text = cmbxOm.SelectedValue + " :0 %";//label
                                frm.ShowDialog();
                            }
                            else if (radEkh.Checked == true)
                            {
                                frm.Controls[0].Text = cmbxEkh.SelectedValue + " :0 %";//label
                                frm.ShowDialog();
                            }
                        }
                        if (cmbxOm.Enabled == true)
                        {
                            if (Om[cmbxOm.SelectedIndex].Substring(0, 1) != " ")
                            {
                                Om[cmbxOm.SelectedIndex] = " " + Om[cmbxOm.SelectedIndex] + ": %0";
                                percentOm[cmbxOm.SelectedIndex] = 0;
                            }
                            else
                            {
                                Om[cmbxOm.SelectedIndex] = " " + comboBoxItemsOm[cmbxOm.SelectedIndex] + ": %0";
                                percentOm[cmbxOm.SelectedIndex] = 0;
                            }
                        }
                        else if (cmbxEkh.Enabled == true && cmboxReshte.SelectedIndex == 0)
                        {
                            if (EkhRz[cmbxEkh.SelectedIndex].Substring(0, 1) != " ")
                            {
                                EkhRz[cmbxEkh.SelectedIndex] = " " + EkhRz[cmbxEkh.SelectedIndex] + ": %0";
                                percentEkh[cmbxEkh.SelectedIndex] = 0;
                            }
                            else
                            {
                                EkhRz[cmbxEkh.SelectedIndex] = " " + comboBoxItemsEkhRz[cmbxEkh.SelectedIndex] + ": %0";
                                percentEkh[cmbxEkh.SelectedIndex] = 0;
                            }
                        }
                        else if (cmbxEkh.Enabled == true && cmboxReshte.SelectedIndex == 1)
                        {
                            if (EkhTj[cmbxEkh.SelectedIndex].Substring(0, 1) != " ")
                            {
                                EkhTj[cmbxEkh.SelectedIndex] = " " + EkhTj[cmbxEkh.SelectedIndex] + ": %0";
                                percentEkh[cmbxEkh.SelectedIndex] = 0;
                            }
                            else
                            {
                                EkhTj[cmbxEkh.SelectedIndex] = " " + comboBoxItemsEkhTj[cmbxEkh.SelectedIndex] + ": %0";
                                percentEkh[cmbxEkh.SelectedIndex] = 0;
                            }
                        }
                    }
                    else
                    {
                        int _true = Int32.Parse(txtTrue.Text);
                        int _false = Int32.Parse(txtFalse.Text);
                        int _na = Int32.Parse(txtNA.Text);
                        float soorat = (_true * 3) - _false;
                        float makhraj = (_true + _false + _na) * 3;
                        grade = (soorat / makhraj) * 100;
                        if (radOm.Checked == true || radEkh.Checked == true)
                        {
                            results frm = new results();
                            if (radOm.Checked == true)
                            {
                                frm.Controls[0].Text = cmbxOm.SelectedValue + " :" + grade.ToString() + " %";//label
                                frm.ShowDialog();
                            }
                            if (cmboxReshte.SelectedItem != null)
                            {
                                if (radEkh.Checked == true)
                                {
                                    frm.Controls[0].Text = cmbxEkh.SelectedValue + " :" + grade.ToString() + " %";//label
                                    frm.ShowDialog();
                                }
                            }
                        }
                        if (cmbxOm.Enabled == true)
                        {
                            if (Om[cmbxOm.SelectedIndex].Substring(0, 1) != " ")
                            {
                                Om[cmbxOm.SelectedIndex] = " " + Om[cmbxOm.SelectedIndex] + ": %" + grade.ToString();
                                percentOm[cmbxOm.SelectedIndex] = grade;
                            }
                            else
                            {
                                Om[cmbxOm.SelectedIndex] = " " + comboBoxItemsOm[cmbxOm.SelectedIndex] + ": %" + grade.ToString();
                                percentOm[cmbxOm.SelectedIndex] = grade;
                            }
                        }
                        else if (cmbxEkh.Enabled == true && cmboxReshte.SelectedIndex == 0)
                        {
                            if (EkhRz[cmbxEkh.SelectedIndex].Substring(0, 1) != " ")
                            {
                                EkhRz[cmbxEkh.SelectedIndex] = " " + EkhRz[cmbxEkh.SelectedIndex] + ": %" + grade.ToString();
                                percentEkh[cmbxEkh.SelectedIndex] = grade;
                            }
                            else
                            {
                                EkhRz[cmbxEkh.SelectedIndex] = " " + comboBoxItemsEkhRz[cmbxEkh.SelectedIndex] + ": %" + grade.ToString();
                                percentEkh[cmbxEkh.SelectedIndex] = grade;
                            }
                        }
                        else if (cmbxEkh.Enabled == true && cmboxReshte.SelectedIndex == 1)
                        {
                            if (EkhTj[cmbxEkh.SelectedIndex].Substring(0, 1) != " ")
                            {
                                EkhTj[cmbxEkh.SelectedIndex] = " " + EkhTj[cmbxEkh.SelectedIndex] + ": %" + grade.ToString();
                                percentEkh[cmbxEkh.SelectedIndex] = grade;
                            }
                            else
                            {
                                EkhTj[cmbxEkh.SelectedIndex] = " " + comboBoxItemsEkhTj[cmbxEkh.SelectedIndex] + ": %" + grade.ToString();
                                percentEkh[cmbxEkh.SelectedIndex] = grade;
                            }
                        }
                    }
                }
                catch (Exception)
                {

                    MessageBox.Show("Invalid input", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                }
                    txtResultsTotal.Text = "";
                    int counterom = 0;
                    foreach (string strOm in Om)
                    {
                        if (strOm != comboBoxItemsOm[counterom])
                        {
                            txtResultsTotal.Text += strOm + "\r\n";
                        }
                        counterom++;
                    }
                    //txtResultsEkh.Text = "";
                    if (cmboxReshte.SelectedIndex == 0)
                    {
                        int counterekh = 0;
                        foreach (string strEkh in EkhRz)
                        {
                            if (strEkh != comboBoxItemsEkhRz[counterekh])
                            {
                                txtResultsTotal.Text += strEkh + "\r\n";
                            }
                            counterekh++;
                        }
                    }
                    else if (cmboxReshte.SelectedIndex == 1)
                    {
                        int counterekh = 0;
                        foreach (string strEkh in EkhTj)
                        {
                            if (strEkh != comboBoxItemsEkhTj[counterekh])
                            {
                                txtResultsTotal.Text += strEkh + "\r\n";
                            }
                            counterekh++;
                        }
                    }
                totalResult();
                pictureBox5.Refresh();
                if (cmboxReshte.SelectedValue != null)
                {
                    int counter = 0;
                    foreach (float om in percentOm)
                    {
                        data[counter] = om.ToString();
                        counter++;
                    }
                    if (cmboxReshte.SelectedIndex == 0)
                    {
                        data[counter] = "Rz";
                        counter++;
                        foreach (float ekh in percentEkh)
                        {
                            data[counter] = ekh.ToString();
                            counter++;
                        }
                    }
                    else if (cmboxReshte.SelectedIndex == 1)
                    {
                        data[counter] = "Tj";
                        counter++;
                        foreach (float ekh in percentEkh)
                        {
                            data[counter] = ekh.ToString();
                            counter++;
                        }
                    }
                }
                try //sending percents(float) to saveFile()
                {
                    if (cmboxReshte.SelectedIndex == 0)
                    {
                        savefilestr[0] = "riazi";
                    }
                    else if (cmboxReshte.SelectedIndex == 1)
                    {
                        savefilestr[0] = "tajrobi";
                    }
                    int i = 1;
                    foreach (float omflt in percentOm)
                    {
                        savefilestr[i] = omflt.ToString();
                        i++;
                    }
                    if (cmboxReshte.SelectedIndex == 0 || cmboxReshte.SelectedIndex == 1)
                    {
                        foreach (float ekhflt in percentEkh)
                        {
                            savefilestr[i] = ekhflt.ToString();
                            i++;
                        }
                    }
                    saveFile();
                }
                catch
                {
                    MessageBox.Show("Error saving the file!", "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                }
            }
            else if (tabControl1.SelectedIndex != 0 && tabControl1.SelectedIndex != 5)
            {
                tabControl1.SelectedIndex = 0;
            }
        }