Ejemplo n.º 1
0
        public void SetAction(BtnEvent pAction, string pPkValue)
        {
            fAction = pAction;

            switch (fAction)
            {
            case BtnEvent.Open:
                btn_save.Text = "&CLOSE";
                obj           = CUpvc_invoice_exten.PKId(pPkValue, new DAL());
                list          = CUpvc_invoiceitems_exten.FKId(pPkValue, new DAL());
                this.EnableControls(false);
                break;

            case BtnEvent.New:
                btn_save.Text = "&SAVE";
                obj           = CUpvc_invoice.GetNew();
                list          = new List <Upvc_invoiceitems>();
                this.EnableControls(true);
                break;

            case BtnEvent.Edit:
                btn_save.Text = "&UPDATE";
                obj           = CUpvc_invoice_exten.PKId(pPkValue, new DAL());
                list          = CUpvc_invoiceitems_exten.FKId(pPkValue, new DAL());
                this.EnableControls(true);
                break;

            case BtnEvent.Delete:
                btn_save.Text = "CONFIRM\r\n&DELETE";
                obj           = CUpvc_invoice_exten.PKId(pPkValue, new DAL());
                list          = CUpvc_invoiceitems_exten.FKId(pPkValue, new DAL());
                this.EnableControls(false);
                break;

            case BtnEvent.Print:
                btn_save.Text = "&PRINT";
                obj           = CUpvc_invoice_exten.PKId(pPkValue, new DAL());
                list          = CUpvc_invoiceitems_exten.FKId(pPkValue, new DAL());
                this.EnableControls(false);
                print_panel.Show();
                break;
            }

            LoadData(obj);
            Loaditems(list);
        }
Ejemplo n.º 2
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 DAL();
                        dalsession.BeginTransaction();
                        CUpvc_invoice.Insert(vData, dalsession);
                        vId = DAL.GetIdentity(dalsession);
                        var itemsList = Collectitems(vId);
                        CUpvc_invoiceitems.Insert(itemsList, dalsession);
                        dalsession.Commit();

                        MessageBox.Show(this.FindForm(), "Record Saved Successfully.", "Save...", 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 Save...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SetFocus();
                        return;
                    }
                    break;

                case BtnEvent.Edit:
                    try
                    {
                        var vData = CollectData();

                        dalsession = new DAL();
                        dalsession.BeginTransaction();
                        CUpvc_invoiceitems.Delete(vId, dalsession);
                        CUpvc_invoice.Update(vData, dalsession);
                        var itemsList = Collectitems(vId);
                        CUpvc_invoiceitems.Insert(itemsList, 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 DAL();
                        dalsession.BeginTransaction();
                        CUpvc_invoiceitems.Delete(vId, dalsession);
                        CUpvc_invoice.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:
                    Print_copies();
                    this.Hide();
                    Form_NeedToRefresh();
                    break;
                }
            }
        }