Ejemplo n.º 1
0
        public void Button_Click(CTLMButtonsEnum pButtonName) //lauched when clicked any button
        {
            try
            {
                CTLMEventArgs lCTLMEventArgs = new CTLMEventArgs(pButtonName);
                OnBeforeButtonClick(lCTLMEventArgs); //launched BeforeButtonClick Event
                if (lCTLMEventArgs.Cancel)
                {
                    return;
                }
                switch (pButtonName)
                {
                case CTLMButtonsEnum.btnAdd:
                    OnAfterButtonClick(new CTLMEventArgs(pButtonName));     //Launched AfterButtonClick Event
                    SetStatus(EnumStatus.ADDNEW);
                    CTLMItems.Where(x => x.DefaultValue != null).ToList().ForEach(x => x.Value = x.DefaultValue);
                    break;

                case CTLMButtonsEnum.btnUpp:
                    OnAfterButtonClick(new CTLMEventArgs(pButtonName));     //Launched AfterButtonClick Event
                    SetStatus(EnumStatus.EDIT);
                    break;

                case CTLMButtonsEnum.btnDel:
                    if (MessageBox.Show("This will delete the actual record. Are you sure?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        SetStatus(EnumStatus.DELETE);
                        Click_OK(pButtonName);
                    }
                    break;

                case CTLMButtonsEnum.btnSearch:
                    OnAfterButtonClick(new CTLMEventArgs(pButtonName));
                    SetStatus(EnumStatus.SEARCH);
                    break;

                case CTLMButtonsEnum.btnCancel:
                    ClearValues();
                    OnAfterButtonClick(new CTLMEventArgs(pButtonName));
                    SetStatus(EnumStatus.SEARCH);
                    break;

                case CTLMButtonsEnum.btnOk:
                    Click_OK(pButtonName);
                    break;

                case CTLMButtonsEnum.btnNext:
                    if (mDA.SelectRS.State == RSState.Open)
                    {
                        try
                        {
                            setRSPosition(RSPosition + 1);
                        } catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                    OnAfterButtonClick(new CTLMEventArgs(pButtonName));
                    break;

                case CTLMButtonsEnum.btnPrev:
                    if (mDA.SelectRS.State == RSState.Open)
                    {
                        try
                        {
                            setRSPosition(RSPosition - 1);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                    OnAfterButtonClick(new CTLMEventArgs(pButtonName));
                    break;

                case CTLMButtonsEnum.btnFirst:
                    if (mDA.SelectRS.State == RSState.Open)
                    {
                        try
                        {
                            setRSPosition(0);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                    OnAfterButtonClick(new CTLMEventArgs(pButtonName));
                    break;

                case CTLMButtonsEnum.btnLast:
                    if (mDA.SelectRS.State == RSState.Open)
                    {
                        try
                        {
                            setRSPosition(mDA.SelectRS.RecordCount - 1);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                    OnAfterButtonClick(new CTLMEventArgs(pButtonName));
                    break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
 public CTLMEventArgs(CTLMButtonsEnum pButtonClick)
 {
     mButtonClick = pButtonClick;
     Cancel       = false;
 }
Ejemplo n.º 3
0
        private void Click_OK(CTLMButtonsEnum pButtonName = CTLMButtonsEnum.btnOk)
        {
            switch (Status)
            {
            case EnumStatus.SEARCH:
            {
                mDA.SelectRS.Open();
                if (mDA.SelectRS.EOF)
                {
                    MessageBox.Show("No data found.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    OnAfterButtonClick(new CTLMEventArgs(pButtonName));
                    SetStatus(EnumStatus.SEARCH);
                    ClearValues();
                    return;
                }
                try
                {
                    ShowRSValues();
                } catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
                OnAfterButtonClick(new CTLMEventArgs(pButtonName));
                SetStatus(EnumStatus.NAVIGATE);
                if (MsgStatusInfoLabel != null)
                {
                    MsgStatusInfoLabel.Text = mDA.SelectRS.RecordCount.ToString() + " Records returned by search.";
                }
                break;
            }

            case EnumStatus.ADDNEW:
            {
                if (mDA.Conn.State == ConnectionState.Open)
                {
                    mDA.Conn.Close();
                }
                mDA.InsertCommand.Execute();
                if (mDA.InsertCommand.LastMsg.Substring(0, 2) != "OK")
                {
                    MessageBox.Show("ERROR:" + mDA.InsertCommand.LastMsg, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (MsgStatusInfoLabel != null)
                    {
                        MsgStatusInfoLabel.Text = "ERROR:" + mDA.InsertCommand.LastMsg;
                    }
                    return;
                }
                OnAfterButtonClick(new CTLMEventArgs(pButtonName));
                if (Clear)
                {
                    ClearValues();
                }
                else
                {
                    if (ItemsPK.Count == 1 && mDA.InsertCommand.LastMsg.Length > 2)         //if the msg is longer that 2 for example "OK/12345" it assigns the right side to the first key control
                    {
                        ItemsPK[0].Value = mDA.InsertCommand.LastMsg.Substring(3);
                    }
                }
                if (MsgStatusInfoLabel != null)
                {
                    MsgStatusInfoLabel.Text = "Record added successfully :D!";
                }
                if (ReQuery)
                {
                    ClearValues(true);
                    SetStatus(EnumStatus.SEARCH);
                    Click_OK(pButtonName);
                }

                if (VsGrids.Count != 0)
                {
                    SetStatus(EnumStatus.EDIT);
                    ((Control)VsGrids[0]).Focus();
                }

                if (EDGVs.Count != 0)
                {
                    SetStatus(EnumStatus.EDIT);
                    ((Control)EDGVs[0]).Focus();
                }

                if (EDGVCs.Count != 0)
                {
                    SetStatus(EnumStatus.EDIT);
                    ((Control)EDGVCs[0]).Focus();
                }
                else
                {
                    SetStatus(EnumStatus.SEARCH);
                }
                break;
            }

            case EnumStatus.EDIT:
            {
                if (mDA.Conn.State == ConnectionState.Open)
                {
                    mDA.Conn.Close();
                }
                mDA.UpdateCommand.Execute();
                if (mDA.UpdateCommand.LastMsg.Substring(0, 2) != "OK")
                {
                    MessageBox.Show("ERROR:" + mDA.UpdateCommand.LastMsg, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (MsgStatusInfoLabel != null)
                    {
                        MsgStatusInfoLabel.Text = "ERROR:" + mDA.UpdateCommand.LastMsg;
                    }
                    return;
                }
                OnAfterButtonClick(new CTLMEventArgs(pButtonName));
                if (Clear)
                {
                    ClearValues();
                }
                if (ReQuery)
                {
                    ClearValues(true);
                    SetStatus(EnumStatus.SEARCH);
                    Click_OK(pButtonName);;
                }
                SetStatus(EnumStatus.SEARCH);
                if (MsgStatusInfoLabel != null)
                {
                    MsgStatusInfoLabel.Text = "Record updated successfully ;D!";
                }
                break;
            }

            case EnumStatus.DELETE:
            {
                if (mDA.Conn.State == ConnectionState.Open)
                {
                    mDA.Conn.Close();
                }
                mDA.DeleteCommand.Execute();
                if (mDA.DeleteCommand.LastMsg.Substring(0, 2) != "OK")
                {
                    MessageBox.Show("ERROR:" + mDA.DeleteCommand.LastMsg, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    StatusMsg("ERROR:" + mDA.DeleteCommand.LastMsg);
                    return;
                }
                ClearValues();
                OnAfterButtonClick(new CTLMEventArgs(pButtonName));

                SetStatus(EnumStatus.SEARCH);
                if (MsgStatusInfoLabel != null)
                {
                    MsgStatusInfoLabel.Text = "Record deleted successfully X(!";
                }
                break;
            }
            }
        }
Ejemplo n.º 4
0
 public CTLMEventArgs(string pButtonClick)
 {
     mButtonClick = (CTLMButtonsEnum)Enum.Parse(typeof(CTLMButtonsEnum), pButtonClick);
     Cancel       = false;
 }