Пример #1
0
        private void Save_Event()
        {
            if (Validation() != false)
            {
                switch (fAction)
                {
                case BtnEvent.Open:
                    this.Hide();
                    Form_NeedToRefresh();
                    break;

                case BtnEvent.New:
                    try
                    {
                        var vData = CollectData();
                        dalsession = new SQLITE_DAL();
                        dalsession.BeginTransaction();

                        CStables.Insert(vData, dalsession);
                        vId = SQLITE_DAL.GetIdentity(dalsession);

                        var vItems = CollectItems(vId);
                        CSFields.Insert(vItems, dalsession);

                        var vItems_2 = CollectItems_2(vId);
                        CSFieldsitem.Insert(vItems_2, dalsession);

                        dalsession.Commit();

                        MessageBox.Show(this.FindForm(), "Record Saved Successfully.", "Save...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        SetAction(BtnEvent.New, null);
                    }
                    catch (Exception ex)
                    {
                        if (dalsession != null)
                        {
                            dalsession.Rollback();
                        }
                        MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Save...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SetFocus();
                        return;
                    }
                    break;

                case BtnEvent.Edit:
                    try
                    {
                        var vData = CollectData();
                        dalsession = new SQLITE_DAL();
                        dalsession.BeginTransaction();

                        CSFields.Delete(vId, dalsession);
                        CSFieldsitem.Delete(vId, dalsession);

                        CStables.Update(vData, dalsession);

                        var vItems = CollectItems(vId);
                        CSFields.Insert(vItems, dalsession);

                        var vItems_2 = CollectItems_2(vId);
                        CSFieldsitem.Insert(vItems_2, dalsession);

                        dalsession.Commit();

                        MessageBox.Show(this.FindForm(), "Record Updated Successfully.", "Update...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.Hide();
                        Form_NeedToRefresh();
                    }
                    catch (Exception ex)
                    {
                        if (dalsession != null)
                        {
                            dalsession.Rollback();
                        }
                        MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Update...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SetFocus();
                        return;
                    }
                    break;

                case BtnEvent.Delete:
                    try
                    {
                        dalsession = new SQLITE_DAL();
                        dalsession.BeginTransaction();
                        CStables.Delete(vId, dalsession);
                        dalsession.Commit();

                        MessageBox.Show(this.FindForm(), "Record Deleted Successfully.", "Delete...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.Hide();
                        Form_NeedToRefresh();
                    }
                    catch (Exception ex)
                    {
                        if (dalsession != null)
                        {
                            dalsession.Rollback();
                        }
                        MessageBox.Show(this.FindForm(), "Something Goes Wrong \r\n" + ex.Message, "Could Not Update...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SetFocus();
                        return;
                    }
                    break;

                case BtnEvent.Print:
                    this.Hide();
                    Form_NeedToRefresh();
                    break;
                }
            }
        }