private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                Designaiton oDesignation = new Designaiton();

                if (lsvDesignation.SelectedItems != null && lsvDesignation.SelectedItems.Count > 0)
                {
                    oDesignation = (Designaiton)lsvDesignation.SelectedItems[0].Tag;
                    if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        using (DLMSEntities db = new DLMSEntities())
                        {
                            db.Designaitons.Attach(oDesignation);
                            db.Designaitons.Remove(oDesignation);
                            //Save to database
                            db.SaveChanges();
                        }
                        RefreshList();
                    }
                }
                else
                {
                    MessageBox.Show("select an item to Delete", "Item not yet selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Cannot delete item due to " + Ex.Message);
            }
        }
Exemplo n.º 2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         ExpenseItem oExpenseItem = new ExpenseItem();
         if (lsvExpenseIteams.SelectedItems != null && lsvExpenseIteams.SelectedItems.Count > 0)
         {
             oExpenseItem = (ExpenseItem)lsvExpenseIteams.SelectedItems[0].Tag;
             if (MessageBox.Show("Do you want to delete the selected item?", "Delete Setup", MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 using (DLMSEntities db = new DLMSEntities())
                 {
                     db.ExpenseItems.Attach(oExpenseItem);
                     db.ExpenseItems.Remove(oExpenseItem);
                     //Save to database
                     db.SaveChanges();
                 }
                 RefreshList();
             }
         }
     }
     catch (Exception Ex)
     {
         MessageBox.Show("Cannot delete item due to " + Ex.Message);
     }
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsValid())
                {
                    return;
                }
                bool isNew = false;
                using (DLMSEntities db = new DLMSEntities())
                {
                    if (_ExpenseItem.ExpenseItemID <= 0)
                    {
                        RefreshObject();
                        _ExpenseItem.ExpenseItemID = db.ExpenseItems.Count() > 0 ? db.ExpenseItems.Max(obj => obj.ExpenseItemID) + 1 : 1;
                        db.ExpenseItems.Add(_ExpenseItem);
                        isNew = true;
                    }
                    else
                    {
                        _ExpenseItem = db.ExpenseItems.FirstOrDefault(obj => obj.ExpenseItemID == _ExpenseItem.ExpenseItemID);
                        RefreshObject();
                    }

                    db.SaveChanges();

                    MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (!isNew)
                    {
                        if (ItemChanged1 != null)
                        {
                            ItemChanged1();
                        }
                        this.Close();
                    }
                    else
                    {
                        if (ItemChanged1 != null)
                        {
                            ItemChanged1();
                        }
                        _ExpenseItem = new ExpenseItem();
                        RefreshValue();
                        txtCode.Text = GenerateCategoryCode();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!IsValid())
            {
                return;
            }
            if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    using (DLMSEntities db = new DLMSEntities())
                    {
                        if (_Outlet.OutletID <= 0)
                        {
                            RefreshObject();
                            _Outlet.OutletID = db.Outlets.Count() > 0 ? db.Outlets.Max(obj => obj.OutletID) + 1 : 1;
                            db.Outlets.Add(_Outlet);
                        }
                        else
                        {
                            _Outlet = db.Outlets.FirstOrDefault(obj => obj.OutletID == _Outlet.OutletID);
                            RefreshObject();
                        }

                        db.SaveChanges();
                        MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (MessageBox.Show("Do you want to insert another Outlet?", "Insert Outlet", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            this.Close();
                        }
                        else
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            _Outlet = new Outlet();
                            RefreshValue();
                            txtOutletCode.Text = GenerateOutletCode();
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException == null)
                    {
                        MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsValid())
                {
                    return;
                }
                if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    using (DLMSEntities db = new DLMSEntities())
                    {
                        if (_Employee.EmployeeID <= 0)
                        {
                            RefreshObject();
                            _Employee.EmployeeID = db.Employees.Count() > 0 ? db.Employees.Max(obj => obj.EmployeeID) + 1 : 1;
                            db.Employees.Add(_Employee);
                        }
                        else
                        {
                            _Employee = db.Employees.FirstOrDefault(obj => obj.EmployeeID == _Employee.EmployeeID);
                            RefreshObject();
                        }

                        db.SaveChanges();

                        MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (MessageBox.Show("Do you want to create another Employee?", "Create Employee", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            this.Close();
                        }
                        else
                        {
                            if (ItemChanged != null)
                            {
                                ItemChanged();
                            }
                            _Employee = new Employee();
                            RefreshValue();
                            txtEmpCode.Text = GenerateEmpCode();
                        }
                    }
                }
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
        }
Exemplo n.º 6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    using (DLMSEntities db = new DLMSEntities())
                    {
                        if (_SystemInformation.SystemInfoID <= 0)
                        {
                            RefreshObject();
                            _SystemInformation.SystemInfoID = db.SystemInformations.Count() > 0 ? db.SystemInformations.Max(obj => obj.SystemInfoID) + 1 : 1;
                            db.SystemInformations.Add(_SystemInformation);
                        }
                        else
                        {
                            _SystemInformation = db.SystemInformations.FirstOrDefault(obj => obj.SystemInfoID == _SystemInformation.SystemInfoID);
                            RefreshObject();
                        }

                        db.SaveChanges();
                        MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException == null)
                    {
                        MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }