Example #1
0
        //public static bool isValid1(string str)
        //{
        //    string pattern = "^[а-яА-Я]";
        //    Match isMatch = Regex.Match(str, pattern, RegexOptions.IgnoreCase);
        //    return isMatch.Success;
        //}
        //public static bool isValid2(string str)
        //{
        //    string pattern = @"^[\s+,+\d]*$";
        //    Match isMatch = Regex.Match(str, pattern, RegexOptions.IgnoreCase);
        //    return isMatch.Success;
        //}

        private void button2Ok_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            if (insp.isValid1(textBox1.Text) && insp.isValid2(textBox2.Text))
            {
                Equipments equipm  = (Equipments) new Equipments().findByID(index);
                Equipment  equipm_ = new Equipment(equipm.ID, textBox1.Text, Convert.ToDecimal(textBox2.Text), 0, 1);
                equipm_.edit();
                this.Close();
            }
            else
            {
                MessageBox.Show("Поля не могут быть пустыми.\nПоле 'Название' может содержать только символы кириллицы.\nПоле 'Стоимость' может содержать только цифры.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                DialogResult = DialogResult.None;
            }
        }
Example #2
0
        private void GetTable()
        {
            dataGridView1.Rows.Clear();

            Equipment     e    = new Equipment();
            Equipment     m    = new Equipment();
            List <object> list = new Equipments().getList(e, m);

            foreach (object equipment in list)
            {
                Equipments obj = (Equipments)equipment;
                if (obj.WasDel != 1)
                {
                    dataGridView1.Rows.Add(Convert.ToString(obj.ID), obj.name_, obj.price, "Редактировать", "Удалить");
                }
            }
        }
Example #3
0
        public CreateReport()
        {
            InitializeComponent();
            this.checkedListBox1.CheckOnClick = true;
            this.checkedListBox2.CheckOnClick = true;
            this.checkedListBox3.CheckOnClick = true;

            Field         f      = new Field();
            Field         s      = new Field();
            List <object> fields = new Fields().getList(f, s);

            foreach (object field in fields)
            {
                Fields fi = (Fields)field;
                if (fi.WasDel != 1)
                {
                    checkedListBox1.Items.Add(fi.name_, false);
                }
            }

            Equipment     q          = new Equipment();
            Equipment     h          = new Equipment();
            List <object> equipments = new Equipments().getList(q, h);

            foreach (object equipment in equipments)
            {
                Equipments fi = (Equipments)equipment;
                if (fi.WasDel != 1)
                {
                    checkedListBox2.Items.Add(fi.name_, false);
                }
            }

            Repair        r       = new Repair();
            Repair        p       = new Repair();
            List <object> repairs = new Repairs().getList(r, p);

            foreach (object repair in repairs)
            {
                Repairs fi = (Repairs)repair;
                if (fi.WasDel != 1)
                {
                    checkedListBox3.Items.Add(fi.name_, false);
                }
            }
        }
Example #4
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.CurrentCell.ColumnIndex == 3) // редактировать
            {
                if ((flag_ == 2) || (flag_ == 3))
                {
                    MessageBox.Show("Недостаточно прав.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    DialogResult = DialogResult.None;
                }
                else
                {
                    EquipForm equipForm = new EquipForm();
                    equipForm.textBox1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
                    equipForm.textBox2.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
                    equipForm.index         = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                    equipForm.ShowDialog();
                    if (equipForm.DialogResult == DialogResult.OK)
                    {
                        GetTable();
                    }
                }
            }

            if (dataGridView1.CurrentCell.ColumnIndex == 4) // удалить
            {
                if ((flag_ == 2) || (flag_ == 3))
                {
                    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());
                        Equipments cut = (Equipments) new Equipments().findByID(id);
                        // перезапись из Equipments в Equipment, чтобы пометить на удаление
                        Equipment equipm = new Equipment(cut.ID, cut.name_, cut.price, 1, 1);
                        equipm.edit();
                        GetTable();
                    }
                }
            }
        }
Example #5
0
        public Application_(string id, string wasDel, string comment, List <string> equipment,
                            string field, string finish, string performed, string repair, string sender, string start,
                            string SumReal, string sumNominal, List <string> technicians, string wasEdit, string WasPerformed, string count)
        {
            Equipments eq  = new Equipments();
            Fields     f   = new Fields();
            Employees  emp = new Employees();
            Repairs    r   = new Repairs();

            List <Equipments> equip = new List <Equipments>();
            List <Employees>  empls = new List <Employees>();

            this.ID      = Convert.ToInt32(id);
            this.WasDel  = Convert.ToInt32(wasDel);
            this.comment = comment;

            foreach (string s in equipment)
            {
                equip.Add((Equipments) new Equipments().findByID(Convert.ToInt32(s)));
            }
            this.equipment = equip;

            this.field               = (Fields)f.findByID(Convert.ToInt32(field));
            this.finish              = Convert.ToDateTime(finish).Date;
            this.wasPerformed        = Convert.ToInt32(performed);
            this.repair              = (Repairs)r.findByID(Convert.ToInt32(repair));
            this.SenderOfApplication = (Employees)emp.findByID(Convert.ToInt32(sender));
            this.start               = Convert.ToDateTime(start).Date;
            this.sumReal             = Convert.ToDecimal(SumReal);
            this.sumNominal          = Convert.ToDecimal(sumNominal);

            foreach (string e in technicians)
            {
                empls.Add((Employees) new Employees().findByID(Convert.ToInt32(e)));
            }
            this.technicians  = empls;
            this.wasEdit      = Convert.ToInt32(wasEdit);
            this.wasPerformed = wasPerformed;
            this.count        = count;

            this.tableName_ = "applications";
        }
Example #6
0
        public virtual List <object> getList(object filter, object sorting)
        {
            List <string> valuesFilter  = new List <string>();
            List <string> valuesSorting = new List <string>();
            List <object> ListObjects   = new List <object>();

            ConnectionStringSettings conString;

            conString = ConfigurationManager.ConnectionStrings["MySQLConStr"];
            using (MySqlConnection con = new MySqlConnection(conString.ConnectionString))
            {
                con.Open();
                foreach (var prop in filter.GetType().GetProperties())
                {
                    if (prop.Name == "tableName_")
                    {
                        continue;
                    }
                    // -1 это поля, не задействованные в фильтре
                    if ((prop.GetValue(filter) != null) && (prop.GetValue(filter).ToString() != "-1") && (prop.GetValue(filter).ToString() != "01.01.0001 0:00:00"))
                    {
                        try
                        {
                            Fields f = (Fields)prop.GetValue(filter);

                            valuesFilter.Add(prop.Name + "=" + "'" + f.ID + "'");
                            continue;
                        }
                        catch
                        {
                            valuesFilter.Add(prop.Name + "=" + "'" + prop.GetValue(filter) + "'");
                        }
                    }
                }

                foreach (var prop in sorting.GetType().GetProperties())
                {
                    if (prop.Name == "tableName_")
                    {
                        continue;
                    }
                    if ((prop.GetValue(sorting) != null) && (prop.GetValue(sorting).ToString() != "-1") && (prop.GetValue(sorting).ToString() != "01.01.0001 0:00:00"))
                    {
                        valuesSorting.Add(prop.Name);
                    }
                }
                string sql = "";

                try
                {
                    if ((valuesSorting.Count != 0) && (valuesFilter.Count != 0))
                    {
                        sql = @"select * from " + this.tableName_ + " where " + "(" + valuesFilter.Aggregate((workingSQL, next) => next + " and " + workingSQL) + ")" + " order by " + valuesSorting.Aggregate((workingSQL, next) => next + ", " + workingSQL);
                    }
                    else
                    {
                        if ((valuesSorting.Count != 0) && (valuesFilter.Count == 0))
                        {
                            sql = @"select * from " + this.tableName_ + " order by " + valuesSorting.Aggregate((workingSQL, next) => next + ", " + workingSQL);
                        }

                        if ((valuesSorting.Count == 0) && (valuesFilter.Count != 0))
                        {
                            sql = @"select * from " + this.tableName_ + " where " + "(" + valuesFilter.Aggregate((workingSQL, next) => next + " and " + workingSQL) + ")";
                        }
                    }
                }

                catch { sql = @"select * from " + this.tableName_; }

                if (sql == "")
                {
                    sql = @"select * from " + this.tableName_;
                }

                MySqlCommand    cmd    = new MySqlCommand(sql, con);
                MySqlDataReader result = cmd.ExecuteReader();
                Type            t      = this.GetType();

                if (result.HasRows)
                {
                    while (result.Read())
                    {
                        var SomeObject = Activator.CreateInstance(t);

                        List <Equipments> elp         = new List <Equipments>();
                        PropertyInfo      equipments_ = this.GetType().GetProperty("equipment");

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


                            string NameResult;

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

                                    if (NameResult != "tableName_")
                                    {
                                        propertyInfo.SetValue(SomeObject, Convert.ChangeType(result.GetString(NameResult), propertyInfo.PropertyType), null);
                                    }
                                }
                                if (propertyInfo.PropertyType.Name == "Fields")
                                {
                                    Fields f = (Fields) new Fields().findByID(result.GetInt32(propertyInfo.Name));
                                    propertyInfo.SetValue(SomeObject, Convert.ChangeType(f, propertyInfo.PropertyType), null);
                                }

                                if (propertyInfo.PropertyType.Name == "Repairs")
                                {
                                    Repairs r = (Repairs) new Repairs().findByID(result.GetInt32(propertyInfo.Name));
                                    propertyInfo.SetValue(SomeObject, Convert.ChangeType(r, propertyInfo.PropertyType), null);
                                }

                                if (propertyInfo.PropertyType.Name == "Employees")
                                {
                                    Employees ep = (Employees) new Employees().findByID(result.GetInt32(propertyInfo.Name));
                                    propertyInfo.SetValue(SomeObject, Convert.ChangeType(ep, propertyInfo.PropertyType), null);
                                }

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

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

                                if (propertyInfo.PropertyType.Name == "List`1")
                                {
                                    string   s   = result.GetString(propertyInfo.Name);
                                    string[] mas = s.Split(',');


                                    if (propertyInfo.Name == "equipment")
                                    {
                                        foreach (string val in mas)
                                        {
                                            Equipments eq = (Equipments) new Equipments().findByID(Convert.ToInt32(val));
                                            elp.Add(eq);
                                        }
                                        propertyInfo.SetValue(SomeObject, Convert.ChangeType(elp, propertyInfo.PropertyType), null);
                                    }

                                    else
                                    {
                                        if (propertyInfo.Name != "count")
                                        {
                                            List <Employees> ed = new List <Employees>();
                                            foreach (string val in mas)
                                            {
                                                Employees emp = (Employees) new Employees().findByID(Convert.ToInt32(val));
                                                ed.Add(emp);
                                            }
                                            propertyInfo.SetValue(SomeObject, Convert.ChangeType(ed, propertyInfo.PropertyType), null);
                                        }

                                        if (propertyInfo.Name == "count")
                                        {
                                            List <string> countSt = new List <string>();
                                            string        countt  = "";
                                            foreach (string val in mas)
                                            {
                                                if (countt == "")
                                                {
                                                    countt = countt + val;
                                                }
                                                else
                                                {
                                                    countt = countt + ", " + val;
                                                }
                                            }
                                            propertyInfo.SetValue(SomeObject, Convert.ChangeType(countt, propertyInfo.PropertyType), null);
                                        }
                                    }
                                }
                            }
                        }
                        ListObjects.Add(SomeObject);
                    }
                }
            }
            return(ListObjects);
        }
Example #7
0
        public virtual object findByID(int id)
        {
            ConnectionStringSettings conString;

            conString = ConfigurationManager.ConnectionStrings["MySQLConStr"];
            using (MySqlConnection con = new MySqlConnection(conString.ConnectionString))
            {
                string queryString = @"SELECT * FROM " + this.tableName_ + " WHERE id=" + id;
                con.Open();
                MySqlCommand cmd = new MySqlCommand(queryString, con);

                MySqlDataReader result = cmd.ExecuteReader();

                if (result.HasRows)
                {
                    result.Read();

                    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 == "Fields")
                        {
                            Fields f = (Fields) new Fields().findByID(result.GetInt32(propertyInfo.Name));
                            propertyInfo.SetValue(this, Convert.ChangeType(f, propertyInfo.PropertyType), null);
                        }

                        if (propertyInfo.PropertyType.Name == "Repairs")
                        {
                            Repairs r = (Repairs) new Repairs().findByID(result.GetInt32(propertyInfo.Name));
                            propertyInfo.SetValue(this, Convert.ChangeType(r, propertyInfo.PropertyType), null);
                        }

                        if (propertyInfo.PropertyType.Name == "Employees")
                        {
                            Employees e = (Employees) new Employees().findByID(result.GetInt32(propertyInfo.Name));
                            propertyInfo.SetValue(this, Convert.ChangeType(e, propertyInfo.PropertyType), null);
                        }

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

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


                        if (propertyInfo.PropertyType.Name == "List`1")
                        {
                            string   s   = result.GetString(propertyInfo.Name);
                            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);
                                }
                                propertyInfo.SetValue(this, Convert.ChangeType(e, propertyInfo.PropertyType), null);
                            }

                            else
                            {
                                List <Employees> e = new List <Employees>();
                                foreach (string val in mas)
                                {
                                    Employees emp = (Employees) new Employees().findByID(Convert.ToInt32(val));
                                    e.Add(emp);
                                }
                                propertyInfo.SetValue(this, Convert.ChangeType(e, propertyInfo.PropertyType), null);
                            }
                        }

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

                                if (NameResult != "tableName_")
                                {
                                    propertyInfo.SetValue(this, Convert.ChangeType(result.GetString(NameResult), propertyInfo.PropertyType), null);
                                }
                            }
                        }
                    }
                }
            }
            return(this);
        }
Example #8
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);
        }
Example #9
0
 private void button2Create_Click(object sender, EventArgs e)
 {
     if (radioButton1.Checked == true)
     {
         if ((checkedListBox1.CheckedIndices.Count == 0) && (checkedListBox2.CheckedIndices.Count == 0) && (checkedListBox3.CheckedIndices.Count == 0))
         {
             MessageBox.Show("Фильтр не может быть пустым.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             DialogResult = DialogResult.None;
         }
         else
         {
             this.Hide();
             this.DialogResult = DialogResult.OK;
             Report filter = new Report();
             if (checkedListBox1.CheckedIndices.Count != 0)
             {
                 List <Fields> fis     = new List <Fields>();
                 string        fields_ = "";
                 for (int i = 0; i < checkedListBox1.Items.Count; i++)
                 {
                     if (checkedListBox1.GetItemChecked(i))
                     {
                         if (fields_ != "")
                         {
                             fields_ = fields_ + "," + checkedListBox1.Items[i].ToString();
                         }
                         else
                         {
                             fields_ = checkedListBox1.Items[i].ToString();
                         }
                     }
                 }
                 string[] masField = fields_.Split(',');
                 foreach (string name in masField)
                 {
                     List <object> found = new Fields().findByName(name);
                     foreach (object fo in found)
                     {
                         Fields fie = (Fields)fo;
                         fis.Add(fie);
                     }
                 }
                 filter.field = fis;
             }
             if (checkedListBox2.CheckedIndices.Count != 0)
             {
                 List <Equipments> equi        = new List <Equipments>();
                 string            equipments_ = "";
                 for (int i = 0; i < checkedListBox2.Items.Count; i++)
                 {
                     if (checkedListBox2.GetItemChecked(i))
                     {
                         if (equipments_ != "")
                         {
                             equipments_ = equipments_ + "," + checkedListBox2.Items[i].ToString();
                         }
                         else
                         {
                             equipments_ = checkedListBox2.Items[i].ToString();
                         }
                     }
                 }
                 string[] masEqu = equipments_.Split(',');
                 foreach (string name in masEqu)
                 {
                     List <object> found = new Equipments().findByName(name);
                     foreach (object fo in found)
                     {
                         Equipments fie = (Equipments)fo;
                         equi.Add(fie);
                     }
                 }
                 filter.equipment = equi;
             }
             if (checkedListBox3.CheckedIndices.Count != 0)
             {
                 List <Repairs> rep  = new List <Repairs>();
                 string         rep_ = "";
                 for (int i = 0; i < checkedListBox3.Items.Count; i++)
                 {
                     if (checkedListBox3.GetItemChecked(i))
                     {
                         if (rep_ != "")
                         {
                             rep_ = rep_ + "," + checkedListBox3.Items[i].ToString();
                         }
                         else
                         {
                             rep_ = checkedListBox3.Items[i].ToString();
                         }
                     }
                 }
                 string[] masEqu = rep_.Split(',');
                 foreach (string name in masEqu)
                 {
                     List <object> found = new Repairs().findByName(name);
                     foreach (object fo in found)
                     {
                         Repairs fie = (Repairs)fo;
                         rep.Add(fie);
                     }
                 }
                 filter.repairs = rep;
             }
             List <Report>   reports = new Reports().GetReportsByFilter(filter);
             ReportFilterTab rft     = new ReportFilterTab();
             rft.list = reports;
             this.Close();
             rft.ShowDialog();
         }
     }
     if (radioButton2.Checked == true)
     {
         DateTime start = dateTimePicker1.Value;
         DateTime end   = dateTimePicker2.Value;
         if (start < end)
         {
             this.Hide();
             List <Report>   r   = new Reports().GetReportsByAllApplications(start, end);
             ReportApplicTab rat = new ReportApplicTab();
             rat.list = r;
             rat.ShowDialog();
         }
         else
         {
             MessageBox.Show("Дата начала должна быть меньше даты окончания.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             DialogResult = DialogResult.None;
         }
     }
 }
Example #10
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();
            }
        }
Example #11
0
        public Applic()
        {
            InitializeComponent();

            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;

                comboBox1.Items.Add(fielh.name_);
            }

            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;
                comboBox2.Items.Add(rep.name_);
            }
            comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;

            textBox1.ReadOnly = true;
            textBox2.ReadOnly = true;

            dataGridView1.Rows.Clear();

            Equipment     e    = new Equipment();
            Equipment     m    = new Equipment();
            List <object> list = new Equipments().getList(e, m);

            foreach (object appl in list)
            {
                Equipments obj = (Equipments)appl;
                dataGridView1.Rows.Add(obj.name_, false, obj.count, obj.ID);
            }
            dataGridView1.Columns[3].Visible = false;

            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;
                dataGridView2.Rows.Add(obj.surname, obj.name_, obj.middleName, false, obj.ID);
            }
            dataGridView2.Columns[4].Visible = false;

            comboBox1.SelectedIndex = 1;
            comboBox2.SelectedIndex = 1;

            dataGridView1.AllowUserToAddRows    = false;
            dataGridView1.AllowUserToDeleteRows = false;

            dataGridView2.AllowUserToAddRows    = false;
            dataGridView2.AllowUserToDeleteRows = false;
        }
Example #12
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();
                    }
                }
            }
        }
Example #13
0
        private void button1Create_Click(object sender, EventArgs e)
        {
            if ((flag_ == 1) || (flag_ == 2))
            {
                MessageBox.Show("Недостаточно прав.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                DialogResult = DialogResult.None;
            }
            else
            {
                Applic newap = new Applic();
                newap.flag_ = this.flag_;

                newap.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)
                    {
                        newap.dataGridView1.Rows.Add(obj.name_, false, obj.count, obj.ID);
                    }
                }
                newap.dataGridView1.Columns[3].Visible = false;


                newap.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)
                    {
                        newap.dataGridView2.Rows.Add(obj.surname, obj.name_, obj.middleName, false, obj.ID);
                    }
                }
                newap.dataGridView2.Columns[4].Visible = false;
                newap.comboBox2.Items.Clear();

                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)
                    {
                        newap.comboBox2.Items.Add(rep.name_);
                    }
                }

                newap.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)
                    {
                        newap.comboBox1.Items.Add(fielh.name_);
                    }
                }

                newap.comboBox1.SelectedIndex = 1;
                newap.comboBox2.SelectedIndex = 1;

                newap.textBox1.Text        = textbo.name_ + " " + textbo.middleName + " " + textbo.surname;
                newap.textBox2.Text        = "0";
                newap.radioButton1.Checked = true;
                newap.radioButton2.Checked = false;

                newap.dateTimePicker1.Value = DateTime.Now.AddDays(1);
                newap.dateTimePicker2.Value = DateTime.Now.AddDays(30);
                newap.index = new Applications().getMaxID() + 1;
                newap.ShowDialog();
                if (newap.DialogResult == DialogResult.OK)
                {
                    newap.mi.add();
                    GetTable();
                }
            }
        }