Esempio n. 1
0
        private void button2Ok_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;

            Applications  apl        = (Applications) new Applications().findByID(index);
            List <string> countEquip = new List <string>();

            countEquip.Add("");
            List <Equipments> equipm = new List <Equipments>();

            int flag1 = 0;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1[1, i].Value.ToString() == "True")
                {
                    Equipments equi = (Equipments) new Equipments().findByID(Convert.ToInt32(dataGridView1[3, i].Value.ToString()));
                    if (countEquip[0] != "")
                    {
                        countEquip[0] = countEquip[0] + "," + dataGridView1[2, i].Value.ToString();
                    }
                    else
                    {
                        countEquip[0] = dataGridView1[2, i].Value.ToString();
                    }
                    equipm.Add(equi);
                    flag1++;
                    continue;
                }
            }

            List <object> fields = new Fields().findByName(comboBox1.GetItemText(comboBox1.SelectedItem));
            Fields        fiel   = (Fields)fields[0];

            List <object> repairs = new Repairs().findByName(comboBox2.GetItemText(comboBox2.SelectedItem));
            Repairs       repair  = (Repairs)repairs[0];

            string se = textBox1.Text;

            string[]      mas     = se.Split(' ');
            List <object> chel    = new Employees().findByName(mas[0]);
            Employees     senderr = new Employees();

            foreach (object ch in chel)
            {
                Employees chelk = (Employees)ch;
                if (chelk.surname == mas[2])
                {
                    senderr = chelk;
                }
            }

            List <Employees> elp = new List <Employees>();
            int flag2            = 0;

            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                if (dataGridView2[3, i].Value.ToString() == "True")
                {
                    Employees epn = (Employees) new Employees().findByID(Convert.ToInt32(dataGridView2[4, i].Value.ToString()));
                    elp.Add(epn);
                    flag2++;
                    continue;
                }
            }

            DateTime start = dateTimePicker1.Value;
            DateTime end   = dateTimePicker2.Value;

            if ((flag2 == 0) || (flag1 == 0) || (insp.isValid1(solution.Text) == false) || (insp.isValid2(textBox3.Text) == false))
            {
                MessageBox.Show("Поля не могут быть пустыми.\nТаблицы оборудования и техников должны быть заполнены.\nПоле 'Фактическая сумма по заявке' должно содержать только цифры.\nПоле 'Комментарий' должно содержать только символы кириллицы.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                DialogResult = DialogResult.None;
            }
            else
            {
                Application_ ion_ = new Application_();

                string co = "";
                foreach (string c in countEquip)
                {
                    if (co == "")
                    {
                        co = co + c;
                    }
                    else
                    {
                        co = co + "," + c;
                    }
                }

                decimal sumNom = 0;
                foreach (Equipments eq in equipm)
                {
                    sumNom = sumNom + eq.price;
                }

                try
                {
                    ion_.ID        = apl.ID;
                    ion_.WasDel    = 0;
                    ion_.comment   = solution.Text;
                    ion_.equipment = equipm;
                    ion_.count     = co;
                    ion_.field     = fiel;
                    ion_.finish    = dateTimePicker2.Value;
                    ion_.performed = Convert.ToInt32(radioButton1.Checked);
                    ion_.repair    = repair;

                    string        ser      = textBox1.Text;
                    string[]      masi     = ser.Split(' ');
                    List <object> chel1    = new Employees().findByName(masi[0]);
                    Employees     senderr5 = new Employees();
                    foreach (object ch in chel1)
                    {
                        Employees chelk = (Employees)ch;
                        if (chelk.surname == mas[2])
                        {
                            senderr5 = chelk;
                        }
                    }

                    ion_.SenderOfApplication = senderr5;
                    ion_.start        = dateTimePicker1.Value;
                    ion_.sumReal      = Convert.ToDecimal(textBox3.Text);
                    ion_.sumNominal   = sumNom;
                    ion_.technicians  = elp;
                    ion_.wasEdit      = 1;
                    ion_.wasPerformed = Convert.ToInt32(radioButton2.Checked);

                    this.mi = ion_;
                    mi.ID   = index;

                    ion_.edit();
                }
                catch
                {
                    MessageBox.Show("Введены некорректные данные. Попробуйте снова.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    DialogResult = DialogResult.None;
                }


                this.Close();
            }
        }
Esempio n. 2
0
        public List <Applications> getApplicationsListOnDate(Application_ start, Application_ finish)
        // дописать типы см.ниже
        {
            List <Applications>      List = new List <Applications>();
            ConnectionStringSettings conString;

            conString = ConfigurationManager.ConnectionStrings["MySQLConStr"];
            using (MySqlConnection con = new MySqlConnection(conString.ConnectionString))
            {
                string queryString = @"SELECT * FROM " + this.tableName_ + " WHERE start BETWEEN @dateS AND @dateF";
                con.Open();
                MySqlCommand cmd = new MySqlCommand(queryString, con);
                cmd.Parameters.AddWithValue("@dateS", start.start.Date);
                cmd.Parameters.AddWithValue("@dateF", finish.start.Date);
                MySqlDataReader result = cmd.ExecuteReader();

                if (result.HasRows)
                {
                    while (result.Read())
                    {
                        Applications application = new Applications();

                        foreach (var prop in this.GetType().GetProperties())
                        {
                            if (prop.Name == "tableName")
                            {
                                continue;
                            }
                            PropertyInfo propertyInfo = this.GetType().GetProperty(prop.Name);
                            string       NameResult;

                            if (propertyInfo.PropertyType.Name == "Int32")
                            {
                                NameResult = propertyInfo.Name;
                                propertyInfo.SetValue(application, Convert.ChangeType(result.GetInt32(NameResult), propertyInfo.PropertyType), null);
                            }
                            else
                            {
                                if (propertyInfo.PropertyType.Name == "String")
                                {
                                    NameResult = propertyInfo.Name;

                                    if (NameResult != "tableName_")
                                    {
                                        propertyInfo.SetValue(application, Convert.ChangeType(result.GetString(NameResult), propertyInfo.PropertyType), null);
                                    }
                                }

                                if (propertyInfo.PropertyType.Name == "Fields")
                                {
                                    application.field = (Fields) new Fields().findByID(result.GetInt32(propertyInfo.Name));
                                }

                                if (propertyInfo.PropertyType.Name == "Repairs")
                                {
                                    application.repair = (Repairs) new Repairs().findByID(result.GetInt32(propertyInfo.Name));
                                }

                                if (propertyInfo.PropertyType.Name == "Employees")
                                {
                                    application.SenderOfApplication = (Employees) new Employees().findByID(result.GetInt32(propertyInfo.Name));
                                }

                                if (propertyInfo.PropertyType.Name == "DateTime")
                                {
                                    NameResult = propertyInfo.Name;
                                    propertyInfo.SetValue(application, Convert.ChangeType(result.GetString(NameResult), propertyInfo.PropertyType), null);
                                }

                                if (propertyInfo.PropertyType.Name == "Decimal")
                                {
                                    NameResult = propertyInfo.Name;
                                    propertyInfo.SetValue(application, Convert.ChangeType(result.GetDecimal(NameResult), propertyInfo.PropertyType), null);
                                }

                                if (propertyInfo.PropertyType.Name == "List`1")
                                {
                                    NameResult = propertyInfo.Name;
                                    string   s   = result.GetString(NameResult);
                                    string[] mas = s.Split(',');
                                    if (propertyInfo.Name == "equipment")
                                    {
                                        List <Equipments> e = new List <Equipments>();
                                        foreach (string val in mas)
                                        {
                                            Equipments eq = (Equipments) new Equipments().findByID(Convert.ToInt32(val));
                                            e.Add(eq);
                                        }
                                        application.equipment = e;
                                    }

                                    else
                                    {
                                        if (propertyInfo.Name != "count")
                                        {
                                            List <Employees> e = new List <Employees>();
                                            foreach (string val in mas)
                                            {
                                                Employees emp = (Employees) new Employees().findByID(Convert.ToInt32(val));
                                                e.Add(emp);
                                            }
                                            application.technicians = e;
                                        }
                                        ///////////////////////////////////////else
                                    }
                                }
                            }
                        }
                        List.Add(application);
                    }
                }
            }
            return(List);
        }
Esempio n. 3
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.CurrentCell.ColumnIndex == 5) // список оборудования
            {
                EquipList         el        = new EquipList();
                Applications      apl       = (Applications) new Applications().findByID(Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
                List <Equipments> equipList = apl.equipment;
                string[]          mas       = apl.count.Split(',');
                int nom    = 0;
                int nomber = 0;
                for (int k = 0; k < equipList.Count; k++)
                {
                    nomber++;
                    nom = k;
                    el.dataGridView1.Rows.Add(nomber, equipList[k].name_, mas[nom]);
                }
                el.ShowDialog();
            }
            if (dataGridView1.CurrentCell.ColumnIndex == 6) // редактировать
            {
                if ((flag_ == 1) || (flag_ == 2))
                {
                    MessageBox.Show("Недостаточно прав.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    DialogResult = DialogResult.None;
                }
                else
                {
                    Applic aplForm = new Applic();

                    aplForm.dataGridView1.Rows.Clear();

                    Equipment     ej   = new Equipment();
                    Equipment     m    = new Equipment();
                    List <object> list = new Equipments().getList(ej, m);
                    foreach (object appl in list)
                    {
                        Equipments obj = (Equipments)appl;
                        if (obj.WasDel != 1)
                        {
                            aplForm.dataGridView1.Rows.Add(obj.name_, false, obj.count, obj.ID);
                        }
                    }
                    aplForm.dataGridView1.Columns[3].Visible = false;
                    aplForm.comboBox2.Items.Clear();

                    aplForm.dataGridView2.Rows.Clear();
                    Employee      er     = new Employee();
                    Employee      mu     = new Employee();
                    List <object> list_t = new Employees().getList(er, mu);
                    foreach (object appl in list_t)
                    {
                        Employees obj = (Employees)appl;
                        if (obj.WasDel != 1)
                        {
                            aplForm.dataGridView2.Rows.Add(obj.surname, obj.name_, obj.middleName, false, obj.ID);
                        }
                    }
                    aplForm.dataGridView2.Columns[4].Visible = false;

                    Repair        r1      = new Repair();
                    Repair        r2      = new Repair();
                    List <object> repairs = new Repairs().getList(r1, r2);
                    foreach (object o in repairs)
                    {
                        Repairs rep = (Repairs)o;
                        if (rep.WasDel != 1)
                        {
                            aplForm.comboBox2.Items.Add(rep.name_);
                        }
                    }

                    aplForm.comboBox1.Items.Clear();

                    Field         f1     = new Field();
                    Field         f2     = new Field();
                    List <object> fields = new Fields().getList(f1, f2);
                    foreach (object fiel in fields)
                    {
                        Fields fielh = (Fields)fiel;
                        if (fielh.WasDel != 1)
                        {
                            aplForm.comboBox1.Items.Add(fielh.name_);
                        }
                    }


                    aplForm.comboBox2.Items.Add(dataGridView1.CurrentRow.Cells[4].Value.ToString());
                    aplForm.comboBox1.Items.Add(dataGridView1.CurrentRow.Cells[1].Value.ToString());

                    aplForm.comboBox1.SelectedIndex = aplForm.comboBox1.FindStringExact(dataGridView1.CurrentRow.Cells[1].Value.ToString());
                    aplForm.comboBox2.SelectedIndex = aplForm.comboBox2.FindStringExact(dataGridView1.CurrentRow.Cells[4].Value.ToString());

                    EquipList    el  = new EquipList();
                    Applications apl = (Applications) new Applications().findByID(Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString()));

                    List <Equipments> equipList = apl.equipment;
                    string[]          mas       = apl.count.Split(',');
                    int fl = -1;
                    for (int y = 0; y < equipList.Count; y++)
                    {
                        for (int i = 0; i < aplForm.dataGridView1.RowCount; i++)
                        {
                            if (aplForm.dataGridView1[0, i].FormattedValue.ToString().Contains(equipList[y].name_))
                            {
                                fl++;
                                aplForm.dataGridView1[1, i].Value = true;

                                aplForm.dataGridView1[2, i].Value = mas[fl];
                            }
                        }
                    }

                    List <Employees> techList = apl.technicians;
                    for (int y = 0; y < techList.Count; y++)
                    {
                        if (techList[y].WasDel == 1)
                        {
                            aplForm.dataGridView2.Rows.Add(techList[y].surname, techList[y].name_, techList[y].middleName, true, techList[y].ID);
                        }

                        for (int i = 0; i < aplForm.dataGridView2.RowCount; i++)
                        {
                            if (aplForm.dataGridView2[0, i].FormattedValue.ToString().Contains(techList[y].surname))
                            {
                                aplForm.dataGridView2[3, i].Value = true;
                            }
                        }
                    }

                    string send = apl.SenderOfApplication.name_ + " " + apl.SenderOfApplication.middleName + " " + apl.SenderOfApplication.surname;
                    aplForm.textBox1.Text = send;


                    if (apl.performed == 1)
                    {
                        aplForm.radioButton1.Checked = true;
                        aplForm.radioButton2.Checked = false;
                    }

                    if (apl.wasPerformed == 1)
                    {
                        aplForm.radioButton1.Checked = false;
                        aplForm.radioButton2.Checked = true;
                    }

                    decimal sum = 0;
                    foreach (Equipments eq in equipList)
                    {
                        string v = eq.price.ToString();
                        sum = Convert.ToDecimal(sum + Convert.ToDecimal(v));
                    }
                    sum = sum + apl.repair.price;
                    aplForm.textBox2.Text         = sum.ToString();
                    aplForm.textBox3.Text         = apl.sumReal.ToString();
                    aplForm.dateTimePicker1.Value = apl.start;
                    aplForm.dateTimePicker2.Value = apl.finish;
                    aplForm.solution.Text         = apl.comment;

                    aplForm.index = apl.ID;

                    aplForm.ShowDialog();

                    if (aplForm.DialogResult == DialogResult.OK)
                    {
                        GetTable();
                    }
                }
            }

            if (dataGridView1.CurrentCell.ColumnIndex == 7) // удалить
            {
                if ((flag_ == 1) || (flag_ == 2))
                {
                    MessageBox.Show("Недостаточно прав.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    DialogResult = DialogResult.None;
                }
                else
                {
                    if (MessageBox.Show("Вы уверены? Данные будут удалены без возможности восстановления.", "Внимание!", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
                    {
                        int          id  = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                        Applications cut = (Applications) new Applications().findByID(id);

                        List <string> equipm = new List <string>();
                        foreach (Equipments g in cut.equipment)
                        {
                            equipm.Add(g.ID.ToString());
                        }

                        List <string> techn = new List <string>();
                        foreach (Employees m in cut.technicians)
                        {
                            techn.Add(m.ID.ToString());
                        }
                        Application_ a = new Application_();
                        a.ID = cut.ID;
                        a.del();
                        GetTable();
                    }
                }
            }
        }