osipyonok

Untitled

Jul 22nd, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using MySql.Data.MySqlClient;
  10.  
  11. namespace MedicalCardGenerator
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         private bool OnlineMode;//1-использовать сетевую бд , 0 - локальную
  16.         List<Cabinet> Cabinets = new List<Cabinet>(); //список кабинетов
  17.         List<Client_job> Client_jobs = new List<Client_job>();//список работ пациентов
  18.         List<Company> Companies = new List<Company>();//список компаний
  19.         List<Doctor> Doctors = new List<Doctor>();//список кабинетов с врачами
  20.         List<General_doctor> General_doctors = new List<General_doctor>();//список обследований для осмотров
  21.         List<General_inspection> General_inspections = new List<General_inspection>();//список осмотров
  22.         List<Payment_type> Payment_types = new List<Payment_type>();//типы оплаты
  23.         List<Professional_inspection> Professional_inspections = new List<Professional_inspection>();//список обследований для профосмотров
  24.         List<Profession> Professions = new List<Profession>();//список профессий врачей
  25.         List<Company_payment> Company_payments = new List<Company_payment>();//типы оплаты для компании
  26.         string con_str = @"server=82bc33e8-38bd-43e9-8c56-a64100b14ddc.mysql.sequelizer.com;database=db82bc33e838bd43e98c56a64100b14ddc;uid=dtlolccenqyetewj;pwd=Spzz27Q6g3RnrZxDpGg632i88SqokuYuZKDQUBejdEBGvZ2PpA4mc7AZfAAiQBUT";
  27.            
  28.         public Form1()
  29.         {
  30.             InitializeComponent();
  31.         }
  32.  
  33.         private void Form1_Load(object sender, EventArgs e)
  34.         {
  35.             string cs = con_str;
  36.             MySqlConnection conn = null;
  37.             try
  38.             {
  39.                 conn = new MySqlConnection(cs);
  40.                 conn.Open();
  41.                 OnlineMode = true;
  42.                 //MessageBox.Show("Success");
  43.            }
  44.            catch (MySqlException ex)
  45.            {
  46.                OnlineMode = false;
  47.                 //MessageBox.Show(ex.ToString());
  48.  
  49.            }
  50.            finally
  51.            {
  52.                
  53.                 FillLists();
  54.                 FillCheckBox();
  55.                 FillJobs();
  56.                 FillGeneralInspections();
  57.                
  58.                 textBox1.Text = Companies.Count.ToString();
  59.                 if (conn != null)
  60.                 {
  61.                     conn.Close();
  62.                 }
  63.            }
  64.         }
  65.  
  66.         private void button1_Click(object sender, EventArgs e)
  67.         {
  68.            // FillLists();
  69.             MessageBox.Show("Done");
  70.         }
  71.  
  72.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  73.         {
  74.             if (comboBox1.SelectedIndex == 0) return;
  75.             if (comboBox1.SelectedIndex == 1)
  76.             {  
  77.             /*    for (int i = 0; i < checkedListBox1.Items.Count; ++i)
  78.                 {
  79.                     string name = checkedListBox1.Items[i].ToString();
  80.                    
  81.                     for (int j = 0; j < Professions.Count; ++j)
  82.                     {
  83.                         if (Professions[j].GetName() == name)
  84.                         {
  85.                             if (Professions[j].GetFemaleOnly())
  86.                             {                              
  87.                                 checkedListBox1.SetItemChecked(i, false);
  88.                                 checkedListBox1.SetItemCheckState(i, CheckState.Indeterminate);
  89.                               //  MessageBox.Show(checkedListBox1.SelectedItems.Count.ToString());
  90.                             }
  91.                             if (Professions[j].GetMaleOnly())
  92.                             {
  93.                                 checkedListBox1.SetItemCheckState(i, CheckState.Unchecked);
  94.                             }
  95.                         }
  96.                     }
  97.                 }*/
  98.                
  99.  
  100.                 for (int i = 0; i < listView2.Items.Count; ++i)
  101.                 {
  102.                    
  103.                     string name = listView2.Items[i].Text;
  104.                     MessageBox.Show(name);
  105.                     for (int j = 0; j < Professions.Count; ++j)
  106.                     {
  107.                         if (Professions[j].GetName() == name)
  108.                         {
  109.                             if (Professions[j].GetFemaleOnly())
  110.                             {
  111.                                
  112.                                 listView2.Items[i].Checked = false;
  113.                                 listView2.Items[i].ForeColor = Color.LightGray;
  114.  
  115.  
  116.                                 //listView2.SetItemCheckState(i, CheckState.Indeterminate);
  117.                                 //  MessageBox.Show(checkedListBox1.SelectedItems.Count.ToString());
  118.                             }
  119.                             if (Professions[j].GetMaleOnly())
  120.                             {
  121.                                 listView2.Items[i].Checked = false;
  122.                                 listView2.Items[i].ForeColor = Color.Black;
  123.                                 //checkedListBox1.SetItemCheckState(i, CheckState.Unchecked);
  124.                             }
  125.                         }
  126.                     }
  127.                 }
  128.                 return;
  129.             }
  130.             if (comboBox1.SelectedIndex == 2)
  131.             {
  132.                 for (int i = 0; i < checkedListBox1.Items.Count; ++i)
  133.                 {
  134.                     string name = checkedListBox1.Items[i].ToString();
  135.  
  136.                     for (int j = 0; j < Professions.Count; ++j)
  137.                     {
  138.                         if (Professions[j].GetName() == name)
  139.                         {
  140.                             if (Professions[j].GetMaleOnly())
  141.                             {
  142.                                 checkedListBox1.SetItemChecked(i, false);
  143.                                 checkedListBox1.SetItemCheckState(i, CheckState.Indeterminate);
  144.                             }
  145.                             if (Professions[j].GetFemaleOnly())
  146.                             {
  147.                                 checkedListBox1.SetItemCheckState(i, CheckState.Unchecked);
  148.                             }
  149.                         }
  150.                     }
  151.                 }
  152.                 return;
  153.             }
  154.         }
  155.  
  156.         private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
  157.         {
  158.             if (comboBox1.SelectedIndex == 1)
  159.             {
  160.                 for (int i = 0; i < Professions.Count; ++i)
  161.                 {
  162.                     if (Professions[i].GetFemaleOnly())
  163.                     {
  164.                         if (Professions[i].GetName() == checkedListBox1.Items[e.Index].ToString())
  165.                         {
  166.                             e.NewValue = CheckState.Indeterminate;//e.CurrentValue;
  167.                        
  168.                         }
  169.                     }
  170.                 }
  171.             }
  172.             //if (e.NewValue == CheckState.Indeterminate) return;
  173.             if (e.CurrentValue == CheckState.Indeterminate) return;
  174.             if (e.NewValue.ToString() == "Checked")
  175.             {
  176.                 double cur = double.Parse(label1.Text);
  177.                 int intcur = (int)(cur * 100);
  178.                 int curcost = 0;
  179.                 for (int i = 0; i < Professions.Count; ++i)
  180.                 {
  181.                     if (Professions[i].GetName() == checkedListBox1.Items[e.Index].ToString())
  182.                     {
  183.                         curcost = Professions[i].GetCost();
  184.                     }
  185.                 }
  186.                 intcur += curcost;
  187.                 cur = (double)intcur / 100.0;
  188.                 label1.Text = cur.ToString();
  189.             }
  190.             else
  191.             {
  192.                 double cur = double.Parse(label1.Text);
  193.                 int intcur = (int)(cur * 100);
  194.                 int curcost = 0;
  195.                 for (int i = 0; i < Professions.Count; ++i)
  196.                 {
  197.                     if (Professions[i].GetName() == checkedListBox1.Items[e.Index].ToString())
  198.                     {
  199.                         curcost = Professions[i].GetCost();
  200.                     }
  201.                 }
  202.                 intcur -= curcost;
  203.                 intcur = Math.Max(intcur, 0);
  204.                 cur = (double)intcur / 100.0;
  205.                 label1.Text = cur.ToString();
  206.             }
  207.         }
  208.  
  209.         private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
  210.         {
  211.             bool[] used = new bool[500];
  212.             int ck = comboBox2.SelectedIndex;
  213.             int prof_id = -1;
  214.             for(int i = 0 ; i < Client_jobs.Count ; ++i){
  215.                 if(Client_jobs[i].GetName() == comboBox2.Items[ck].ToString()){
  216.                     prof_id = Client_jobs[i].GetId();
  217.                     break;
  218.                 }
  219.             }
  220.             for (int i = 0; i < Professional_inspections.Count; ++i)
  221.             {
  222.                 if (Professional_inspections[i].GetClientProfessionId() == prof_id)
  223.                 {
  224.                     string p = "";
  225.                     for(int j = 0 ; j < Professions.Count ; ++j){
  226.                         if(Professions[j].GetId() == Professional_inspections[i].GetDoctorProfessionId())
  227.                             p = Professions[j].GetName();
  228.                     }
  229.  
  230.                     /*
  231.                     for (int j = 0; j < checkedListBox1.Items.Count; ++j)
  232.                     {
  233.                         if (checkedListBox1.Items[j].ToString() == p)
  234.                         {
  235.                             checkedListBox1.SetItemChecked(j, true);
  236.                             used[j] = true;
  237.                         }
  238.                     }*/
  239.                     for (int j = 0; j < listView2.Items.Count; ++j)
  240.                     {
  241.                         if (listView2.Items[j].Text == p)
  242.                         {
  243.                             listView2.Items[j].Checked = used[j] = true;
  244.                         }
  245.                     }
  246.                 }
  247.             }
  248.             for (int i = 0; i < listView2.Items.Count; ++i)
  249.             {
  250.                 if (used[i] == false)
  251.                 {
  252.                     listView2.Items[i].Checked = false;
  253.                 }
  254.             }
  255.         }
  256.  
  257.         private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
  258.         {
  259.             bool[] used = new bool[500];
  260.             int ck = comboBox3.SelectedIndex;
  261.             int gen_id = -1;
  262.             for (int i = 0; i < General_inspections.Count; ++i)
  263.             {
  264.                 if (General_inspections[i].GetName() == comboBox3.Items[ck].ToString())
  265.                 {
  266.                     gen_id = General_inspections[i].GetId();
  267.                     break;
  268.                 }
  269.             }
  270.             for (int i = 0; i < General_doctors.Count; ++i)
  271.             {
  272.                 if (General_doctors[i].GetGeneralInspectionId() == gen_id)
  273.                 {
  274.                     string p = "";
  275.                     for (int j = 0; j < Professions.Count; ++j)
  276.                     {
  277.                         if (Professions[j].GetId() == General_doctors[i].GetProfessionId())
  278.                             p = Professions[j].GetName();
  279.                     }
  280.                     for (int j = 0; j < checkedListBox1.Items.Count; ++j)
  281.                     {
  282.                         if (checkedListBox1.Items[j].ToString() == p)
  283.                         {
  284.                             checkedListBox1.SetItemChecked(j, true);
  285.                             used[j] = true;
  286.                         }
  287.                     }
  288.                 }
  289.             }
  290.             for (int i = 0; i < checkedListBox1.Items.Count; ++i)
  291.             {
  292.                 if (used[i] == false)
  293.                 {
  294.                     checkedListBox1.SetItemChecked(i, false);
  295.                 }
  296.             }
  297.         }
  298.  
  299.         private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
  300.         {
  301.             if (string.IsNullOrEmpty(e.Label))
  302.             {
  303.                 e.CancelEdit = true;
  304.                 return;
  305.             }
  306.             try
  307.             {
  308.                 double nw;
  309.                 nw = double.Parse(e.Label);
  310.                 nw *= 100;
  311.                 int nwi = (int)nw;
  312.                 if ((double)nwi == nw) return;
  313.                 e.CancelEdit = true;
  314.                 MessageBox.Show("Введеное значение неверно!");
  315.             }
  316.             catch
  317.             {
  318.                 e.CancelEdit = true;
  319.                 MessageBox.Show("Введеное значение неверно!");
  320.             }
  321.            
  322.         }
  323.  
  324.         private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
  325.         {
  326.  
  327.         }
  328.  
  329.         private void checkedListBox1_SelectedValueChanged(object sender, EventArgs e)
  330.         {
  331.           //  listView1.SelectedIndices.Add(checkedListBox1.SelectedIndex);
  332.         }
  333.         bool selectflag = false;
  334.         private void listView2_SelectedIndexChanged(object sender, EventArgs e)
  335.         {
  336.             selectflag = false;
  337.             listView1.SelectedIndices.Clear();
  338.             foreach (int ind in listView2.SelectedIndices)
  339.             {
  340.                 listView1.SelectedIndices.Add(ind);
  341.             }
  342.             selectflag = true;
  343.         }
  344.  
  345.         private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  346.         {
  347.             if (selectflag == false) return;
  348.  
  349.             listView2.SelectedIndices.Clear();
  350.             foreach (int ind in listView1.SelectedIndices)
  351.             {
  352.                 listView2.SelectedIndices.Add(ind);
  353.             }
  354.         }
  355.  
  356.         private void listView2_ItemCheck(object sender, ItemCheckEventArgs e)
  357.         {
  358.             if (listView2.Items[e.Index].ForeColor == Color.LightGray)
  359.             {
  360.                 e.NewValue = CheckState.Unchecked;
  361.             }
  362.         }
  363.     }
  364. }
Add Comment
Please, Sign In to add comment