public void FindButton_Click(object sender, EventArgs e)
        {
            if (customProperties.FindButtonProcedureName != null)
            {
                Form frm = customProperties.Form;

                frmWaitForm waitForm = new frmWaitForm();
                waitForm.Show(frm);

                frmSearch frmSearch = new frmSearch(customProperties.FindButtonProcedureName, customProperties.FindButtonParameters, customProperties.FindButtonColSizes,
                                                    customProperties.FindButtonSearchIndex == null ? 0 : customProperties.FindButtonSearchIndex);

                SqlParameter[] _Params = new SqlParameter[customProperties.FindButtonParameters.Count()];

                //DataTable dtSearch = SQLHelper.ExecuteQueryReturnDS(CommandType.StoredProcedure, customProperties.FindButtonProcedureName, _Params).Tables[0];

                int _index = 0;
                foreach (string lstString in customProperties.FindButtonParameters)
                {
                    string _ParamName  = lstString.Substring(0, lstString.IndexOf('='));
                    string _ParamValue = "";

                    _Params[_index] = new SqlParameter(_ParamName, lstString.Substring(lstString.IndexOf('=') + 1));

                    _index++;
                    //}
                }

                DataTable dtSearch = SQLHelper.ExecuteQueryReturnDS(System.Data.CommandType.StoredProcedure,
                                                                    customProperties.FindButtonProcedureName, _Params).Tables[0];

                waitForm.Close();

                if (frmSearch.ShowDialog() == DialogResult.OK)
                {
                    waitForm = new frmWaitForm();
                    waitForm.Show(frm);

                    FindAndReplaceText(frm);
                    BindDetail();


                    if (customProperties.AfterFind != null)
                    {
                        var        type      = customProperties.Form.GetType();
                        MethodInfo theMethod = type.GetMethod(customProperties.AfterFind);
                        theMethod.Invoke(customProperties.Form, null);
                    }

                    waitForm.Close();
                }
            }
        }
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (customProperties.SaveButtonProcedureName != null)
            {
                Form frm = customProperties.Form;

                if (customProperties.SaveState == true)
                {
                    return;
                }

                frmWaitForm waitForm = new frmWaitForm();
                waitForm.Show(frm);


                string SQLCmd = customProperties.SaveButtonProcedureName;

                lstSaveParams = new List <string>();

                CreateSaveParameters(customProperties.Form);

                if (customProperties.AdditionalSaveButtonParameters != null)
                {
                    foreach (string sAdditionalParams in customProperties.AdditionalSaveButtonParameters)
                    {
                        AddSaveParametertoList(sAdditionalParams);
                    }
                }
                if (customProperties.SaveGridView1 != null)
                {
                    customProperties.SaveButtonParametersTable1 = dgTodt(customProperties.SaveGridView1);
                }

                if (customProperties.SaveGridView2 != null)
                {
                    customProperties.SaveButtonParametersTable2 = dgTodt(customProperties.SaveGridView2);
                }

                if (customProperties.SaveGridView3 != null)
                {
                    customProperties.SaveButtonParametersTable3 = dgTodt(customProperties.SaveGridView3);
                }

                SqlParameter[] _Params = new SqlParameter[lstSaveParams.Count];

                int _index = 0;
                foreach (string lstString in lstSaveParams)
                {
                    //if (_Params[_index] != null)
                    //{
                    string _ParamName  = lstString.Substring(0, lstString.IndexOf('='));
                    string _ParamValue = "";

                    if (lstString.Substring(lstString.IndexOf('=') + 1) == "Table1")
                    {
                        _Params[_index] = new SqlParameter(_ParamName, customProperties.SaveButtonParametersTable1);
                    }
                    else if (lstString.Substring(lstString.IndexOf('=') + 1) == "Table2")
                    {
                        _Params[_index] = new SqlParameter(_ParamName, customProperties.SaveButtonParametersTable2);
                    }
                    else if (lstString.Substring(lstString.IndexOf('=') + 1) == "Table3")
                    {
                        _Params[_index] = new SqlParameter(_ParamName, customProperties.SaveButtonParametersTable3);
                    }
                    else if (lstString.Substring(lstString.IndexOf('=') + 1) == "Image")
                    {
                        _Params[_index] = new SqlParameter(_ParamName, customProperties.SaveImageParameter);
                    }
                    else
                    {
                        _Params[_index] = new SqlParameter(_ParamName, lstString.Substring(lstString.IndexOf('=') + 1));
                    }


                    _index++;
                    //}
                }

                try
                {
                    DataSet dsSaveRcd = SQLHelper.ExecuteQueryReturnDS(System.Data.CommandType.StoredProcedure, SQLCmd, _Params);

                    if (customProperties.ReturnTableNo != null)
                    {
                        customProperties.ReturnTableOnSave = dsSaveRcd.Tables[customProperties.ReturnTableNo];
                    }

                    if (dsSaveRcd.Tables[0].Rows[0][0].ToString() == "Duplicate")
                    {
                        MessageBox.Show(dsSaveRcd.Tables[0].Rows[0][1].ToString(),
                                        GlobalVariables.sMessageBox, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (dsSaveRcd.Tables[0].Rows[0][0].ToString() == "Error")
                    {
                        MessageBox.Show("Saving Error. Please try again", GlobalVariables.sMessageBox, MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    else
                    {
                        UpdateTranNumb(customProperties.Form, dsSaveRcd.Tables[0].Rows[0][0].ToString());
                        UpdateReturnValues(dsSaveRcd.Tables[0]);
                        if (customProperties.AfterSave != null)
                        {
                            var        type      = customProperties.Form.GetType();
                            MethodInfo theMethod = type.GetMethod(customProperties.AfterSave);
                            theMethod.Invoke(customProperties.Form, null);
                        }

                        if (customProperties.PrintButton != null)
                        {
                            if (MessageBox.Show("Do you want to print ? ", GlobalVariables.sMessageBox,
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                            {
                                var        type      = customProperties.Form.GetType();
                                MethodInfo theMethod = type.GetMethod(customProperties.PrintButton);
                                theMethod.Invoke(customProperties.Form, null);
                            }
                        }

                        customProperties.Form.TopMost = true;
                        if (!customProperties.DontShowMsgOnSave)
                        {
                            if (MessageBox.Show("Record has been saved successfully. Do you want to add another ", GlobalVariables.sMessageBox,
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                            {
                                customProperties.Form.Activate();
                                RefreshButton_Click(sender, e);
                            }
                        }
                        customProperties.Form.TopMost = false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }


                waitForm.Close();
            }
        }