private void Button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count == 0)
            {
                return;
            }

            int id = JobsModel.GetOneJobs(listBox1.SelectedItem.ToString()).First().Id;

            if (id == 0)
            {
                return;
            }

            var employeeByID = MainModel.GetByJobsID(id);

            // Если пользователь привязан к этому ID
            if (employeeByID.Count() != 0)
            {
                MessageBox.Show(
                    "Працівник: " + employeeByID.First().LName + " " + employeeByID.First().FName
                    + " [#" + employeeByID.First().Id + "] - займає цю посаду",
                    "Помилка"
                    );
                return;
            }

            int isDeleted = JobsModel.DeleteObject <JobsTable>(id);

            if (isDeleted == 1)
            {
                listBox1.Items.Remove(listBox1.SelectedItem);
            }
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBox1.Text))
            {
                return;
            }

            if (isEdit)
            {
                int isUpdate = JobsModel.Update(new JobsTable {
                    Id    = JobsModel.GetOneJobs(listBox1.SelectedItem.ToString()).First().Id,
                    Title = textBox1.Text
                });

                if (isUpdate == 1)
                {
                    listBox1.Items.Remove(listBox1.SelectedItem);
                    listBox1.Items.Add(textBox1.Text);
                    textBox1.Text = string.Empty;
                }

                return;
            }

            int isInsert = JobsModel.Insert(new JobsTable
            {
                Title = textBox1.Text
            });

            if (isInsert == 1)
            {
                listBox1.Items.Add(textBox1.Text);
            }
        }
Exemplo n.º 3
0
        public static void AddItems(MainTable mt)
        {
            var    job      = JobsModel.GetOneJobs(mt.JobId);
            string JobTitle = job.Count() > 0 ? job.First().Title : "";

            l.Items.Add(new ListViewItem(new[] {
                T(mt.Id), T(mt.FName), T(mt.LName), T(mt.MName), JobTitle, T(mt.Email),
                T(mt.TelWork), mt.Sex ? "Чоловік" : "Жінка", T(mt.IsActivity),
                T(mt.EmploymentDate), T(mt.UpdateAt)
            }));

            ColorRows(GetCountItems() - 1, mt);
        }
Exemplo n.º 4
0
        public static void UpdateItems(int i, MainTable mt)
        {
            var    job      = JobsModel.GetOneJobs(mt.JobId);
            string JobTitle = job.Count() > 0 ? job.First().Title : "";

            l.Items[i].SubItems[I_FNAME].Text           = T(mt.FName);
            l.Items[i].SubItems[I_MNAME].Text           = T(mt.MName);
            l.Items[i].SubItems[I_LNAME].Text           = T(mt.LName);
            l.Items[i].SubItems[I_JOB_ID].Text          = JobTitle;
            l.Items[i].SubItems[I_SEX].Text             = mt.Sex ? "Чоловік" : "Жінка";
            l.Items[i].SubItems[I_EMAIL].Text           = T(mt.Email);
            l.Items[i].SubItems[I_TEL_WORK].Text        = T(mt.TelWork);
            l.Items[i].SubItems[I_IS_ACTIVITY].Text     = T(mt.IsActivity);
            l.Items[i].SubItems[I_EMPLOYMENT_DATE].Text = T(mt.EmploymentDate);
            l.Items[i].SubItems[I_UPDATE_AT].Text       = T(mt.UpdateAt);

            ColorRows(i, mt);
        }
        public void ExistsEmployee(int id)
        {
            this.id = id;
            Text    = Config.PROJECT_NAME + " - Картка працівника: #" + id;

            MainTable main;

            try
            {
                main = MainModel.GetOneByID(id).First();
            }
            catch { return; }

            var employeesJobID = JobsModel.GetOneJobs(main.JobId);

            // Top
            textBox2.Text  = main.FName;
            textBox1.Text  = main.LName;
            textBox3.Text  = main.MName;
            comboBox1.Text = employeesJobID.Count() != 0 ? employeesJobID.First().Title : "";

            // Middle Main
            textBox9.Text  = main.TimeTableNum.ToString();
            textBox8.Text  = main.IndividualTaxNum.ToString();
            comboBox3.Text = main.Sex ? "Чоловік" : "Жінка";

            textBox5.Text = main.Email;
            textBox6.Text = main.TelWork;
            textBox7.Text = main.TelHome;

            dateTimePicker2.Value = main.EmploymentDate;
            dateTimePicker3.Value = main.DateDismissal;
            dateTimePicker1.Value = main.UpdateAt;

            textBox10.Text = main.Salary.ToString();
            textBox4.Text  = main.About;

            // Bottom
            comboBox2.Text = main.IsActivity ? "Працює" : "Звільнений";

            // Img
            pictureBox1.Image = Employees.GetImage(id);
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            if (isNew)
            {
                id = MainModel.GetCountRecords() + 1;
            }

            int jobID = string.IsNullOrWhiteSpace(comboBox1.Text)
                ? 0
                : JobsModel.GetOneJobs(comboBox1.Text).First().Id;

            bool isCorrectSalary = Double.TryParse(textBox10.Text, out double salary);

            if (!isCorrectSalary)
            {
                MessageBox.Show("Зарплата не вірна");
                return;
            }

            var main = new MainTable
            {
                Id               = id,
                FName            = textBox2.Text, // Top
                MName            = textBox3.Text,
                LName            = textBox1.Text,
                JobId            = jobID,
                TimeTableNum     = textBox9.Text, // Middle Main
                IndividualTaxNum = textBox8.Text,
                Sex              = comboBox3.Text.Equals("Чоловік"),
                EmploymentDate   = dateTimePicker2.Value.Date,
                DateDismissal    = dateTimePicker3.Value.Date,
                UpdateAt         = DateTime.Today,
                Email            = textBox5.Text,
                TelWork          = textBox6.Text,
                TelHome          = textBox7.Text,
                About            = textBox4.Text,
                Salary           = salary,
                IsActivity       = comboBox2.Text.Equals("Працює") // Bottom
            };

            int isUpdated = isNew ? MainModel.Insert(main) : MainModel.Update(main);

            if (isUpdated == 1)
            {
                if (isNew)
                {
                    EmployeesLV.AddOneData(id);
                }
                else
                {
                    EmployeesLV.UpdateOneData(id);
                }

                EmployeesLV.UpdateSelected();
                label19.BackColor = Color.DarkSlateGray;
                label19.Text      = "Збережено";
            }
            else
            {
                label19.BackColor = Color.FromArgb(185, 46, 59);
                label19.Text      = "Не збережено";
            }

            label19.Visible = true;
            timer1.Enabled  = true;
        }