Esempio n. 1
0
        public it_log GetById(int id)
        {
            using (MySqlConnection conn = new MySqlConnection(connStr))
            {
                conn.Open();

                string query = "SELECT * FROM it_log WHERE it_log_id = @id";

                MySqlCommand cmd = new MySqlCommand(query, conn);

                cmd.Parameters.AddWithValue("@id", id);
                cmd.ExecuteNonQuery();

                MySqlDataAdapter da = new MySqlDataAdapter(query, conn);
                DataTable        dt = new DataTable();

                da.Fill(dt);
                conn.Close();

                it_log log = new it_log();
                log.id              = Convert.ToInt32(dt.Rows[0]["it_log_id"]);
                log.Name            = dt.Rows[0]["name"].ToString();
                log.Office          = dt.Rows[0]["office"].ToString();
                log.Date            = Convert.ToDateTime(dt.Rows[0]["date"]);
                log.Time            = TimeSpan.Parse(dt.Rows[0]["time"].ToString());
                log.Service_Request = dt.Rows[0]["service_request"].ToString();
                log.IT_Personnel_id = Convert.ToInt32(dt.Rows[0]["it_personnel_id"]);

                return(log);
            }
        }
Esempio n. 2
0
 public void Update(it_log obj)
 {
     using (ittransactionlogEntities db = new ittransactionlogEntities())
     {
         db.it_log.Attach(obj);
         db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 3
0
 public it_log Insert(it_log obj)
 {
     using (ittransactionlogEntities db = new ittransactionlogEntities())
     {
         db.it_log.Add(obj);
         db.SaveChanges();
         return(obj);
     }
 }
Esempio n. 4
0
        public FormAddEdit(int?id)
        {
            InitializeComponent();

            if (id == null)
            {
                IsNew = true;
            }
            else
            {
                this.updateObj = ITLogServices.GetById((int)id);
                IsNew          = false;

                textBoxName.Text                  = updateObj.name;
                textBoxOffice.Text                = updateObj.office;
                dateTimePickerDate.Text           = Convert.ToDateTime(updateObj.date).ToString();
                dateTimePickerTime.Text           = updateObj.time.ToString();
                textBoxServiceRequest.Text        = updateObj.service_request;
                comboBoxITPersonnel.SelectedIndex = (int)updateObj.it_personnel_id;
            }
        }
Esempio n. 5
0
 public static void Update(it_log obj)
 {
     repository.Update(obj);
 }
Esempio n. 6
0
 public static it_log Insert(it_log obj)
 {
     return(repository.Insert(obj));
 }
Esempio n. 7
0
        private void FormAddEdit_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                if (string.IsNullOrEmpty(textBoxName.Text))
                {
                    MessageBox.Show("Please Enter Name!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBoxName.Focus();
                    e.Cancel = true;
                    return;
                }

                if (string.IsNullOrEmpty(textBoxOffice.Text))
                {
                    MessageBox.Show("Please Enter Office Name!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBoxOffice.Focus();
                    e.Cancel = true;
                    return;
                }

                if ((string.IsNullOrEmpty(dateTimePickerDate.Text)))
                {
                    MessageBox.Show("Please Enter the Date!");
                    dateTimePickerDate.Focus();
                    e.Cancel = true;
                    return;
                }

                if ((string.IsNullOrEmpty(dateTimePickerTime.Text)))
                {
                    MessageBox.Show("Please Enter the Date!");
                    dateTimePickerTime.Focus();
                    e.Cancel = true;
                    return;
                }

                if (string.IsNullOrEmpty(textBoxServiceRequest.Text))
                {
                    MessageBox.Show("Please Enter the Service Requested!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBoxServiceRequest.Focus();
                    e.Cancel = true;
                    return;
                }

                if (IsNew)
                {
                    var log = new it_log()
                    {
                        name            = textBoxName.Text.ToString(),
                        office          = textBoxOffice.Text.ToString(),
                        date            = Convert.ToDateTime(dateTimePickerDate.Text),
                        time            = TimeSpan.Parse(dateTimePickerTime.Text),
                        service_request = textBoxServiceRequest.Text.ToString(),
                        it_personnel_id = comboBoxITPersonnel.SelectedIndex
                    };

                    ITLogServices.Insert(log);
                    MessageBox.Show("Added!");
                }
                else
                {
                    updateObj.name            = textBoxName.Text.ToString();
                    updateObj.office          = textBoxOffice.Text.ToString();
                    updateObj.date            = Convert.ToDateTime(dateTimePickerDate.Text);
                    updateObj.time            = TimeSpan.Parse(dateTimePickerTime.Text);
                    updateObj.service_request = textBoxServiceRequest.Text.ToString();
                    updateObj.it_personnel_id = comboBoxITPersonnel.SelectedIndex;

                    ITLogServices.Update(updateObj);
                    MessageBox.Show("Saved!");
                }
            }
        }