Ejemplo n.º 1
0
 private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (SCMS.CurrentSystemUser != null)
     {
         if (SCMS.CurrentSystemUser.IsSignedIn)
         {
             e.Cancel = VisualBasic.CBool(MsgBoxEx.Ask("Quit from the application?", "Exit") != System.Windows.Forms.DialogResult.Yes);
             if (!e.Cancel)
             {
                 SCMS.CleanUp(); SCMS.CurrentSystemUser.LogOut();
                 SCMS.CurrentSystemUser = null; SCMS.Connection = null;
                 Application.Exit();
             }
             else
             {
                 _isclosing = false;
             }
         }
         else
         {
             Program.StartUpForm.Show();
         }
     }
     else
     {
         if (!e.Cancel)
         {
             SCMS.CleanUp();   SCMS.Connection = null; Application.Exit();
         }
     }
 }
        private void InitializeInfo()
        {
            DataTable _denominations = Cache.GetCachedTable("currencydenominations");

            if (_denominations != null)
            {
                DataRow[] _rows = _denominations.Select("[DetailId] = " + _id.ToString());
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (VisualBasic.IsNumeric(_row["Denomination"]))
                    {
                        txtValue.Value = VisualBasic.CDbl(_row["Denomination"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Currency"]))
                    {
                        cboCurrency.SelectedValue = _row["Currency"];
                    }
                    if (VisualBasic.IsNumeric(_row["Active"]))
                    {
                        chkActive.Checked = VisualBasic.CBool(_row["Active"]);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of DatabaseScriptInfo.
        /// </summary>
        /// <param name="table"></param>
        public DatabaseScriptInfo(DataTable table)
        {
            ClearInfo();

            if (table != null)
            {
                if (table.TableName != "scripts")
                {
                    return;
                }

                if (table.Rows.Count > 0)
                {
                    DataRow _row = table.Rows[0];
                    if (!Materia.IsNullOrNothing(_row["Author"]))
                    {
                        _author = _row["Author"].ToString();
                    }
                    if (VisualBasic.IsDate(_row["DateCreated"]))
                    {
                        _datecreated = VisualBasic.CDate(_row["DateCreated"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Description"]))
                    {
                        _description = _row["Description"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["ReferenceNo"]))
                    {
                        _referenceno = _row["ReferenceNo"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["RequireAppRestart"]))
                    {
                        _requiresapprestartafterexecution = VisualBasic.CBool(_row["RequireAppRestart"]);
                    }
                    if (VisualBasic.IsNumeric(_row["RequireBackup"]))
                    {
                        _requiresbackupbeforeexecution = VisualBasic.CBool(_row["RequireBackup"]);
                    }
                    if (VisualBasic.IsNumeric(_row["RequirePcRestart"]))
                    {
                        _requirespcrestartafterexecution = VisualBasic.CBool(_row["RequirePcRestart"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Script"]))
                    {
                        _sqlstatement = _row["Script"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["SystemVersion"]))
                    {
                        _systemversion = _row["SystemVersion"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Title"]))
                    {
                        _title = _row["Title"].ToString();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void InitializeCheckBoxes()
        {
            if (_multiselect &&
                grdSearch.DataSource != null)
            {
                string _fieldname = _multiselectmember;
                if (string.IsNullOrEmpty(_fieldname.RLTrim()))
                {
                    for (int i = grdSearch.Cols.Fixed; i <= (grdSearch.Cols.Count - 1); i++)
                    {
                        if (grdSearch.Cols[i].Visible)
                        {
                            _fieldname = grdSearch.Cols[i].Name; break;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(_fieldname.RLTrim()))
                {
                    grdSearch.AllowEditing = true;
                    for (int i = grdSearch.Cols.Fixed; i <= (grdSearch.Cols.Count - 1); i++)
                    {
                        grdSearch.Cols[i].AllowEditing = (grdSearch.Cols[i].Name == _fieldname);
                    }

                    bool _selectall = true;

                    for (int i = grdSearch.Rows.Fixed; i <= (grdSearch.Rows.Count - 1); i++)
                    {
                        bool _selected = VisualBasic.CBool(grdSearch[i, "Select"]);

                        if (_selected)
                        {
                            grdSearch.SetCellCheck(i, grdSearch.Cols[_fieldname].Index, CheckEnum.Checked);
                        }
                        else
                        {
                            grdSearch.SetCellCheck(i, grdSearch.Cols[_fieldname].Index, CheckEnum.Unchecked);
                        }

                        _selectall = _selectall && _selected;
                    }

                    if (_selectall)
                    {
                        grdSearch.SetCellCheck(0, grdSearch.Cols[_fieldname].Index, CheckEnum.Checked);
                    }
                    else
                    {
                        grdSearch.SetCellCheck(0, grdSearch.Cols[_fieldname].Index, CheckEnum.Unchecked);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new instance of DatabaseScriptInfo.
        /// </summary>
        /// <param name="refno"></param>
        public DatabaseScriptInfo(string refno)
        {
            _referenceno = refno; ClearInfo();

            DataTable _scripts = Cache.GetCachedTable("scripts");

            if (_scripts != null)
            {
                DataRow[] _rows = _scripts.Select("[ReferenceNo] LIKE '" + refno.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["Author"]))
                    {
                        _author = _row["Author"].ToString();
                    }
                    if (VisualBasic.IsDate(_row["DateCreated"]))
                    {
                        _datecreated = VisualBasic.CDate(_row["DateCreated"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Description"]))
                    {
                        _description = _row["Description"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["RequireAppRestart"]))
                    {
                        _requiresapprestartafterexecution = VisualBasic.CBool(_row["RequireAppRestart"]);
                    }
                    if (VisualBasic.IsNumeric(_row["RequireBackup"]))
                    {
                        _requiresbackupbeforeexecution = VisualBasic.CBool(_row["RequireBackup"]);
                    }
                    if (VisualBasic.IsNumeric(_row["RequirePcRestart"]))
                    {
                        _requirespcrestartafterexecution = VisualBasic.CBool(_row["RequirePcRestart"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Script"]))
                    {
                        _sqlstatement = _row["Script"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["SystemVersion"]))
                    {
                        _systemversion = _row["SystemVersion"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Title"]))
                    {
                        _title = _row["Title"].ToString();
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private bool IsRevalidated(string value)
        {
            bool _isvalid = true;

            if (!String.IsNullOrEmpty(value.RLTrim()))
            {
                int    _startindex = 0;
                char[] _chars      = value.ToCharArray();

                for (int i = 0; i <= (_chars.Length - 1); i++)
                {
                    if (_chars[i].ToString().ToUpper().In("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
                                                          "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
                                                          "Y", "Z"))
                    {
                        _startindex = i; break;
                    }
                }

                if (_startindex >= 0)
                {
                    List <string> _patterns      = GetSqlPatternList();
                    string        _reparsedvalue = value.Substring(_startindex, value.Length - _startindex);

                    foreach (string pattern in _patterns)
                    {
                        _isvalid = Regex.IsMatch(_reparsedvalue, pattern);

                        if (_isvalid)
                        {
                            string          _incompletestringblock = "'[\\n\\r\\t a-zA-Z0-9~`!@#$\\%\\^&\\*\\(\\)-_\\+=\\{\\}\\[\\]\\\\/\\|:;\"<>,\\.\\?']+;";
                            MatchCollection _matches = Regex.Matches(_reparsedvalue, _incompletestringblock);
                            if (_matches.Count > 0)
                            {
                                _isvalid = !_reparsedvalue.EndsWith(_matches[0].Value);
                                if (!_isvalid)
                                {
                                    MatchCollection _clips = Regex.Matches(_reparsedvalue, "'");
                                    _isvalid = VisualBasic.CBool(_clips.Count % 2 == 0);
                                }
                            }

                            break;
                        }
                    }
                }
            }

            return(_isvalid);
        }
Ejemplo n.º 7
0
        private DataTable GetDataSource()
        {
            DataTable _datasource = null;

            Cache.SyncTable(SCMS.Connection, "scripts");
            DataTable _scripts = Cache.GetCachedTable("scripts");

            if (_scripts != null)
            {
                var _query = from _scr in _scripts.AsEnumerable()
                             select new
                {
                    ReferenceNo   = _scr.Field <string>("ReferenceNo"),
                    SystemVersion = _scr.Field <string>("SystemVersion"),
                    Title         = _scr.Field <string>("Title"),
                    Author        = _scr.Field <string>("Author"),
                    Executed      = _scr.Field <Int16>("Executed"),
                    AutoScript    = _scr.Field <Int16>("AutoScript"),
                    DateCreated   = _scr.Field <DateTime>("DateCreated"),
                    LastModified  = _scr.Field <DateTime>("LastModified")
                };

                _datasource           = new DataTable();
                _datasource.TableName = "scripts";
                DataColumn _pk = _datasource.Columns.Add("ReferenceNo", typeof(string));
                _datasource.Columns.Add("SystemVersion", typeof(string));
                _datasource.Columns.Add("Title", typeof(string));
                _datasource.Columns.Add("Author", typeof(string));
                _datasource.Columns.Add("Executed", typeof(bool));
                _datasource.Columns.Add("AutoScript", typeof(bool));
                _datasource.Columns.Add("DateCreated", typeof(DateTime));
                _datasource.Columns.Add("LastModified", typeof(DateTime));

                foreach (var _row in _query)
                {
                    _datasource.Rows.Add(new object[] {
                        _row.ReferenceNo, _row.SystemVersion, _row.Title,
                        _row.Author, VisualBasic.CBool(_row.Executed), VisualBasic.CBool(_row.AutoScript),
                        _row.DateCreated, _row.LastModified
                    });
                }

                _datasource.AcceptChanges();
            }

            return(_datasource);
        }
        private void FormatGrid(C1FlexGrid grid)
        {
            if (grid == null)
            {
                return;
            }

            ColumnCollection _cols = grid.Cols;

            if (grid.Name == grdUsers.Name)
            {
                grid.AllowEditing = true;

                for (int i = 0; i <= (_cols.Count - 1); i++)
                {
                    _cols[i].AllowEditing = false;
                }
                _cols["AccountHolder"].AllowEditing = true;

                for (int i = 0; i <= (grid.Rows.Count - 1); i++)
                {
                    CheckEnum _checked = CheckEnum.Unchecked;
                    if (i == (_cols.Fixed - 1))
                    {
                        _checked = CheckEnum.Checked;
                    }
                    else
                    {
                        if (VisualBasic.CBool(grid[i, "Select"]))
                        {
                            _checked = CheckEnum.Checked;
                        }
                    }

                    grid.SetCellCheck(i, _cols["AccountHolder"].Index, _checked);
                }

                _cols["AccountHolder"].Caption = "Account Holder";
                _cols["Username"].Visible      = false;
                _cols["Select"].Visible        = false;
                grid.ExtendLastCol             = true;
                _cols[_cols.Fixed - 1].Visible = false;
            }
            else if (grid == grdActions)
            {
                grid.AllowEditing = true;

                for (int i = 0; i <= (_cols.Count - 1); i++)
                {
                    _cols[i].AllowEditing = false;
                }
                _cols["Action"].AllowEditing = true;

                for (int i = 0; i <= (grid.Rows.Count - 1); i++)
                {
                    CheckEnum _checked = CheckEnum.Unchecked;
                    if (i == (_cols.Fixed - 1))
                    {
                        _checked = CheckEnum.Checked;
                    }
                    else
                    {
                        if (VisualBasic.CBool(grid[i, "Select"]))
                        {
                            _checked = CheckEnum.Checked;
                        }
                    }

                    grid.SetCellCheck(i, _cols["Action"].Index, _checked);
                }

                _cols["Id"].Visible            = false;
                _cols["Select"].Visible        = false;
                grid.ExtendLastCol             = true;
                _cols[_cols.Fixed - 1].Visible = false;
            }
            else if (grid == grdLogs)
            {
                _cols["DateAndTime"].Format    = "dd-MMM-yyyy hh:mm:ss tt";
                _cols["DateAndTime"].Caption   = "Date and Time";
                _cols["AccountHolder"].Caption = "Account Holder";
                _cols["ReferenceNo"].Caption   = "Reference No";
                _cols["ComputerName"].Caption  = "Computer Name";
                _cols["IPAddress"].Caption     = "IP Address";
                _cols["Image"].Caption         = "";

                _cols["DetailId"].Visible = false;
                grid.AutoSizeCols(); grid.ExtendLastCol = true;
                _cols[_cols.Fixed - 1].Visible          = false;
                _cols["Image"].Width = 30;
            }
            else
            {
            }
        }
Ejemplo n.º 9
0
        private void InitializeInfo()
        {
            DataTable _scripts = Cache.GetCachedTable("scripts");

            if (_scripts != null)
            {
                DataRow[] _rows = _scripts.Select("[ReferenceNo] LIKE '" + _referenceno.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];

                    if (!Materia.IsNullOrNothing(_row["ReferenceNo"]))
                    {
                        txtReferenceNo.Text = _row["ReferenceNo"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["SystemVersion"]))
                    {
                        txtSystemVersion.Text = _row["SystemVersion"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Author"]))
                    {
                        txtAuthor.Text = _row["Author"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Title"]))
                    {
                        txtTitle.Text = _row["Title"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Script"]))
                    {
                        txtScript.Text = _row["Script"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["RequireBackup"]))
                    {
                        chkBackup.Checked = VisualBasic.CBool(_row["RequireBackup"]);
                    }
                    if (VisualBasic.IsNumeric(_row["RequireAppRestart"]))
                    {
                        chkRestartApp.Checked = VisualBasic.CBool(_row["RequireAppRestart"]);
                    }
                    if (VisualBasic.IsNumeric(_row["RequirePcRestart"]))
                    {
                        chkRestartPc.Checked = VisualBasic.CBool(_row["RequirePcRestart"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Description"]))
                    {
                        txtDescription.Text = _row["Description"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["Executed"]))
                    {
                        if (VisualBasic.CBool(_row["Executed"]))
                        {
                            if (VisualBasic.IsDate(_row["DateExecuted"]))
                            {
                                lblExecuted.Text = "Last Executed : " + VisualBasic.Format(VisualBasic.CDate(_row["DateExecuted"]), "dd-MMM-yyyy");
                                lblExecuted.Show(); lblExecuted.BringToFront();
                            }
                            else
                            {
                                lblExecuted.Hide();
                            }
                        }
                        else
                        {
                            lblExecuted.Hide();
                        }
                    }

                    if (VisualBasic.IsNumeric(_row["AutoScript"]))
                    {
                        if (VisualBasic.CBool(_row["AutoScript"]))
                        {
                            lblAutoScript.Show(); lblAutoScript.BringToFront();
                        }
                        else
                        {
                            lblAutoScript.Hide();
                        }
                    }
                    else
                    {
                        lblAutoScript.Hide();
                    }
                }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Returns whether an specific upload file information with the specified name exists within the collection or not.
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public bool Contains(string name)
 {
     return(VisualBasic.CBool(GetUploadInfoByName(name) != null));
 }
        /// <summary>
        /// Applies table updates from the specified DataTable object into the current DataObjectMap's table.
        /// </summary>
        /// <param name="table"></param>
        public void ApplyUpdatesFromTable(DataTable table)
        {
            if (_table != null &&
                table != null)
            {
                DataTable _updates = table.GetChanges();
                if (_updates != null)
                {
                    foreach (DataRow _row in _updates.Rows)
                    {
                        string _pk = "";

                        foreach (DataColumn _col in _table.Columns)
                        {
                            if (_col.Unique)
                            {
                                _pk = _col.ColumnName; break;
                            }
                        }

                        if (String.IsNullOrEmpty(_pk.RLTrim()))
                        {
                            _pk = _table.Columns[0].ColumnName;
                        }

                        object _pkvalue = null;

                        if (_row.RowState == DataRowState.Deleted ||
                            _row.RowState == DataRowState.Detached ||
                            _row.RowState == DataRowState.Modified)
                        {
                            try { _pkvalue = _row[_pk, DataRowVersion.Original]; }
                            catch { _pkvalue = null; }
                        }
                        else
                        {
                            _pkvalue = _row[_pk];
                        }

                        if (!Materia.IsNullOrNothing(_pkvalue))
                        {
                            string     _filter = "[" + _pk + "] = ";
                            DataColumn _pkcol  = _table.Columns[_pk];
                            object[]   _values = null;

                            switch (_row.RowState)
                            {
                            case DataRowState.Added:
                                _values = new object[_table.Columns.Count];
                                foreach (DataColumn _col in _table.Columns)
                                {
                                    if (!_col.AutoIncrement)
                                    {
                                        if (table.Columns.Contains(_col.ColumnName))
                                        {
                                            _values[_col.Ordinal] = _row[_col.ColumnName];
                                        }
                                    }
                                }
                                AddRow(_values);
                                break;

                            case DataRowState.Deleted:
                            case DataRowState.Detached:
                            case DataRowState.Modified:
                                if (_pkcol.DataType.Name == typeof(string).Name ||
                                    _pkcol.DataType.Name == typeof(String).Name)
                                {
                                    _filter += "'" + _pkvalue.ToString().ToSqlValidString(true) + "'";
                                }
                                else if (_pkcol.DataType.Name == typeof(DateTime).Name)
                                {
                                    if (VisualBasic.IsDate(_pkvalue))
                                    {
                                        _filter += "#" + VisualBasic.Format(VisualBasic.CDate(_pkvalue), "MM/dd/yyyy hh:mm:ss tt") + "#";
                                    }
                                    else
                                    {
                                        _filter = "";
                                    }
                                }
                                else if (_pkcol.DataType.Name == typeof(bool).Name ||
                                         _pkcol.DataType.Name == typeof(Boolean).Name)
                                {
                                    bool _value = VisualBasic.CBool(_pkvalue);
                                    _filter += _value.ToString();
                                }
                                else if (_pkcol.DataType.Name == typeof(byte).Name ||
                                         _pkcol.DataType.Name == typeof(Byte).Name ||
                                         _pkcol.DataType.Name == typeof(decimal).Name ||
                                         _pkcol.DataType.Name == typeof(Decimal).Name ||
                                         _pkcol.DataType.Name == typeof(double).Name ||
                                         _pkcol.DataType.Name == typeof(Double).Name ||
                                         _pkcol.DataType.Name == typeof(int).Name ||
                                         _pkcol.DataType.Name == typeof(Int16).Name ||
                                         _pkcol.DataType.Name == typeof(Int32).Name ||
                                         _pkcol.DataType.Name == typeof(Int64).Name ||
                                         _pkcol.DataType.Name == typeof(long).Name ||
                                         _pkcol.DataType.Name == typeof(sbyte).Name ||
                                         _pkcol.DataType.Name == typeof(SByte).Name ||
                                         _pkcol.DataType.Name == typeof(short).Name ||
                                         _pkcol.DataType.Name == typeof(Single).Name)
                                {
                                    if (VisualBasic.IsNumeric(_pkvalue))
                                    {
                                        _filter += _pkvalue.ToString();
                                    }
                                    else
                                    {
                                        _filter = "";
                                    }
                                }

                                if (!String.IsNullOrEmpty(_filter.RLTrim()))
                                {
                                    if (_row.RowState == DataRowState.Deleted ||
                                        _row.RowState == DataRowState.Detached)
                                    {
                                        DeleteRow(_filter);
                                    }
                                    else
                                    {
                                        DataRow[] _rows = Select(_filter);
                                        if (_rows.Length > 0)
                                        {
                                            DataRow _actualrow = _rows[0];
                                            if (_actualrow.RowState != DataRowState.Deleted &&
                                                _actualrow.RowState != DataRowState.Detached)
                                            {
                                                foreach (DataColumn _col in _table.Columns)
                                                {
                                                    if (!_col.AutoIncrement)
                                                    {
                                                        if (table.Columns.Contains(_col.ColumnName))
                                                        {
                                                            _actualrow[_col.ColumnName] = _row[_col.ColumnName];
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            _values = new object[_table.Columns.Count];
                                            foreach (DataColumn _col in _table.Columns)
                                            {
                                                if (!_col.AutoIncrement)
                                                {
                                                    if (table.Columns.Contains(_col.ColumnName))
                                                    {
                                                        _values[_col.Ordinal] = _row[_col.ColumnName];
                                                    }
                                                }
                                            }
                                            AddRow(_values);
                                        }
                                    }
                                }
                                break;

                            default: break;
                            }
                        }
                    }
                }
            }
        }
        private string Generate()
        {
            StringBuilder _sql = new StringBuilder();

            if (_table != null)
            {
                if (_table.Columns.Count > 0)
                {
                    string _pk = _primarykey.Field;

                    if (String.IsNullOrEmpty(_pk.RLTrim()))
                    {
                        foreach (DataColumn _col in _table.Columns)
                        {
                            if (_col.Unique)
                            {
                                _pk = _col.ColumnName; break;
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(_pk.RLTrim()))
                    {
                        string _tablename = _table.TableName;
                        if (String.IsNullOrEmpty(_tablename.RLTrim()))
                        {
                            _tablename = "table";
                        }

                        string _insert = ""; string _update = "";
                        string _pkvalue = "{" + _table.Columns[_pk].Ordinal.ToString() + "}";
                        if (!String.IsNullOrEmpty(_primarykey.Value.RLTrim()))
                        {
                            _pkvalue = _primarykey.Value;
                        }
                        string _delete = "DELETE FROM `" + _tablename + "` WHERE (`" + _pk + "` = " + _pkvalue + ");";

                        string _insertfields = ""; string _insertparameters = ""; string _updatefield = "";

                        foreach (DataColumn _column in _table.Columns)
                        {
                            if (!_column.AutoIncrement &&
                                !_excludedfields.Contains(_column.ColumnName))
                            {
                                _insertfields += (String.IsNullOrEmpty(_insertfields.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "`";

                                if (_column.ColumnName != _foreignkey.Field)
                                {
                                    _insertparameters += (String.IsNullOrEmpty(_insertparameters.RLTrim()) ? "" : ", ") + "{" + _column.Ordinal.ToString() + "}";
                                    _updatefield      += (String.IsNullOrEmpty(_updatefield.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "` = {" + _column.Ordinal.ToString() + "}";
                                }
                                else
                                {
                                    if (!String.IsNullOrEmpty(_foreignkey.Value.RLTrim()))
                                    {
                                        if (_foreignkey.HeaderTable != null)
                                        {
                                            _insertparameters += (String.IsNullOrEmpty(_insertparameters.RLTrim()) ? "" : ", ") + _foreignkey.Value;
                                            _updatefield      += (String.IsNullOrEmpty(_updatefield.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "` = " + _foreignkey.Value;
                                        }
                                        else
                                        {
                                            if (!String.IsNullOrEmpty(_foreignkey.HeaderPrimaryKey.RLTrim()))
                                            {
                                                if (_foreignkey.HeaderTable.Columns.Contains(_foreignkey.HeaderPrimaryKey))
                                                {
                                                    DataColumn _headercolumn = _foreignkey.HeaderTable.Columns[_foreignkey.HeaderPrimaryKey];
                                                    if (_headercolumn.AutoIncrement)
                                                    {
                                                        if (_foreignkey.HeaderTable.Rows.Count > 0)
                                                        {
                                                            DataRow rw = null;

                                                            foreach (DataRow row in _foreignkey.HeaderTable.Rows)
                                                            {
                                                                if (row.RowState != DataRowState.Deleted &&
                                                                    row.RowState != DataRowState.Detached)
                                                                {
                                                                    rw = row; break;
                                                                }
                                                            }

                                                            if (rw != null)
                                                            {
                                                                if (rw.RowState == DataRowState.Added)
                                                                {
                                                                    _insertparameters += (String.IsNullOrEmpty(_insertparameters.RLTrim()) ? "" : ", ") + _foreignkey.Value;
                                                                    _updatefield      += (String.IsNullOrEmpty(_updatefield.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "` = " + _foreignkey.Value;
                                                                }
                                                                else
                                                                {
                                                                    if (!Materia.IsNullOrNothing(rw[_foreignkey.HeaderPrimaryKey]))
                                                                    {
                                                                        _insertparameters += (String.IsNullOrEmpty(_insertparameters.RLTrim()) ? "" : ", ") + "'" + rw[_foreignkey.HeaderPrimaryKey].ToString().ToSqlValidString() + "'";
                                                                        _updatefield      += (String.IsNullOrEmpty(_updatefield.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "` = " + "'" + rw[_foreignkey.HeaderPrimaryKey].ToString().ToSqlValidString() + "'";
                                                                    }
                                                                    else
                                                                    {
                                                                        _insertparameters += (String.IsNullOrEmpty(_insertparameters.RLTrim()) ? "" : ", ") + _foreignkey.Value;
                                                                        _updatefield      += (String.IsNullOrEmpty(_updatefield.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "` = " + _foreignkey.Value;
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                _insertparameters += (String.IsNullOrEmpty(_insertparameters.RLTrim()) ? "" : ", ") + _foreignkey.Value;
                                                                _updatefield      += (String.IsNullOrEmpty(_updatefield.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "` = " + _foreignkey.Value;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            _insertparameters += (String.IsNullOrEmpty(_insertparameters.RLTrim()) ? "" : ", ") + _foreignkey.Value;
                                                            _updatefield      += (String.IsNullOrEmpty(_updatefield.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "` = " + _foreignkey.Value;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    _insertparameters += (String.IsNullOrEmpty(_insertparameters.RLTrim()) ? "" : ", ") + _foreignkey.Value;
                                                    _updatefield      += (String.IsNullOrEmpty(_updatefield.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "` = " + _foreignkey.Value;
                                                }
                                            }
                                            else
                                            {
                                                _insertparameters += (String.IsNullOrEmpty(_insertparameters.RLTrim()) ? "" : ", ") + _foreignkey.Value;
                                                _updatefield      += (String.IsNullOrEmpty(_updatefield.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "` = " + _foreignkey.Value;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        _insertparameters += (String.IsNullOrEmpty(_insertparameters.RLTrim()) ? "" : ", ") + "{" + _column.Ordinal.ToString() + "}";
                                        _updatefield      += (String.IsNullOrEmpty(_updatefield.RLTrim()) ? "" : ", ") + "`" + _column.ColumnName + "` = {" + _column.Ordinal.ToString() + "}";
                                    }
                                }
                            }
                        }

                        _insert = "INSERT INTO `" + _tablename + "`\n" +
                                  "(" + _insertfields + ")\n" +
                                  "VALUES\n" +
                                  "(" + _insertparameters + ");";

                        string _query = "";

                        foreach (DataRow row in _table.Rows)
                        {
                            if (row.RowState != DataRowState.Unchanged)
                            {
                                _query = ""; _update = "UPDATE `" + _tablename + "` SET " + _updatefield + " WHERE (`" + _pk + "` = " + _pkvalue + ");";

                                string[] _values = new string[_table.Columns.Count];

                                foreach (DataColumn _column in _table.Columns)
                                {
                                    string _value        = "NULL";
                                    object _currentvalue = null;

                                    if (row.RowState == DataRowState.Deleted ||
                                        row.RowState == DataRowState.Detached)
                                    {
                                        try { _currentvalue = row[_column.ColumnName, DataRowVersion.Original]; }
                                        catch { }
                                    }
                                    else
                                    {
                                        _currentvalue = row[_column.ColumnName];
                                    }

                                    if (row.RowState == DataRowState.Modified)
                                    {
                                        if (_column.ColumnName == _pk)
                                        {
                                            object _originalvalue = null;

                                            try
                                            {
                                                _originalvalue = row[_column.ColumnName, DataRowVersion.Original];
                                                if (_originalvalue != _currentvalue)
                                                {
                                                    string _originalpk = "NULL";

                                                    if (_column.DataType.Name == typeof(string).Name ||
                                                        _column.DataType.Name == typeof(String).Name)
                                                    {
                                                        _originalpk = "'" + _originalvalue.ToString().ToSqlValidString() + "'";
                                                    }
                                                    else if (_column.DataType.Name == typeof(DateTime).Name)
                                                    {
                                                        if (VisualBasic.IsDate(_originalvalue))
                                                        {
                                                            _originalpk = "'" + VisualBasic.CDate(_originalvalue).ToSqlValidString(true) + "'";
                                                        }
                                                    }
                                                    else if (_column.DataType.Name == typeof(byte).Name ||
                                                             _column.DataType.Name == typeof(Byte).Name ||
                                                             _column.DataType.Name == typeof(decimal).Name ||
                                                             _column.DataType.Name == typeof(Decimal).Name ||
                                                             _column.DataType.Name == typeof(double).Name ||
                                                             _column.DataType.Name == typeof(Double).Name ||
                                                             _column.DataType.Name == typeof(float).Name ||
                                                             _column.DataType.Name == typeof(int).Name ||
                                                             _column.DataType.Name == typeof(Int16).Name ||
                                                             _column.DataType.Name == typeof(Int32).Name ||
                                                             _column.DataType.Name == typeof(Int64).Name ||
                                                             _column.DataType.Name == typeof(long).Name ||
                                                             _column.DataType.Name == typeof(sbyte).Name ||
                                                             _column.DataType.Name == typeof(SByte).Name ||
                                                             _column.DataType.Name == typeof(short).Name ||
                                                             _column.DataType.Name == typeof(Single).Name)
                                                    {
                                                        if (VisualBasic.IsNumeric(_originalvalue))
                                                        {
                                                            _originalpk = _originalvalue.ToString();
                                                        }
                                                    }
                                                    else if (_column.DataType.Name == typeof(bool).Name ||
                                                             _column.DataType.Name == typeof(Boolean).Name)
                                                    {
                                                        try
                                                        {
                                                            if (VisualBasic.CBool(_originalvalue))
                                                            {
                                                                _originalpk = "1";
                                                            }
                                                            else
                                                            {
                                                                _originalpk = "0";
                                                            }
                                                        }
                                                        catch { }
                                                    }
                                                    else
                                                    {
                                                        if (_column.DataType.Name.ToLower().Contains("byte[]") ||
                                                            _column.DataType.Name.ToLower().Contains("byte()") ||
                                                            _column.DataType.Name.ToLower().Contains("bytes[]") ||
                                                            _column.DataType.Name.ToLower().Contains("bytes()"))
                                                        {
                                                            try
                                                            { _originalpk = "x'" + ((byte[])_originalvalue).ToHexadecimalString().ToSqlValidString() + "'"; }
                                                            catch { _originalpk = "NULL"; }
                                                        }
                                                    }

                                                    _update = "UPDATE `" + _tablename + "` SET " + _updatefield + " WHERE (`" + _pk + "` = " + _originalpk + ");";
                                                }
                                            }
                                            catch { }
                                        }
                                    }

                                    if (!Materia.IsNullOrNothing(_currentvalue))
                                    {
                                        if (_column.DataType.Name == typeof(string).Name ||
                                            _column.DataType.Name == typeof(String).Name)
                                        {
                                            _value = "'" + _currentvalue.ToString().ToSqlValidString() + "'";
                                        }
                                        else if (_column.DataType.Name == typeof(DateTime).Name)
                                        {
                                            if (VisualBasic.IsDate(_currentvalue))
                                            {
                                                _value = "'" + VisualBasic.CDate(_currentvalue).ToSqlValidString(true) + "'";
                                            }
                                        }
                                        else if (_column.DataType.Name == typeof(byte).Name ||
                                                 _column.DataType.Name == typeof(Byte).Name ||
                                                 _column.DataType.Name == typeof(decimal).Name ||
                                                 _column.DataType.Name == typeof(Decimal).Name ||
                                                 _column.DataType.Name == typeof(double).Name ||
                                                 _column.DataType.Name == typeof(Double).Name ||
                                                 _column.DataType.Name == typeof(float).Name ||
                                                 _column.DataType.Name == typeof(int).Name ||
                                                 _column.DataType.Name == typeof(Int16).Name ||
                                                 _column.DataType.Name == typeof(Int32).Name ||
                                                 _column.DataType.Name == typeof(Int64).Name ||
                                                 _column.DataType.Name == typeof(long).Name ||
                                                 _column.DataType.Name == typeof(sbyte).Name ||
                                                 _column.DataType.Name == typeof(SByte).Name ||
                                                 _column.DataType.Name == typeof(short).Name ||
                                                 _column.DataType.Name == typeof(Single).Name)
                                        {
                                            if (VisualBasic.IsNumeric(_currentvalue))
                                            {
                                                _value = _currentvalue.ToString();
                                            }
                                        }
                                        else if (_column.DataType.Name == typeof(bool).Name ||
                                                 _column.DataType.Name == typeof(Boolean).Name)
                                        {
                                            try
                                            {
                                                if (VisualBasic.CBool(_currentvalue))
                                                {
                                                    _value = "1";
                                                }
                                                else
                                                {
                                                    _value = "0";
                                                }
                                            }
                                            catch { }
                                        }
                                        else
                                        {
                                            if (_column.DataType.Name.ToLower().Contains("byte[]") ||
                                                _column.DataType.Name.ToLower().Contains("byte()") ||
                                                _column.DataType.Name.ToLower().Contains("bytes[]") ||
                                                _column.DataType.Name.ToLower().Contains("bytes()"))
                                            {
                                                try
                                                { _value = "x'" + ((byte[])_currentvalue).ToHexadecimalString().ToSqlValidString() + "'"; }
                                                catch { _value = "NULL"; }
                                            }
                                        }
                                    }

                                    _values[_column.Ordinal] = _value;
                                }

                                switch (row.RowState)
                                {
                                case DataRowState.Added:
                                    _query = _insert; break;

                                case DataRowState.Modified:
                                    _query = _update; break;

                                case DataRowState.Deleted:
                                    _query = _delete; break;

                                case DataRowState.Detached:
                                default: break;
                                }

                                _query = String.Format(_query, _values);
                                string _currentsql = _sql.ToString();
                                if (!String.IsNullOrEmpty(_currentsql.RLTrim()))
                                {
                                    _sql.Append("\n");
                                }
                                _sql.Append(_query);
                            }
                        }
                    }
                }
            }

            return(_sql.ToString());
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gathers a user information based on the supplied credentials.
        /// </summary>
        /// <returns></returns>
        public bool GetInformation()
        {
            bool _withinfo = false; ClearInformation();

            Cache.SyncTable(SCMS.Connection, "users");
            DataTable _table = Cache.GetCachedTable("users");

            if (_table != null)
            {
                _table.CaseSensitive = true;
                DataRow[] _rows = _table.Select("[Username] = '" + _username.ToSqlValidString(true) + "' AND [Password] = '" + _password.Encrypt(SCMS.EncryptionKey).ToSqlValidString(true) + "'");

                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["Department"]))
                    {
                        _department = _row["Department"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["FirstName"]))
                    {
                        _firstname = _row["FirstName"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["LastName"]))
                    {
                        _lastname = _row["LastName"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["MiddleName"]))
                    {
                        _middlename = _row["MiddleName"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Position"]))
                    {
                        _position = _row["Position"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Active"]))
                    {
                        _isactive = VisualBasic.CBool(_row["Active"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Role"]))
                    {
                        _issuperuser = VisualBasic.CBool(_row["Role"].ToString() == SuperUserRole);
                    }
                    if (!Materia.IsNullOrNothing(_row["AllCustomers"]))
                    {
                        _isallowedallcustomers = VisualBasic.CBool(_row["AllCustomers"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["AllCompanies"]))
                    {
                        _isallowedallcompanies = VisualBasic.CBool(_row["AllCompanies"]);
                    }

                    if (!_isallowedallcompanies)
                    {
                        DataTable _companies = null;
                        _companies = _companies.LoadData(SCMS.Connection, "SELECT `Company` FROM `usercompanies` WHERE (`Username` LIKE '" + _username.ToSqlValidString() + "')");

                        if (_companies != null)
                        {
                            foreach (DataRow _company in _companies.Rows)
                            {
                                _accessiblecompanies.Add(new CompanyInfo(_company["Company"].ToString()));
                            }

                            _companies.Dispose(); _companies = null;
                            Materia.RefreshAndManageCurrentProcess();
                        }
                    }

                    _isvaliduser = true; _withinfo = true;
                }
            }

            return(_withinfo);
        }
Ejemplo n.º 14
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (!btnDelete.Enabled)
            {
                return;
            }
            if (!grdStockAdjustments.Redraw)
            {
                return;
            }
            if (grdStockAdjustments.DataSource == null)
            {
                return;
            }
            if (grdStockAdjustments.RowSel < grdStockAdjustments.Rows.Fixed)
            {
                return;
            }
            if (Materia.IsNullOrNothing(grdStockAdjustments[grdStockAdjustments.RowSel, "ReferenceNo"]))
            {
                return;
            }

            string    _referenceno      = grdStockAdjustments[grdStockAdjustments.RowSel, "ReferenceNo"].ToString();
            DataTable _stockadjustments = Cache.GetCachedTable("stockadjustments");

            if (_stockadjustments != null)
            {
                DataRow[] _rows = _stockadjustments.Select("[ReferenceNo] LIKE '" + _referenceno.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (VisualBasic.IsNumeric(_row["Closed"]))
                    {
                        if (VisualBasic.CBool(_row["Closed"]))
                        {
                            MsgBoxEx.Shout("Cannot delete stock adjustment : <font color=\"blue\">" + _referenceno + "</font> because it is already marked as final.", "Delete Stock Adjustment");
                            return;
                        }
                    }

                    if (MsgBoxEx.Ask("Delete stock adjustment <font color=\"blue\">" + _referenceno + "</font> permanently from the list?", "Delete Stock Adjustments") != System.Windows.Forms.DialogResult.Yes)
                    {
                        return;
                    }

                    string       _query      = "DELETE FROM `stockadjustments` WHERE (`ReferenceNo` LIKE '" + _referenceno.ToSqlValidString(true) + "')";
                    IAsyncResult _execresult = Que.BeginExecution(SCMS.Connection, _query);

                    btnNew.Enabled     = false; btnEdit.Enabled = false; btnDelete.Enabled = false;
                    btnRefresh.Enabled = false; txtSearch.Enabled = false;

                    while (!_execresult.IsCompleted &&
                           !_cancelled)
                    {
                        Thread.Sleep(1); Application.DoEvents();
                    }

                    if (_cancelled)
                    {
                        if (!_execresult.IsCompleted)
                        {
                            try { _execresult = null; }
                            catch { }
                            finally { Materia.RefreshAndManageCurrentProcess(); }
                        }

                        return;
                    }
                    else
                    {
                        QueResult _result = Que.EndExecution(_execresult);
                        if (string.IsNullOrEmpty(_result.Error.RLTrim()))
                        {
                            _row.Delete(); _stockadjustments.AcceptChanges();

                            if (grdStockAdjustments.Redraw)
                            {
                                grdStockAdjustments.BeginUpdate();
                            }

                            DataTable _datasource = null;

                            try { _datasource = (DataTable)grdStockAdjustments.DataSource; }
                            catch { }

                            if (_datasource != null)
                            {
                                DataRow[] _currows = _datasource.Select("[ReferenceNo] LIKE '" + _referenceno.ToSqlValidString(true) + "'");
                                if (_currows.Length > 0)
                                {
                                    _currows[0].Delete();
                                }
                                _datasource.AcceptChanges();
                            }

                            FormatGrid(); ResizeGrid();

                            Cursor = Cursors.WaitCursor;
                            IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(UserAction.Delete, "Deletes stock adjustment : " + _referenceno + ".", _referenceno);
                            _logresult.WaitToFinish(); Cursor = Cursors.Default;

                            while (!grdStockAdjustments.Redraw)
                            {
                                grdStockAdjustments.EndUpdate();
                            }
                        }
                        else
                        {
                            SCMS.LogError(this.GetType().Name, new Exception(_result.Error));
                            MsgBoxEx.Alert("Failed to delete the specified stock adjustment.", "Delete Stock Adjustment");
                        }

                        _result.Dispose(); EnableButtons(); DisplayInfo();
                    }
                }
            }
        }
        private void grdActions_CellChecked(object sender, RowColEventArgs e)
        {
            if (!_shown)
            {
                return;
            }
            if (!grdActions.Redraw)
            {
                return;
            }
            if (grdActions.DataSource == null)
            {
                return;
            }

            ColumnCollection _cols = grdActions.Cols;

            if (_cols[e.Col].Name == "Action")
            {
                if (e.Row == (grdActions.Rows.Fixed - 1))
                {
                    if (grdActions.Redraw)
                    {
                        grdActions.BeginUpdate();
                    }
                    CheckEnum _checked = grdActions.GetCellCheck(e.Row, e.Col);

                    for (int i = grdActions.Rows.Fixed; i <= (grdActions.Rows.Count - 1); i++)
                    {
                        grdActions.SetCellCheck(i, e.Col, _checked);
                        grdActions[i, _cols["Select"].Index] = (_checked == CheckEnum.Checked);
                    }

                    while (!grdActions.Redraw)
                    {
                        grdActions.EndUpdate();
                    }
                }
                else
                {
                    grdActions[e.Row, "Select"] = (grdActions.GetCellCheck(e.Row, e.Col) == CheckEnum.Checked);

                    CheckEnum _checked    = CheckEnum.Checked;
                    bool      _allchecked = true;

                    for (int i = grdActions.Rows.Fixed; i <= (grdActions.Rows.Count - 1); i++)
                    {
                        _allchecked = _allchecked && VisualBasic.CBool(grdActions[i, "Select"]);
                        if (!_allchecked)
                        {
                            break;
                        }
                    }

                    if (!_allchecked)
                    {
                        _checked = CheckEnum.Unchecked;
                    }

                    grdActions.SetCellCheck(grdActions.Rows.Fixed - 1, e.Col, _checked);
                }
            }
        }
Ejemplo n.º 16
0
        private void InitializeUserInformation()
        {
            DataTable _users = Cache.GetCachedTable("users");

            if (_users != null)
            {
                DataRow[] _rows = _users.Select("[Username] LIKE '" + _username.ToSqlValidString(true) + "'");

                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    txtUsername.Text = _username;

                    if (!Materia.IsNullOrNothing(_row["Password"]))
                    {
                        txtPassword.Text = _row["Password"].ToString().Decrypt(SCMS.EncryptionKey);
                    }
                    if (!Materia.IsNullOrNothing(_row["FirstName"]))
                    {
                        txtFirstName.Text = _row["FirstName"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["MiddleName"]))
                    {
                        txtMiddleName.Text = _row["MiddleName"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["LastName"]))
                    {
                        txtLastName.Text = _row["LastName"].ToString();
                    }

                    if (!Materia.IsNullOrNothing(_row["Department"]))
                    {
                        try  { cboDepartment.SelectedValue = _row["Department"].ToString(); }
                        catch {}
                    }

                    if (!Materia.IsNullOrNothing(_row["Position"]))
                    {
                        try  { cboPosition.SelectedValue = _row["Position"].ToString(); }
                        catch {}
                    }

                    if (!Materia.IsNullOrNothing(_row["Active"]))
                    {
                        chkActive.Checked = VisualBasic.CBool(_row["Active"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Role"]))
                    {
                        chkSuperUser.Checked = (_row["Role"].ToString() == SystemUserInfo.SuperUserRole);
                    }
                    if (!Materia.IsNullOrNothing(_row["AllCustomers"]))
                    {
                        chkAllowAllCustomers.Checked = VisualBasic.CBool(_row["AllCustomers"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["AllCompanies"]))
                    {
                        chkAllowAllCompanies.Checked = VisualBasic.CBool(_row["AllCompanies"]);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        private void InitializeRestorePoints()
        {
            if (grdRestorePoints.Redraw)
            {
                grdRestorePoints.BeginUpdate();
            }

            if (grdRestorePoints.DataSource != null)
            {
                try { grdRestorePoints.DataSource = null; }
                catch { }
                finally { Materia.RefreshAndManageCurrentProcess(); }
            }

            string    _path  = Application.StartupPath + "\\Xml\\restorepoints.xml";
            DataTable _table = SCMS.XmlToTable(_path);

            if (_table != null)
            {
                DataTable  _datasource = new DataTable();
                DataColumn _pkcol      = _datasource.Columns.Add("Id", typeof(int));
                _pkcol.AutoIncrement     = true; _pkcol.AutoIncrementSeed = 1;
                _pkcol.AutoIncrementStep = 1;
                _datasource.Columns.Add("Select", typeof(bool));
                _datasource.Columns.Add("As Of", typeof(DateTime));
                _datasource.Columns.Add("Info", typeof(RestorePointInfo));


                DataRow[] _rows = _table.Select("[Company] LIKE '" + SCMS.CurrentCompany.Company.ToSqlValidString(true) + "' AND\n" +
                                                "[Server] LIKE '" + SCMS.ServerConnection.Server.ToSqlValidString(true) + "' AND\n" +
                                                "[Database] LIKE '" + SCMS.ServerConnection.Database.ToSqlValidString(true) + "'");

                for (int i = 0; i <= (_rows.Length - 1); i++)
                {
                    DataRow          _row          = _rows[i];
                    RestorePointInfo _restorepoint = new RestorePointInfo(VisualBasic.CLng(_row["DetailId"]));

                    if (!String.IsNullOrEmpty(_restorepoint.Filename.RLTrim()))
                    {
                        if (File.Exists(_restorepoint.Filename))
                        {
                            DataColumnCollection _cols   = _datasource.Columns;
                            object[]             _values = new object[_cols.Count];
                            _values[_cols["Select"].Ordinal] = VisualBasic.CBool(i == 0);
                            _values[_cols["As Of"].Ordinal]  = _row["DateAndTime"];
                            _values[_cols["Info"].Ordinal]   = _restorepoint;
                            _datasource.Rows.Add(_values);
                        }
                    }
                }

                grdRestorePoints.DataSource = _datasource;
                grdRestorePoints.Rows[grdRestorePoints.Rows.Fixed - 1].Visible = false;
                grdRestorePoints.Cols["Id"].Visible     = false;
                grdRestorePoints.Cols["Select"].Caption = "";
                grdRestorePoints.Cols["As Of"].Format   = "dd-MMM-yyyy hh:mm:ss tt";
                grdRestorePoints.Cols["Info"].Visible   = false;
                grdRestorePoints.AutoNumber();
                grdRestorePoints.AutoSizeCols();
                grdRestorePoints.ExtendLastCol = true;
            }
            else
            {
                grdRestorePoints.InitializeAppearance();
            }

            while (!grdRestorePoints.Redraw)
            {
                grdRestorePoints.EndUpdate();
            }
        }
Ejemplo n.º 18
0
        private void InitializeModules(ModuleGroup modules)
        {
            string    _path  = Application.StartupPath + "\\Xml\\modules.xml";
            DataTable _table = SCMS.XmlToTable(_path);

            if (_table != null)
            {
                DataRow[] _rows = _table.Select("[Group] = " + VisualBasic.CInt(modules).ToString(), "[Order]");
                if (_rows != null)
                {
                    if (_rows.Length > 0)
                    {
                        brModules.Items.Clear();

                        for (int i = 0; i <= (_rows.Length - 1); i++)
                        {
                            DataRow _row        = _rows[i];
                            Image   _image      = (Image)Properties.Resources.Brick.Clone();
                            bool    _begingroup = VisualBasic.CBool(brModules.Items.Count > 0);

                            ButtonItem _button = new ButtonItem("btnModule" + _row["Id"].ToString(), _row["Text"].ToString());
                            _button.ButtonStyle = eButtonStyle.ImageAndText;
                            if (_moduleimages.Images.ContainsKey(_row["ImageKey"].ToString()))
                            {
                                _image = _moduleimages.Images[_row["ImageKey"].ToString()];
                            }
                            _button.Image         = _image; _button.ImageFixedSize = new Size(32, 32);
                            _button.ImagePosition = eImagePosition.Top;
                            _button.Tag           = _row["Id"]; _button.FixedSize = new Size(120, 75);
                            _button.BeginGroup    = _begingroup; _button.Cursor = Cursors.Hand;
                            _button.Click        += new EventHandler(_button_Click);
                            brModules.Items.Add(_button);
                        }

                        _selectedmodulegroup = modules;
                    }
                }

                _table.Dispose(); _table = null;
                Materia.RefreshAndManageCurrentProcess();
            }

            ButtonItem _modulebutton      = null;
            Image      _modulebuttonimage = (Image)Properties.Resources.Brick.Clone();

            switch (modules)
            {
            case ModuleGroup.Operations:
                _modulebutton = new ButtonItem("btnFinance", "Finance");
                if (_moduleimages.Images.ContainsKey("Finance"))
                {
                    _modulebuttonimage = _moduleimages.Images["Finance"];
                }
                _modulebutton.Image = _modulebuttonimage;
                _modulebutton.Tag   = ModuleGroup.Finance;
                break;

            case ModuleGroup.Finance:
                _modulebutton = new ButtonItem("btnOperations", "Operations");
                if (_moduleimages.Images.ContainsKey("Operations"))
                {
                    _modulebuttonimage = _moduleimages.Images["Operations"];
                }
                _modulebutton.Image = _modulebuttonimage;
                _modulebutton.Tag   = ModuleGroup.Operations;
                break;

            default: break;
            }

            if (_modulebutton != null)
            {
                _modulebutton.ButtonStyle    = eButtonStyle.ImageAndText;
                _modulebutton.ImageFixedSize = new Size(32, 32);
                _modulebutton.FixedSize      = new Size(120, 75);
                _modulebutton.ImagePosition  = eImagePosition.Top;
                bool _begingroup = VisualBasic.CBool(brModules.Items.Count > 0);
                _modulebutton.BeginGroup = _begingroup;
                _modulebutton.Click     += new EventHandler(_button_Click);
                _modulebutton.Cursor     = Cursors.Hand;
                brModules.Items.Add(_modulebutton);
            }

            brModules.RecalcSize();
            brModules.Refresh(); brModules.Update();

            Materia.RefreshAndManageCurrentProcess();
        }