private void btnDelete_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(labid.Text))
     {
         MessageBox.Show("Please Select Confereance", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         int ID = int.Parse(labid.Text);
         VibesDataSourceEntities entities    = new VibesDataSourceEntities();
         Tb_Conferences          conferences = entities.Tb_Conferences.SingleOrDefault(a => a.ID == ID);
         entities.Tb_Conferences.Remove(conferences);
         if (entities.SaveChanges() > 0)
         {
             MessageBox.Show("The conferance has been deleted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
             SelectData(entities);
         }
     }
 }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            MyHelper helper = new MyHelper();

            if (helper.EnableandUnEnableControls(this.groupBox1))
            {
            }
            else
            {
                Tb_Conferences conferences = new Tb_Conferences();
                conferences.ID   = int.Parse(labid.Text);
                conferences.Name = txtname.Text;
                conferences.Persident_of_Conferences = txtpersident.Text;
                conferences.from         = datefrom.Value;
                conferences.to           = dateto.Value;
                conferences.introdaction = txtinroduced.Text;
                conferences.Note         = txtNote.Text;
                conferences.customerid   = Convert.ToInt32(comboBox1.SelectedValue);
                conferences.hotelid      = Convert.ToInt32(comboBox2.SelectedValue);

                ValidationContext       context = new ValidationContext(conferences);
                List <ValidationResult> list    = new List <ValidationResult>();

                if (Validator.TryValidateObject(conferences, context, list, true))
                {
                    VibesDataSourceEntities entities = new VibesDataSourceEntities();
                    entities.Entry <Tb_Conferences>(conferences).State = System.Data.Entity.EntityState.Modified;
                    if (entities.SaveChanges() > 0)
                    {
                        MessageBox.Show("The conferance has been edited", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        SelectData(entities);
                    }
                }
                else
                {
                    foreach (var item in list)
                    {
                        MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #3
0
        private void btnsubmit_Click(object sender, EventArgs e)
        {
            MyHelper             helper  = new MyHelper();
            List <InvoiceDetail> details = helper.ConvertToList(this.dataGridView1);

            if (details.Count <= 0)
            {
                MessageBox.Show("please add the detils of the invoice", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Invoice invoice = new Invoice();

            invoice.ConferencesID  = Convert.ToInt32(comboConference.SelectedValue);
            invoice.CustomerID     = Convert.ToInt32(comboCustomer.SelectedValue);
            invoice.Name           = txtname.Text;
            invoice.Note           = txtnote.Text;
            invoice.InvoiceDetails = details;
            invoice.DateOfInvoice  = dateTimePicker1.Value;
            invoice.total          = Convert.ToDecimal(txtDebit.Text);
            invoice.TaxCusto       = Convert.ToDecimal(txtcustomerTax.Text);
            invoice.vatcustom      = Convert.ToDecimal(txtvatcustomer.Text);
            invoice.ISPaid         = false;
            invoice.ISCancel       = false;
            invoice.ISprinted      = false;

            entities.Invoices.Add(invoice);

            if (entities.SaveChanges() > 0)
            {
                MessageBox.Show("The invoice has been added", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                int i = entities.Invoices.Max(a => a.ID);
                txtID.Text = (i + 1).ToString();
            }
            else
            {
                MessageBox.Show("Test");
            }
        }
        private void Add()
        {
            VibesDataSourceEntities entities = new VibesDataSourceEntities();

            Tb_Conferences tb_Conferences = new Tb_Conferences()
            {
                Name = txtname.Text,
                Persident_of_Conferences = txtpersident.Text,
                from         = datefrom.Value,
                to           = dateto.Value,
                introdaction = txtinroduced.Text,
                customerid   = Convert.ToInt32(comboBox1.SelectedValue),
                hotelid      = Convert.ToInt32(comboBox2.SelectedValue),
                Note         = txtNote.Text
            };
            ValidationContext       context = new ValidationContext(tb_Conferences);
            List <ValidationResult> list    = new List <ValidationResult>();

            if (Validator.TryValidateObject(tb_Conferences, context, list, true))
            {
                entities.Tb_Conferences.Add(tb_Conferences);
            }
            else
            {
                foreach (var item in list)
                {
                    MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }


            if (entities.SaveChanges() > 0)
            {
                MessageBox.Show("the Conferance has been added ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                SelectData(entities);
            }
        }