Exemplo n.º 1
0
        private bool action(String act)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    ob = act == "insert" ? new Otobus() : dc.Otobus.FirstOrDefault(id => id.Id == Convert.ToInt16(lbIdValue.Text));

                    ob.OtobusName = tbOtobusName.Text;
                    if (act == "insert")
                        dc.Otobus.InsertOnSubmit(ob);
                    dc.SubmitChanges();
                    ts.Complete();
                    if (act != "insert")
                    {
                        lbIdValue.Text = "";
                        lbIdValue.Visible = false;
                        lbID.Visible = false;
                        bCancel.Visible = false;
                    }
                    tbOtobusName.ResetText();
                    return true;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return false;
            }
        }
Exemplo n.º 2
0
        private bool DeleteOtobus()
        {
            DialogResult dr = MessageBox.Show("Are you sure to delete this Otobus ?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (dr == DialogResult.Yes)
            {
                try
                {
                    Otobus oto = new Otobus();
                    oto = dc.Otobus.FirstOrDefault(x => x.Id == Convert.ToInt16(dgOtobus.CurrentRow.Cells["Id"].Value));
                    using(TransactionScope ts = new TransactionScope())
                    {
                        if (oto != null)
                        {
                            dc.Otobus.DeleteOnSubmit(oto);
                            dc.SubmitChanges();
                            ts.Complete();
                            return true;
                        }
                        else
                        {
                            MessageBox.Show("Somthing error with delete proccess", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }

                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 3
0
 partial void UpdateOtobus(Otobus instance);
Exemplo n.º 4
0
 partial void DeleteOtobus(Otobus instance);
Exemplo n.º 5
0
 partial void InsertOtobus(Otobus instance);