Exemple #1
0
        public static RadioButton RdTypeCheckedChanged(object sender, EventArgs e)
        {
            RadioButton selectedrb = null;
            var         rb         = sender as RadioButton;

            try
            {
                if (rb == null)
                {
                    return(null);
                }

                // Ensure that the RadioButton.Checked property
                // changed to true.
                if (rb.Checked)
                {
                    // Keep track of the selected RadioButton by saving a reference
                    // to it.
                    selectedrb = rb;
                }
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
            return(selectedrb);
        }
        public static bool CreateFile(String dataPath)
        {
            FileStream fs = null;

            try
            {
                dataPath = dataPath.Replace((char)92, '/');
                dataPath = dataPath.Replace((char)9, '/');
                if (!File.Exists(dataPath))
                {
                    string temp = Path.GetDirectoryName(dataPath);
                    if (temp != null && !Directory.Exists(temp))
                    {
                        Directory.CreateDirectory(temp);
                    }
                    fs = new FileStream(dataPath, FileMode.CreateNew);
                    fs.Close();
                }
                return(true);
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
            return(false);
        }
Exemple #3
0
        public int Count(string strSQL)
        {
            var result = 0;

            try
            {
                ConnectDb();
                if (!_isConnected)
                {
                    return(result);
                }

                var             sqlCom = new MySqlCommand(strSQL, _conn);
                MySqlDataReader reader = sqlCom.ExecuteReader();
                if (reader.Read())
                {
                    result = reader.GetInt32(0);
                }
                DisconnectDb();
            }
            catch (Exception ex)
            {
                MessageClass.HideError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
            return(result);
        }
Exemple #4
0
        public static void AppendDataTable(DataTable dtSource, ref DataTable dtDestination)
        {
            try
            {
                if (dtSource == null || dtSource.Rows.Count < 1)
                {
                    return;
                }

                if (dtDestination == null || dtDestination.Rows.Count < 1)
                {
                    dtDestination = dtSource;
                    return;
                }

                foreach (DataRow dr in dtSource.Rows)
                {
                    dtDestination.ImportRow(dr);
                }
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
                return;
            }
        }
Exemple #5
0
        public Boolean Update(string strSQL)
        {
            Boolean result = true;

            try
            {
                ConnectDb();
                if (!_isConnected)
                {
                    return(false);
                }

                var sqlCom = new MySqlCommand(strSQL, _conn);
                sqlCom.ExecuteNonQuery();
                sqlCom.Dispose();
                DisconnectDb();
            }
            catch (MySqlException ex)
            {
                if (ex.ErrorCode != -2147467259)
                {
                    MessageClass.HideError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
                }
                result = false;
            }
            return(result);
        }
Exemple #6
0
        public MySqlConnection ConnectDb()
        {
            try
            {
                if (_isConnected == false)
                {
                    try
                    {
                        if (_mConnString.Length <= 0)
                        {
                            _isConnected = false;
                            return(null);
                        }

                        _conn = new MySqlConnection(_mConnString);
                        _conn.Open();
                    }
                    catch (MySqlException ex)
                    {
                        _isConnected = false;
                        MessageClass.HideError(ex.Message + "MySqlException", System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
                        return(null);
                    }
                    _isConnected = true;
                }
                return(_conn);
            }
            catch (Exception ex)
            {
                MessageClass.HideError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
                return(null);
            }
        }
Exemple #7
0
        public String SingleResult(string strSQL)
        {
            String result = String.Empty;

            try
            {
                ConnectDb();
                if (!_isConnected)
                {
                    return(result);
                }

                var             sqlCom  = new MySqlCommand(strSQL, _conn);
                MySqlDataReader sqlRead = sqlCom.ExecuteReader();
                if (sqlRead.Read())
                {
                    result = sqlRead[0].ToString();
                }
                sqlCom.Dispose();
                DisconnectDb();
            }
            catch (Exception ex)
            {
                MessageClass.HideError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }

            return(result);
        }
        public static DataTable LoadAll()
        {
            DataTable dt = null;

            try
            {
                dt = new DataTable();

                var dc = new DataColumn
                {
                    DataType   = System.Type.GetType("System.String"),
                    ColumnName = Status,
                    ReadOnly   = true,
                    Unique     = true
                };
                dt.Columns.Add(dc);
                DataRow dr = dt.NewRow();
                dr[0] = Active;
                dt.Rows.Add(dr);
                dr    = dt.NewRow();
                dr[0] = Cancel;
                dt.Rows.Add(dr);
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
            return(dt);
        }
Exemple #9
0
 public static void DelConfig()
 {
     try
     {
         File.Delete(Application.ExecutablePath + ".config");
     }
     catch (Exception ex) { MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name); }
 }
Exemple #10
0
        public Boolean ExecuteNonQuery(string strSQL, MySqlParameter[] oSqlParameter)
        {
            const bool isSusscess = false;

            try
            {
                ConnectDb();
                if (!_isConnected)
                {
                    return(isSusscess);
                }

                var sqlCom             = new MySqlCommand();
                MySqlTransaction trans = _conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
                sqlCom.Connection     = _conn;
                sqlCom.CommandTimeout = 0;
                sqlCom.Transaction    = trans;
                try
                {
                    sqlCom.CommandText = strSQL;

                    if (oSqlParameter != null)
                    {
                        sqlCom.Prepare();
                        foreach (MySqlParameter prm in oSqlParameter)
                        {
                            sqlCom.Parameters.Add(prm);
                        }
                    }
                    sqlCom.ExecuteNonQuery();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    MessageClass.HideError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
                }
            }
            catch (Exception ex)
            {
                MessageClass.HideError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
            finally
            {
                DisconnectDb();
            }

            if (oSqlParameter != null)
            {
                strSQL = oSqlParameter.Aggregate(strSQL, (current, prm) => current + (":" + prm.Value.ToString()));
            }
            return(isSusscess);
        }
Exemple #11
0
 public static bool IsText(String strValue)
 {
     try
     {
         var rgx = new Regex("[^0-9]");
         return(!rgx.IsMatch(strValue.Trim()));
     }
     catch (Exception ex)
     {
         MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
         return(false);
     }
 }
Exemple #12
0
        public static bool IsNumeric(string strValue)
        {
            var results = false;

            try
            {
                double dTmp = 0;
                results = double.TryParse(strValue.Trim(), System.Globalization.NumberStyles.Any, null, out dTmp);
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
            return(results);
        }
Exemple #13
0
        public static String Encrypt(String origValue)
        {
            String enryValue = String.Empty;

            try
            {
                var enDes = new TripleDes();
                enryValue = enDes.Encrypt(origValue);
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
            return(enryValue);
        }
Exemple #14
0
 public static void LoadListBox(ListBox ddl, DataTable dt, string textField, string valueField)
 {
     try
     {
         ddl.DataSource = null;
         ddl.Items.Clear();
         ddl.DisplayMember = textField;
         ddl.ValueMember   = valueField;
         ddl.DataSource    = dt;
     }
     catch (Exception ex)
     {
         MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
     }
 }
Exemple #15
0
 public static void LoadDropDown(ComboBox ddl, DataTable dt, string textField, string valueField)
 {
     try
     {
         ddl.SuspendLayout();
         ddl.Items.Clear();
         ddl.DataSource = dt;
         //new BindingSource(dt, "");
         ddl.DisplayMember      = textField;
         ddl.ValueMember        = valueField;
         ddl.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
         ddl.AutoCompleteSource = AutoCompleteSource.ListItems;
         ddl.ResumeLayout();
     }
     catch (Exception ex)
     {
         MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
     }
 }
Exemple #16
0
 public static void AltLoadListBox(ListBox ddl, DataTable dt)
 {
     try
     {
         ddl.BeginUpdate();
         for (var i = 0; i < dt.Rows.Count; i++)
         {
             if (dt.Rows[i][0].ToString().Length > 0)
             {
                 ddl.Items.Add(dt.Rows[i][0].ToString());
             }
         }
         ddl.EndUpdate();
     }
     catch (Exception ex)
     {
         MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
     }
 }
 public static void CloseAllChild(Form[] mdiChildren)
 {
     try
     {
         using (new HourGlass())
         {
             foreach (Form childForm in mdiChildren)
             {
                 childForm.Close();
                 childForm.Dispose();
             }
             GC.Collect();
         }
     }
     catch (Exception ex)
     {
         MessageClass.ShowError(ex.Message, MethodBase.GetCurrentMethod().ReflectedType.Name);
     }
 }
Exemple #18
0
 public static void RemLastRow(DataGridView dgView, int lastSavedRow, int lastSavedIndex)
 {
     try
     {
         if (dgView.Rows.Count < 1)
         {
             return;
         }
         dgView.Focus();
         dgView.ClearSelection();
         dgView.Rows[lastSavedRow].Selected          = true;
         dgView.Rows[lastSavedRow].Cells[0].Selected = true;
         dgView.FirstDisplayedScrollingRowIndex      = lastSavedIndex;
     }
     catch (Exception ex)
     {
         MessageClass.HideError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
     }
 }
Exemple #19
0
        public static bool IsDate(String strValue)
        {
            bool results = false;

            try
            {
                if (strValue.Length < 12)
                {
                    return(false);
                }

                DateTime dt;
                results = DateTime.TryParse(strValue.Trim(), out dt);
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
            return(results);
        }
        private static void ClearControl(Control c)
        {
            try
            {
                if (c is TextBox && c.Enabled)
                {
                    c.Text = String.Empty;
                }

                if (c is ComboBox && c.Enabled)
                {
                    var t = (ComboBox)c;
                    t.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
        }
Exemple #21
0
 private String GetPasswordwMd5(string pass)
 {
     try
     {
         var    x  = new MD5CryptoServiceProvider();
         byte[] bs = System.Text.Encoding.UTF8.GetBytes(pass);
         bs = x.ComputeHash(bs);
         var s = new System.Text.StringBuilder();
         foreach (byte b in bs)
         {
             s.Append(b.ToString("x2").ToLower());
         }
         return(s.ToString());
     }
     catch (Exception ex)
     {
         MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
         return(String.Empty);
     }
 }
        public static void CloseForm(Form frm, BackgroundWorker bgWrkr)
        {
            try
            {
                if (bgWrkr != null)
                {
                    if (bgWrkr.IsBusy)
                    {
                        bgWrkr.CancelAsync();
                    }
                }

                frm.Close();
                frm.Dispose();
                GC.Collect();
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
        }
Exemple #23
0
        public DataTable RetDataTable(string strSQL, CommandType oCommandType, MySqlParameter[] oSqlParameter)
        {
            DataTable dt = null;

            try
            {
                ConnectDb();
                if (!_isConnected)
                {
                    return(null);
                }

                var da = new MySqlDataAdapter
                {
                    SelectCommand = new MySqlCommand(strSQL, _conn)
                    {
                        CommandTimeout = 0, CommandType = oCommandType
                    }
                };
                if (oSqlParameter != null)
                {
                    foreach (MySqlParameter prm in oSqlParameter)
                    {
                        da.SelectCommand.Parameters.Add(prm);
                    }
                }
                var dsResult = new DataTable();
                da.Fill(dsResult);
                dt = dsResult;
                da.Dispose();
                DisconnectDb();
            }
            catch (Exception ex)
            {
                MessageClass.HideError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
            return(dt);
        }
Exemple #24
0
        public static String GetCurrentRow(DataGridView dgView, int intCellNo)
        {
            var id = String.Empty;

            try
            {
                var selectedRowCount = dgView.Rows.GetRowCount(DataGridViewElementStates.Selected);

                if (selectedRowCount > 0)
                {
                    if (dgView.SelectedRows.Count > 0)
                    {
                        if (dgView.SelectedRows.Count > 1)
                        {
                            var currentRow = dgView.SelectedRows[0];
                            id = currentRow.Cells[intCellNo].Value.ToString();
                        }
                        else
                        {
                            var i = dgView.SelectedCells[0].RowIndex;
                            if (dgView.Rows[i].Cells[intCellNo].Value != null)
                            {
                                id = dgView.Rows[i].Cells[intCellNo].Value.ToString();
                            }
                        }
                    }
                    if (id.Length <= 0)
                    {
                        return(string.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
            return(id);
        }
Exemple #25
0
 public static void LoadListView(ListView lst, DataTable dt)
 {
     try
     {
         lst.Items.Clear();
         lst.BeginUpdate();
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             DataRow dr  = dt.Rows[i];
             var     itm = new ListViewItem(dr[0].ToString());
             for (int n = 1; n < dt.Columns.Count; n++)
             {
                 itm.SubItems.Add(dr[n].ToString());
             }
             lst.Items.Add(itm);
         }
         lst.EndUpdate();
     }
     catch (Exception ex)
     {
         MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
     }
 }
Exemple #26
0
 public static void LoadDropDownWBlank(ComboBox ddl, DataTable dt)
 {
     try
     {
         ddl.SuspendLayout();
         ddl.Items.Clear();
         ddl.BeginUpdate();
         ddl.Items.Add("");
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             ddl.Items.Add(dt.Rows[i][0].ToString());
         }
         ddl.EndUpdate();
         ddl.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
         ddl.AutoCompleteSource = AutoCompleteSource.ListItems;
         ddl.DropDownStyle      = ComboBoxStyle.DropDown;
         ddl.ResumeLayout();
     }
     catch (Exception ex)
     {
         MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
     }
 }
        public static bool WriteToFile(String strfullFilepath, bool append, String data)
        {
            bool         result = true;
            StreamWriter fs     = null;

            try
            {
                fs = append ? new StreamWriter(strfullFilepath, true) : new StreamWriter(strfullFilepath);
                fs.WriteLine(data);
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
                result = false;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
            return(result);
        }
Exemple #28
0
 public static void SelectLastRow(DataGridView dgView)
 {
     try
     {
         if (dgView.Rows.Count < 1)
         {
             return;
         }
         dgView.Focus();
         dgView.ClearSelection();
         var newSelIndex = dgView.Rows.Count - 1;
         dgView.Rows[newSelIndex].Selected          = true;
         dgView.Rows[newSelIndex].Cells[0].Selected = true;
         if (dgView.FirstDisplayedScrollingRowIndex + dgView.DisplayedRowCount(false) <= newSelIndex)
         {
             dgView.FirstDisplayedScrollingRowIndex =
                 newSelIndex - dgView.DisplayedRowCount(false) + 1;
         }
     }
     catch (Exception ex)
     {
         MessageClass.HideError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
     }
 }
        public static void LoadSubfrm(Form newMdiChild, Form parentForm, bool isResize)
        {
            try
            {
                using (new HourGlass())
                {
                    GC.Collect();

                    newMdiChild.Font = Gobal.Myfont;
                    if (isResize)
                    {
                        newMdiChild.WindowState = FormWindowState.Maximized;
                        newMdiChild.MinimumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width - 2,
                                                           Screen.PrimaryScreen.WorkingArea.Height - 20);
                        newMdiChild.MdiParent = parentForm;
                    }
                    else
                    {
                        newMdiChild.StartPosition = FormStartPosition.CenterParent;
                    }
                }

                if (isResize)
                {
                    newMdiChild.Show();
                }
                else
                {
                    newMdiChild.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageClass.ShowError(ex.Message, MethodBase.GetCurrentMethod().ReflectedType.Name);
            }
        }
Exemple #30
0
        public MySqlDataReader Query(string strSQL)
        {
            MySqlDataReader sqlRead = null;

            try
            {
                ConnectDb();
                if (!_isConnected)
                {
                    return(null);
                }

                var sqlCom = new MySqlCommand(strSQL, _conn);
                sqlRead = sqlCom.ExecuteReader();
                sqlCom.Dispose();
                DisconnectDb();
            }
            catch (Exception ex)
            {
                MessageClass.HideError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name);
            }

            return(sqlRead);
        }