Пример #1
0
 public frmEditPerson(Personnel person)
 {
     InitializeComponent();
     db          = new DataBase();
     calendar    = new PersianCalendar();
     this.person = person;
     if (person != null)
     {
         init();
     }
 }
Пример #2
0
        void init()
        {
            HasHistory = HistoryCheck(change);
            string[] date = calendar.SplitDate(change.getFromDate());
            lblFrom.Text = date[0] + "-" + date[1] + "-";
            txtFrom.Text = date[2];
            if (change.getToDate() != null)
            {
                date       = calendar.SplitDate(change.getToDate());
                lblTo.Text = date[0] + "-" + date[1] + "-";
                txtTo.Text = date[2];
            }
            else
            {
                lblTo.Text = lblFrom.Text;
                txtTo.Text = txtFrom.Text;
            }
            Option3.Text = change.getStatus();
            if (Option3.Text == "R")
            {
                Option3.BackColor = Color.LightPink;
                Option1.BackColor = Color.LightGreen;
                Option2.BackColor = Color.Khaki;
                Option1.Text      = "W";
                Option2.Text      = "A";
            }
            else if (Option3.Text == "W")
            {
                Option3.BackColor = Color.LightGreen;
                Option1.BackColor = Color.LightPink;
                Option2.BackColor = Color.Khaki;
                Option1.Text      = "R";
                Option2.Text      = "A";
            }
            else if (Option3.Text == "A")
            {
                Option3.BackColor = Color.Khaki;
                Option1.BackColor = Color.LightGreen;
                Option2.BackColor = Color.LightPink;
                Option1.Text      = "W";
                Option2.Text      = "R";
            }
            txtReason.Text = change.getReason();
            Personnel person = db.getPerson(change.getPersonId());

            lblName.Text      = person.getName();
            HasChangeToSave   = !HasHistory;
            btnRemove.Visible = HasHistory;
            HasChangeToSave   = false;
        }
Пример #3
0
        public void updatePerson(Personnel person)
        {
            string sql = "UPDATE personnel SET name = '" + person.getName() +
                         "', start = '" + person.getStart() +
                         "', work = " + person.getWork() +
                         ", rest = " + person.getRest() +
                         ", xp_id = " + person.getXpId() +
                         " WHERE id = " + person.getId() + ";";

            connection.Open();
            SQLiteCommand command = new SQLiteCommand(sql, connection);

            command.ExecuteNonQuery();
            connection.Close();
        }
Пример #4
0
        public void addPerson(Personnel person)
        {
            string sql = "INSERT INTO personnel (name, start, work, rest, xp_id) VALUES " +
                         "('" + person.getName() + "', '" +
                         person.getStart() + "', " +
                         person.getWork() + ", " +
                         person.getRest() + ", " +
                         person.getXpId() + ");";

            connection.Open();
            SQLiteCommand command = new SQLiteCommand(sql, connection);

            command.ExecuteNonQuery();
            connection.Close();
        }
Пример #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (HasChangeToSave)
            {
                try
                {
                    if (txtName.Text == "")
                    {
                        Toast("فیلد نام و نام خانوادگی نمیتواند خالی باشد", MessageBoxIcon.Warning);
                    }
                    else if (txtRest.Text == "")
                    {
                        Toast("فیلد تعداد روزهای مرخصی نمیتواند خالی باشد", MessageBoxIcon.Warning);
                    }
                    else if (txtWork.Text == "")
                    {
                        Toast("فیلد تعداد روزهای کاری نمیتواند خالی باشد", MessageBoxIcon.Warning);
                    }
                    else if (txtRDay.Text == "")
                    {
                        Toast("فیلد روز شروع روتیشن نمیتواند خالی باشد", MessageBoxIcon.Warning);
                    }
                    else if (txtRYear.Text == "")
                    {
                        Toast("فیلد سال شروع روتیشن نمیتواند خالی باشد", MessageBoxIcon.Warning);
                    }
                    else if (cbRMonth.Text == "")
                    {
                        Toast("فیلد ماه شروع روتیشن نمیتواند خالی باشد", MessageBoxIcon.Warning);
                    }
                    else if (cbXP.Text == "")
                    {
                        Toast("فیلد تخصص نمیتواند خالی باشد", MessageBoxIcon.Warning);
                    }
                    else
                    {
                        bool itsNew;
                        if (person == null)
                        {
                            person = new Personnel();
                            itsNew = true;
                        }
                        else
                        {
                            itsNew = false;
                        }

                        person.setName(txtName.Text);
                        person.setRest(int.Parse(txtRest.Text));
                        person.setWork(int.Parse(txtWork.Text));
                        person.setStart(txtRYear.Text + "-" + (cbRMonth.SelectedIndex + 1) + "-" + txtRDay.Text);
                        foreach (Expertise xp in xps)
                        {
                            if (xp.getXp() == cbXP.Text)
                            {
                                person.setXpId(xp.getId());
                            }
                        }

                        if (itsNew)
                        {
                            db.addPerson(person);
                        }
                        else
                        {
                            db.updatePerson(person);
                        }

                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
                catch (System.FormatException)
                {
                    Toast("مقدار وارد شده صحیح نیست!", MessageBoxIcon.Warning);
                }
                catch (System.Exception ex)
                {
                    Toast(ex.Message, MessageBoxIcon.Error);
                }
            }
            else
            {
                Toast("تغییری برای ذخیره انجام نشده است!", MessageBoxIcon.Information);
            }
        }