Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of RestorePointInfo.
        /// </summary>
        /// <param name="restorepointid"></param>
        public RestorePointInfo(long restorepointid)
        {
            _id = restorepointid;

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

            if (_table != null)
            {
                DataRow[] _rows = _table.Select("[DetailId] = " + _id.ToString());
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (VisualBasic.IsDate(_row["DateAndTime"]))
                    {
                        _asof = VisualBasic.CDate(_row["DateAndTime"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Filename"]))
                    {
                        _filename = _row["Filename"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Server"]))
                    {
                        _server = _row["Server"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Database"]))
                    {
                        _database = _row["Database"].ToString();
                    }
                }
                _table.Dispose(); _table = null;
                Materia.RefreshAndManageCurrentProcess();
            }
        }
Exemplo n.º 2
0
        private void InitializeServers()
        {
            string    _path  = Application.StartupPath + "\\Xml\\databaseconnections.xml";
            DataTable _table = SCMS.XmlToTable(_path);

            if (_table != null)
            {
                cboServers.Enabled = false;

                try { cboServers.DataSource = null; }
                catch { }
                finally { Materia.RefreshAndManageCurrentProcess(); }

                _table.Rows.Add(new string[] { "Server List...", "", "", "", "" });

                cboServers.DataSource         = _table;
                cboServers.DisplayMember      = "Name"; cboServers.ValueMember = "Name";
                cboServers.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                cboServers.AutoCompleteSource = AutoCompleteSource.ListItems;

                try { cboServers.SelectedValue = SCMS.LastSelectedConnection; }
                catch { cboServers.SelectedIndex = -1; }

                cboServers.Enabled = true;
            }
        }
        /// <summary>
        /// Creates a new instance of ServerConnectionInfo.
        /// </summary>
        /// <param name="connectionname"></param>
        public ServerConnectionInfo(string connectionname)
        {
            string    _path  = Application.StartupPath + "\\Xml\\databaseconnections.xml";
            DataTable _table = SCMS.XmlToTable(_path);

            if (_table != null)
            {
                DataRow[] _rows = _table.Select("[Name] = '" + connectionname.ToSqlValidString(true) + "'");

                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0]; _name = connectionname;

                    if (!Materia.IsNullOrNothing(_row["Server"]))
                    {
                        _server = _row["Server"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Database"]))
                    {
                        _database = _row["Database"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["UID"]))
                    {
                        _userid = _row["UID"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Password"]))
                    {
                        _password = _row["Password"].ToString();
                    }
                }

                _table.Dispose(); _table = null;
                Materia.RefreshAndManageCurrentProcess();
            }
        }
Exemplo n.º 4
0
        private void InitializeCompanies()
        {
            string    _path  = Application.StartupPath + "\\Xml\\defaultcompanies.xml";
            DataTable _table = SCMS.XmlToTable(_path);

            if (_table != null)
            {
                if (grdCompanies.Redraw)
                {
                    grdCompanies.BeginUpdate();
                }

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

                grdCompanies.DataSource = _table;
                FormatGrid(grdCompanies);
                grdCompanies.AutoNumber();
                grdCompanies.AutoSizeCols(); ResizeGrid(grdCompanies);
                grdCompanies.ExtendLastCol = true;

                while (!grdCompanies.Redraw)
                {
                    grdCompanies.EndUpdate();
                }
            }
        }
        private void InitializeRoles()
        {
            string    _path  = Application.StartupPath + "\\Xml\\signatoryroles.xml";
            DataTable _roles = SCMS.XmlToTable(_path);

            if (_roles != null)
            {
                cboRole.Enabled = false;

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

                cboRole.DataSource         = _roles;
                cboRole.DisplayMember      = "Role"; cboRole.ValueMember = "Id";
                cboRole.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                cboRole.AutoCompleteSource = AutoCompleteSource.ListItems;

                try { cboRole.SelectedIndex = -1; }
                catch { }

                cboRole.Enabled = true;
            }
        }
Exemplo n.º 6
0
        private void InitializeConnections()
        {
            string    _path  = Application.StartupPath + "\\Xml\\databaseconnections.xml";
            DataTable _table = SCMS.XmlToTable(_path);

            if (_table != null)
            {
                DataTable  _datasource = _table.Clone();
                DataColumn _editorcol  = _datasource.Columns.Add("Editor", typeof(string));
                _datasource.Columns.Add("Extra", typeof(string));
                _editorcol.DefaultValue = "Assign server credentials...";

                foreach (DataRow _row in _table.Rows)
                {
                    string[] _values = new string[_datasource.Columns.Count];
                    foreach (DataColumn _col in _table.Columns)
                    {
                        _values[_col.Ordinal] = _row[_col.ColumnName].ToString();
                    }
                    _values[_datasource.Columns["Editor"].Ordinal] = "Assign server credentials...";
                    _values[_datasource.Columns["Extra"].Ordinal]  = "";

                    _datasource.Rows.Add(_values);
                }

                _datasource.AcceptChanges();
                _table.Dispose(); _table = null;
                Materia.RefreshAndManageCurrentProcess();

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

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

                grdServers.DataSource = _datasource;
                FormatGrid(grdServers);

                grdServers.AutoNumber();
                grdServers.AutoSizeCols(); ResizeGrid(grdServers);
                grdServers.ExtendLastCol = true;

                while (!grdServers.Redraw)
                {
                    grdServers.EndUpdate();
                }
            }
        }
Exemplo n.º 7
0
        private void CreateInitialAccountCodes(IDbConnection connection)
        {
            string    _path            = Application.StartupPath + "\\Xml\\defaultaccounts.xml";
            DataTable _defaultaccounts = SCMS.XmlToTable(_path);

            if (_defaultaccounts != null)
            {
                Cache.SyncTable(connection, "accounts");
                DataTable _accounts = Cache.GetCachedTable("accounts");

                if (_accounts != null)
                {
                    string _query = "";

                    for (int i = 0; i <= (_defaultaccounts.Rows.Count - 1); i++)
                    {
                        DataRow   _row  = _defaultaccounts.Rows[i];
                        DataRow[] _rows = _accounts.Select("[AccountCode] = " + _row["AccountCode"].ToString());
                        if (_rows.Length <= 0)
                        {
                            _query += "INSERT INTO `accounts`\n" +
                                      "(`AccountCode`, `AccountName`, `AccountCategory`, `Active`, `DateCreated`)\n" +
                                      "VALUES\n" +
                                      "(" + _row["AccountCode"].ToString() + ", '" + _row["AccountName"].ToString().ToSqlValidString() + "', '" + _row["AccountCategory"].ToString().ToSqlValidString() + "', 1, NOW());\n";

                            object[]             _values = new object[_accounts.Columns.Count];
                            DataColumnCollection _cols   = _accounts.Columns;
                            _values[_cols["AccountCode"].Ordinal]     = _row["AccountCode"];
                            _values[_cols["AccountName"].Ordinal]     = _row["AccountName"];
                            _values[_cols["AccountCategory"].Ordinal] = _row["AccountCategory"];
                            _values[_cols["Active"].Ordinal]          = 1;
                            _values[_cols["DateCreated"].Ordinal]     = DateTime.Now;
                            _values[_cols["LastModified"].Ordinal]    = DateTime.Now;
                            _accounts.Rows.Add(_values);
                        }
                    }

                    if (!String.IsNullOrEmpty(_query.RLTrim()))
                    {
                        QueResult _result = Que.Execute(connection, _query);
                        if (String.IsNullOrEmpty(_query.RLTrim()))
                        {
                            _accounts.AcceptChanges(); Cache.Save();
                        }
                        else
                        {
                            _accounts.RejectChanges();
                        }
                        _result.Dispose(); _result = null; Materia.RefreshAndManageCurrentProcess();
                    }
                }

                _defaultaccounts.Dispose(); _defaultaccounts = null;
                Materia.RefreshAndManageCurrentProcess();
            }
        }
Exemplo n.º 8
0
        private void CreateInitialCompanies(IDbConnection connection)
        {
            string    _path  = Application.StartupPath + "\\Xml\\defaultcompanies.xml";
            DataTable _table = SCMS.XmlToTable(_path);

            if (_table != null)
            {
                Cache.SyncTable(connection, "companies");

                DataTable _cachedtable = Cache.GetCachedTable("companies");
                if (_cachedtable != null)
                {
                    string _query = "";

                    for (int i = 0; i <= (_table.Rows.Count - 1); i++)
                    {
                        DataRow   _row  = _table.Rows[i];
                        DataRow[] _rows = _cachedtable.Select("[Company] LIKE '" + _row["Company"].ToString().ToSqlValidString(true) + "'");
                        if (_rows.Length <= 0)
                        {
                            _query += "INSERT INTO `companies`\n" +
                                      "(`Company`, `Name`, `DateCreated`)\n" +
                                      "VALUES\n" +
                                      "('" + _row["Company"].ToString().ToSqlValidString() + "', '" + _row["Name"].ToString().ToSqlValidString() + "', NOW());\n";

                            DataColumnCollection _cols   = _cachedtable.Columns;
                            object[]             _values = new object[_cols.Count];
                            _values[_cols["Company"].Ordinal]      = _row["Company"];
                            _values[_cols["Name"].Ordinal]         = _row["Name"];
                            _values[_cols["DateCreated"].Ordinal]  = DateTime.Now;
                            _values[_cols["LastModified"].Ordinal] = DateTime.Now;
                            _cachedtable.Rows.Add(_values);
                        }
                    }

                    if (!String.IsNullOrEmpty(_query.RLTrim()))
                    {
                        QueResult _result = Que.Execute(connection, _query);
                        if (String.IsNullOrEmpty(_result.Error.RLTrim()))
                        {
                            _cachedtable.AcceptChanges(); Cache.Save();
                        }
                        _result.Dispose(); _result = null; Materia.RefreshAndManageCurrentProcess();
                    }
                }

                _table.Dispose(); _table = null;
                Materia.RefreshAndManageCurrentProcess();
            }
        }
Exemplo n.º 9
0
        private void CurrencyInfoDialog_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false; this.ManageOnDispose();
            SCMS.Validators.Add(this); AttachEditorHandler();
            cboAccount.LoadAccounts(); cboExchangeRateDiff.LoadAccounts();

            txtCurrency.ReadOnly = (_currency.ToUpper() == "USD");

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

            if (_defaultaccounts != null)
            {
                if (cboAccount.DataSource != null)
                {
                    long      _cashathand = 54005;
                    DataRow[] _rows       = _defaultaccounts.Select("[AccountName] LIKE 'Cash at hand'");
                    if (_rows.Length > 0)
                    {
                        _cashathand = VisualBasic.CLng(_rows[0]["AccountCode"]);
                    }
                    try { cboAccount.SelectedValue = _cashathand; }
                    catch { }
                }

                if (cboExchangeRateDiff.DataSource != null)
                {
                    long      _exratediff = 34625;
                    DataRow[] _rows       = _defaultaccounts.Select("[AccountName] LIKE 'Exchange rate differences'");
                    if (_rows.Length > 0)
                    {
                        _exratediff = VisualBasic.CLng(_rows[0]["AccountCode"]);
                    }
                    try { cboExchangeRateDiff.SelectedValue = _exratediff; }
                    catch { }
                }

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

            txtCurrency.SetAsRequired();
            cboAccount.SetAsRequired(); cboExchangeRateDiff.SetAsRequired();

            if (!_isnew)
            {
                InitializeInfo();
            }
        }
        private void InitializeActions()
        {
            string    _path    = Application.StartupPath + "\\Xml\\systemactions.xml";
            DataTable _actions = SCMS.XmlToTable(_path);

            if (_actions != null)
            {
                if (grdActions.Redraw)
                {
                    grdActions.BeginUpdate();
                }
                grdActions.ClearRowsAndColumns();

                var _query = from _act in _actions.AsEnumerable()
                             select new
                {
                    Id     = _act.Field <int>("Id"),
                    Action = _act.Field <string>("Name")
                };

                DataTable _datasource = new DataTable();
                _datasource.TableName = "actions";

                DataColumn _pk = _datasource.Columns.Add("Id", typeof(int));
                _datasource.Columns.Add("Action", typeof(string));
                _datasource.Columns.Add("Select", typeof(bool));
                _datasource.Constraints.Add("PK", _pk, true);

                foreach (var _row in _query)
                {
                    _datasource.Rows.Add(new object[] { _row.Id, _row.Action, true });
                }
                _datasource.AcceptChanges(); _datasource.DefaultView.Sort = "[Action]";

                grdActions.DataSource = _datasource;
                FormatGrid(grdActions);

                while (!grdActions.Redraw)
                {
                    grdActions.EndUpdate();
                }
            }
        }
Exemplo n.º 11
0
        private string GetModuleName()
        {
            string    _modulename = "";
            string    _path       = Application.StartupPath + "\\Xml\\modules.xml";
            DataTable _modules    = SCMS.XmlToTable(_path);

            if (_modules != null)
            {
                DataRow[] _rows = _modules.Select("[Id] = " + VisualBasic.CInt(_selectedmodule).ToString());
                if (_rows.Length > 0)
                {
                    _modulename = _rows[0]["Text"].ToString();
                }
                _modules.Dispose(); _modules = null;
                Materia.RefreshAndManageCurrentProcess();
            }

            return(_modulename);
        }
Exemplo n.º 12
0
        private void LoginDialog_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
            {
                string    _path  = Application.StartupPath + "\\Xml\\defaultusers.xml";
                DataTable _table = SCMS.XmlToTable(_path);

                if (_table != null)
                {
                    DataRow[] _rows = _table.Select("[ComputerName] LIKE '" + Environment.MachineName.ToSqlValidString(true) + "' AND [UserAccount] LIKE '" + Environment.UserName.ToSqlValidString(true) + "'");
                    if (_rows.Length > 0)
                    {
                        txtUsername.Text = _rows[0]["Username"].ToString();
                        txtPassword.Text = _rows[0]["Password"].ToString();
                    }

                    _table.Dispose(); _table = null;
                    Materia.RefreshAndManageCurrentProcess();
                }
            }
        }
Exemplo n.º 13
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();
        }
Exemplo n.º 14
0
        private void btnSaveServers_Click(object sender, EventArgs e)
        {
            if (!btnSaveServers.Enabled)
            {
                return;
            }
            if (grdServers.DataSource == null)
            {
                return;
            }
            try { grdServers.Row = grdServers.Rows.Fixed - 1; }
            catch { }

            for (int i = grdServers.Rows.Fixed; i <= (grdServers.Rows.Count - 1); i++)
            {
                if (!Materia.IsNullOrNothing(grdServers.Rows[i]["Name"]))
                {
                    if (String.IsNullOrEmpty(grdServers.Rows[i]["Name"].ToString().RLTrim()))
                    {
                        MsgBoxEx.Shout("Please specify database server connection name at entry : " + i.ToString() + ".", "Required Field Notification");
                        grdServers.StartEditing(i, grdServers.Cols["Name"].Index); return;
                    }

                    if (String.IsNullOrEmpty(grdServers.Rows[i]["Server"].ToString().RLTrim()))
                    {
                        MsgBoxEx.Shout("Please specify database server IP address or hostname at entry : " + i.ToString() + ".", "Required Field Notification");
                        grdServers.StartEditing(i, grdServers.Cols["Server"].Index); return;
                    }

                    if (String.IsNullOrEmpty(grdServers.Rows[i]["Database"].ToString().RLTrim()))
                    {
                        MsgBoxEx.Shout("Please specify database catalog name at entry : " + i.ToString() + ".", "Required Field Notification");
                        grdServers.StartEditing(i, grdServers.Cols["Database"].Index); return;
                    }
                }
            }

            DataTable _datasource = (DataTable)grdServers.DataSource;

            if (_datasource.Rows.Count <= 0)
            {
                MsgBoxEx.Shout("Please specify at least a database connection to be registered.", "Save Database Server Connections"); return;
            }

            DataTable _changes = _datasource.GetChanges();

            if (_changes != null)
            {
                string    _path    = Application.StartupPath + "\\Xml\\databaseconnections.xml";
                DataTable _current = SCMS.XmlToTable(_path);

                if (_current != null)
                {
                    foreach (DataRow _row in _changes.Rows)
                    {
                        switch (_row.RowState)
                        {
                        case DataRowState.Added:
                            string[] _values = new string[_current.Columns.Count];
                            foreach (DataColumn _col in _current.Columns)
                            {
                                _values[_col.Ordinal] = _row[_col.ColumnName].ToString();
                            }
                            _current.Rows.Add(_values); break;

                        case DataRowState.Modified:
                            string _name = "";

                            try { _name = _row["Name", DataRowVersion.Original].ToString(); }
                            catch { _name = _row["Name"].ToString(); }

                            DataRow[] _existingrows = _current.Select("[Name] = '" + _name.ToSqlValidString(true) + "'");
                            if (_existingrows.Length > 0)
                            {
                                DataRow _currentrow = _existingrows[0];
                                foreach (DataColumn _col in _current.Columns)
                                {
                                    _currentrow[_col.ColumnName] = _row[_col.ColumnName];
                                }
                            }

                            break;

                        case DataRowState.Deleted:
                        case DataRowState.Detached:
                            string _deletedname = "";

                            try { _deletedname = _row["Name", DataRowVersion.Original].ToString(); }
                            catch { _deletedname = ""; }

                            DataRow[] _rows = _current.Select("[Name] = '" + _deletedname.ToSqlValidString(true) + "'");
                            if (_rows.Length > 0)
                            {
                                _rows[0].Delete();
                            }

                            break;

                        default: break;
                        }
                    }

                    try
                    {
                        _current.WriteXml(_path, XmlWriteMode.WriteSchema);
                        _datasource.AcceptChanges();
                    }
                    catch (Exception ex)
                    {
                        SCMS.LogError(this.Name, ex);
                        MsgBoxEx.Alert("Failed to save the changes made in the list. Please try again and / or report<br />this to your System Administrator.", "Save Database Server Connections");
                    }

                    try { _current.Dispose(); }
                    catch { }

                    _current = null; Materia.RefreshAndManageCurrentProcess();
                }
            }
        }
Exemplo n.º 15
0
        private DataTable GetPartInventory()
        {
            DataTable _datasource = null;

            Cache.SyncTable(SCMS.Connection, "parts");
            Cache.SyncTable(SCMS.Connection, "partnames");
            Cache.SyncTable(SCMS.Connection, "partcategories");
            Cache.SyncTable(SCMS.Connection, "brands");
            Cache.SyncTable(SCMS.Connection, "models");
            Cache.SyncTable(SCMS.Connection, "measurements");
            Cache.SyncTable(SCMS.Connection, "stockledger");
            Cache.SyncTable(SCMS.Connection, "customers");
            Cache.SyncTable(SCMS.Connection, "suppliers");
            Cache.SyncTable(SCMS.Connection, "locations");
            Cache.SyncTable(SCMS.Connection, "users");

            DataTable _parts          = Cache.GetCachedTable("parts");
            DataTable _partnames      = Cache.GetCachedTable("partnames");
            DataTable _partcategories = Cache.GetCachedTable("partcategories");
            DataTable _brands         = Cache.GetCachedTable("brands");
            DataTable _models         = Cache.GetCachedTable("models");
            DataTable _measurements   = Cache.GetCachedTable("measurements");
            DataTable _ledger         = Cache.GetCachedTable("stockledger");

            if (_parts != null &&
                _partnames != null &&
                _partcategories != null &&
                _brands != null &&
                _models != null &&
                _measurements != null &&
                _ledger != null)
            {
                string    _path       = Application.StartupPath + "\\Xml\\stocktypes.xml";
                DataTable _stocktypes = SCMS.XmlToTable(_path);

                if (_stocktypes != null)
                {
                    var _query = from _part in _parts.AsEnumerable()
                                 join _uom in _measurements.AsEnumerable() on _part.Field <string>("Unit") equals _uom.Field <string>("Unit")
                                 join _name in _partnames.AsEnumerable() on _part.Field <string>("PartName") equals _name.Field <string>("PartName")
                                 join _brand in _brands.AsEnumerable() on _part.Field <string>("Brand") equals _brand.Field <string>("Brand")
                                 join _type in _stocktypes.AsEnumerable() on _part.Field <int>("StockType") equals _type.Field <int>("Id")
                                 join _model in _models.AsEnumerable() on _part.Field <string>("ModelCode") equals _model.Field <string>("ModelCode") into _pm
                                 join _stockledger in _ledger.AsEnumerable() on _part.Field <string>("PartCode") equals _stockledger.Field <string>("PartCode") into _sl
                                     where _part.Field <string>("Company") == SCMS.CurrentCompany.Company
                                 from _model in _pm.DefaultIfEmpty(_models.NewRow())
                                 from _stockledger in _sl.DefaultIfEmpty(_ledger.NewRow())
                                 group _stockledger by new
                    {
                        PartCode     = _part.Field <string>("PartCode"),
                        PartNo       = _part.Field <string>("PartNo"),
                        PartName     = _part.Field <string>("PartName"),
                        Description  = _part.Field <string>("Description"),
                        Brand        = _part.Field <string>("Brand"),
                        Model        = _model.Field <string>("Model"),
                        Category     = _name.Field <string>("PartCategory"),
                        Unit         = _part.Field <string>("Unit"),
                        ReorderPoint = _part.Field <int>("ReorderPoint"),
                        ReorderQty   = _part.Field <int>("ReorderQty"),
                        Type         = _type.Field <string>("StockType"),
                        Status       = (_part.Field <Int16>("Active") == 1 ? "Active" : "Inactive")
                    } into _group
                        select new
                    {
                        PartCode      = _group.Key.PartCode,
                        PartNo        = _group.Key.PartNo,
                        PartName      = _group.Key.PartName,
                        Description   = _group.Key.Description,
                        Brand         = _group.Key.Brand,
                        Model         = _group.Key.Model,
                        Category      = _group.Key.Category,
                        Unit          = _group.Key.Unit,
                        Quantity      = _group.Sum(_stockledger => (_stockledger.Field <int>("In") - _stockledger.Field <int>("Out"))),
                        Incoming      = _group.Sum(_stockledger => _stockledger.Field <int>("Incoming")),
                        Outgoing      = _group.Sum(_stockledger => _stockledger.Field <int>("Outgoing")),
                        Balance       = _group.Sum(_stockledger => (_stockledger.Field <int>("In") - _stockledger.Field <int>("Out") + _stockledger.Field <int>("Incoming") - _stockledger.Field <int>("Outgoing"))),
                        ReorderPoint  = _group.Key.ReorderPoint,
                        ReorderQty    = _group.Key.ReorderQty,
                        Type          = _group.Key.Type,
                        Status        = _group.Key.Status,
                        LastPurchased = _group.Max(_stockledger => _stockledger.Field <DateTime>("PurchaseDate")),
                        UnitCost      = _group.Sum(_stockledger => ((_stockledger.Field <int>("In") > 0 || _stockledger.Field <int>("Incoming") > 0 ? 1 : -1) * _stockledger.Field <decimal>("TotalCostUSD")))
                    };

                    _datasource           = new DataTable();
                    _datasource.TableName = "parts";
                    DataColumn _dpk = _datasource.Columns.Add("PartCode", typeof(string));
                    _datasource.Columns.Add("PartNo", typeof(string));
                    _datasource.Columns.Add("PartName", typeof(string));
                    _datasource.Columns.Add("Description", typeof(string));
                    _datasource.Columns.Add("Brand", typeof(string));
                    _datasource.Columns.Add("Model", typeof(string));
                    _datasource.Columns.Add("Category", typeof(string));
                    _datasource.Columns.Add("Unit", typeof(string));
                    _datasource.Columns.Add("Quantity", typeof(int));
                    _datasource.Columns.Add("Incoming", typeof(int));
                    _datasource.Columns.Add("Outgoing", typeof(int));
                    _datasource.Columns.Add("Balance", typeof(int));
                    _datasource.Columns.Add("UnitCost", typeof(decimal));
                    _datasource.Columns.Add("ReorderPoint", typeof(int));
                    _datasource.Columns.Add("ReorderQty", typeof(int));
                    _datasource.Columns.Add("Type", typeof(string));
                    _datasource.Columns.Add("Status", typeof(string));
                    DataColumn _lastpurchasecol = _datasource.Columns.Add("LastPurchased", typeof(DateTime));
                    _lastpurchasecol.AllowDBNull = true;

                    _datasource.Constraints.Add("PK", _dpk, true);

                    try
                    {
                        foreach (var _row in _query)
                        {
                            decimal _unitcost = 0;
                            if (_row.Balance > 0 &&
                                _row.UnitCost > 0)
                            {
                                _unitcost = _row.UnitCost / _row.Balance;
                            }

                            object _lastpurchased = _row.LastPurchased;
                            if (VisualBasic.IsDate(_lastpurchased))
                            {
                                if (VisualBasic.CDate(_lastpurchased) == VisualBasic.CDate("1/1/1900"))
                                {
                                    _lastpurchased = DBNull.Value;
                                }
                            }

                            _datasource.Rows.Add(new object[] {
                                _row.PartCode, _row.PartNo, _row.PartName,
                                _row.Description, _row.Brand, _row.Model,
                                _row.Category, _row.Unit, _row.Quantity,
                                _row.Incoming, _row.Outgoing, _row.Balance,
                                _unitcost, _row.ReorderPoint, _row.ReorderQty,
                                _row.Type, _row.Status, _lastpurchased
                            });
                        }
                    }
                    catch { }

                    _datasource.AcceptChanges();
                }
            }

            _datasource.DefaultView.Sort = "[PartNo]";
            return(_datasource);
        }
Exemplo n.º 16
0
        private void InitializeModuleNodes()
        {
            if (!_nodesloading)
            {
                _nodesloading = true;
            }

            trvwModules.BeginUpdate(); trvwModules.Nodes.Clear();
            trvwModules.ImageList = _images16; trvwModules.DragDropEnabled = false;

            DevComponents.AdvTree.Node _scmsnode = new DevComponents.AdvTree.Node();
            _scmsnode.Name       = "SCMS"; _scmsnode.Text = "Supply Chain Management System";
            _scmsnode.Selectable = true; _scmsnode.Enabled = true;
            _scmsnode.ImageKey   = "SCMS"; _scmsnode.Editable = false;

            trvwModules.Nodes.Add(_scmsnode);

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

            if (_nodes != null)
            {
                var _query = from _n in _nodes.AsEnumerable()
                             where _n.Field <int>("Module") == VisualBasic.CInt(_selectedmodule)
                             select _n;

                DataTable _modulenodes = null;

                try { _modulenodes = _query.CopyToDataTable(); }
                catch { }

                if (_modulenodes != null)
                {
                    _modulenodes.TableName        = "nodes";
                    _modulenodes.DefaultView.Sort = "[Ordering]";
                    DataTable _viewtable = _modulenodes.DefaultView.ToTable();

                    if (_viewtable.Rows.Count > 0)
                    {
                        for (int i = 0; i <= (_viewtable.Rows.Count - 1); i++)
                        {
                            DataRow _row = _viewtable.Rows[i];
                            DevComponents.AdvTree.Node[] _parentnodes = trvwModules.Nodes.Find(_row["ParentKey"].ToString(), true);
                            if (_parentnodes.Length > 0)
                            {
                                DevComponents.AdvTree.Node _parentnode = _parentnodes[0];
                                DevComponents.AdvTree.Node _childnode  = new DevComponents.AdvTree.Node();
                                _childnode.Name       = _row["NodeKey"].ToString(); _childnode.Text = _row["Text"].ToString();
                                _childnode.ImageKey   = _row["NodeKey"].ToString();
                                _childnode.Editable   = false; _childnode.Enabled = true;
                                _childnode.Selectable = true; _childnode.Tag = _row["SubModuleEnum"];

                                _parentnode.Nodes.Add(_childnode);
                            }
                        }
                    }

                    _viewtable.Dispose(); _viewtable     = null;
                    _modulenodes.Dispose(); _modulenodes = null;
                    _nodes.Dispose(); _nodes             = null;
                    Materia.RefreshAndManageCurrentProcess();
                }
            }

            trvwModules.ExpandAll(); trvwModules.EndUpdate();
            if (_nodesloading)
            {
                _nodesloading = false;
            }

            if (_scmsnode.Nodes.Count > 0)
            {
                DevComponents.AdvTree.Node _selectednode = _scmsnode.Nodes[0];
                trvwModules.SelectedNode = _selectednode;
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Updates the current workstation's cache time stamp.
        /// </summary>
        /// <param name="timestamp"></param>
        public static void UpdateCacheTimeStamp(DateTime timestamp)
        {
            string    _path          = Application.StartupPath + "\\Xml\\cachesettings.xml";
            DataTable _cachesettings = SCMS.XmlToTable(_path);

            if (_cachesettings != null)
            {
                CompanyInfo          _company = SCMS.CurrentCompany;
                ServerConnectionInfo _server  = SCMS.ServerConnection;

                if (_company == null)
                {
                    _company = new CompanyInfo(SCMS.LastSelectedCompany);
                }
                if (_server == null)
                {
                    _server = new ServerConnectionInfo(SCMS.LastSelectedConnection);
                }

                if (_cachesettings.Rows.Count > 0)
                {
                    DataRow[] _rows = _cachesettings.Select("[Company] LIKE '" + _company.Company.ToSqlValidString(true) + "' AND\n" +
                                                            "[Server] LIKE '" + _server.Server.ToSqlValidString(true) + "' AND\n" +
                                                            "[Database] LIKE '" + _server.Database.ToSqlValidString(true) + "'");

                    if (_rows.Length > 0)
                    {
                        _rows[0]["LastRestored"] = timestamp;
                    }
                    else
                    {
                        object[]             _values = new object[_cachesettings.Columns.Count];
                        DataColumnCollection _cols   = _cachesettings.Columns;

                        _values[_cols["Company"].Ordinal]      = _company.Company;
                        _values[_cols["Server"].Ordinal]       = _server.Server;
                        _values[_cols["Database"].Ordinal]     = _server.Database;
                        _values[_cols["LastRestored"].Ordinal] = timestamp;

                        _cachesettings.Rows.Add(_values);
                    }
                }
                else
                {
                    object[]             _values = new object[_cachesettings.Columns.Count];
                    DataColumnCollection _cols   = _cachesettings.Columns;

                    _values[_cols["Company"].Ordinal]      = _company.Company;
                    _values[_cols["Server"].Ordinal]       = _server.Server;
                    _values[_cols["Database"].Ordinal]     = _server.Database;
                    _values[_cols["LastRestored"].Ordinal] = timestamp;

                    _cachesettings.Rows.Add(_values);
                }

                _cachesettings.AcceptChanges();

                try { _cachesettings.WriteXml(_path, XmlWriteMode.WriteSchema); }
                catch { }

                _cachesettings.Dispose(); _cachesettings = null;
                Materia.RefreshAndManageCurrentProcess();
            }
        }
Exemplo n.º 18
0
        private RestorePointInfo MakeRestorePoint()
        {
            RestorePointInfo _restorepoint = null;

            AddEvent(BackupEvent.Information, "Creating database restore point...");

            string _rpdir = Application.StartupPath + "\\Restore Points";

            if (!Directory.Exists(_rpdir))
            {
                try { Directory.CreateDirectory(_rpdir); }
                catch (Exception ex)
                {
                    SCMS.LogError(this.GetType().Name, ex);
                    AddEvent(BackupEvent.Error, "Can't create database restore point directory.");
                }
            }

            if (Directory.Exists(_rpdir))
            {
                Func <IDbConnection, DateTime> _serverdatedelegate = new Func <IDbConnection, DateTime>(MySql.GetServerDateAndTime);
                IAsyncResult _serverdateresult = _serverdatedelegate.BeginInvoke(SCMS.Connection, null, _serverdatedelegate);
                _serverdateresult.WaitToFinish();
                DateTime _serverdatetime = _serverdatedelegate.EndInvoke(_serverdateresult);
                string   _rpfilename     = _rpdir + "\\" + SCMS.ServerConnection.Database.ToUpper() + "_" + SCMS.CurrentCompany.Company + "_RESTORE_POINT_" + VisualBasic.Format(_serverdatetime, "dd_MM_yyyy_HH_mm_ss") + ".sql";
                int      _trycounter     = 0;

                MySqlDumpParameterCollection _parameters = new MySqlDumpParameterCollection();
                _parameters.Add(MySqlDumpParameters.CompleteInsert);
                _parameters.Add(MySqlDumpParameters.HexBlob);
                _parameters.Add(MySqlDumpParameters.Routines);
                _parameters.Add("--skip-extended-insert");
                _parameters.Add(MySqlDumpParameters.Triggers);
                _parameters.Add(MySqlDumpParameters.Quick);

                Func <string, string, MySqlDumpParameterCollection, MySqlResult> _dumpdelegate = new Func <string, string, MySqlDumpParameterCollection, MySqlResult>(MySql.Dump);
                IAsyncResult _dumpresult = _dumpdelegate.BeginInvoke(SCMS.ServerConnection.ToString(), _rpfilename, _parameters, null, _dumpdelegate);

                AddEvent(BackupEvent.Information, "Restore point creation started.");

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

                if (_cancelled)
                {
                    AddEvent(BackupEvent.Warning, "Cancelling restore point creation...");

                    _trycounter = 0;

                    while (File.Exists(_rpfilename) &&
                           _trycounter <= 30)
                    {
                        try { File.Delete(_rpfilename); }
                        catch { }

                        _trycounter += 1;
                        Thread.Sleep(100); Application.DoEvents();
                    }

                    Materia.RefreshAndManageCurrentProcess();
                    AddEvent(BackupEvent.Information, "Restore point creation cancelled.");
                }
                else
                {
                    MySqlResult _result = _dumpdelegate.EndInvoke(_dumpresult);
                    if (_result.Succeeded)
                    {
                        string    _path  = Application.StartupPath + "\\Xml\\restorepoints.xml";
                        DataTable _table = SCMS.XmlToTable(_path);

                        if (_table != null)
                        {
                            bool _created = false; DataRow _newrow = null;

                            object[]             _values = new object[_table.Columns.Count];
                            DataColumnCollection _cols = _table.Columns;
                            _values[_cols["DateAndTime"].Ordinal] = _serverdatetime;
                            _values[_cols["Filename"].Ordinal]    = _rpfilename;
                            _values[_cols["Company"].Ordinal]     = SCMS.CurrentCompany.Company;
                            _values[_cols["Server"].Ordinal]      = SCMS.ServerConnection.Server;
                            _values[_cols["Database"].Ordinal]    = SCMS.ServerConnection.Database;

                            try
                            {
                                _newrow = _table.Rows.Add(_values);
                                _table.AcceptChanges();
                                _table.WriteXml(_path, XmlWriteMode.WriteSchema);
                                _created = true;
                            }
                            catch (Exception ex)
                            {
                                SCMS.LogError(this.GetType().Name, ex);
                                AddEvent(BackupEvent.Error, "Failed to create and / or complete database restore point.");

                                _trycounter = 0;

                                while (File.Exists(_rpfilename) &&
                                       _trycounter <= 30)
                                {
                                    try { File.Delete(_rpfilename); }
                                    catch { }

                                    _trycounter += 1;
                                    Thread.Sleep(100); Application.DoEvents();
                                }
                            }

                            if (_created)
                            {
                                _restorepoint = new RestorePointInfo(VisualBasic.CLng(_newrow["DetailId"]));
                            }

                            _table.Dispose(); _table = null;
                            Materia.RefreshAndManageCurrentProcess();
                        }
                        else
                        {
                            AddEvent(BackupEvent.Error, "Failed to create and / or complete database restore point.");

                            _trycounter = 0;

                            while (File.Exists(_rpfilename) &&
                                   _trycounter <= 30)
                            {
                                try { File.Delete(_rpfilename); }
                                catch { }

                                _trycounter += 1;
                                Thread.Sleep(100); Application.DoEvents();
                            }

                            Materia.RefreshAndManageCurrentProcess();
                        }
                    }
                    else
                    {
                        SCMS.LogError(this.GetType().Name, new Exception(_result.Error));
                        AddEvent(BackupEvent.Error, "Failed to create and / or complete database restore point.");

                        _trycounter = 0;

                        while (File.Exists(_rpfilename) &&
                               _trycounter <= 30)
                        {
                            try { File.Delete(_rpfilename); }
                            catch { }

                            _trycounter += 1;
                            Thread.Sleep(100); Application.DoEvents();
                        }

                        Materia.RefreshAndManageCurrentProcess();
                    }
                }
            }

            return(_restorepoint);
        }
Exemplo n.º 19
0
        private void CreateInitialUser(IDbConnection connection)
        {
            string    _path  = Application.StartupPath + "\\Xml\\defaultusers.xml";
            DataTable _table = SCMS.XmlToTable(_path);

            if (_table != null)
            {
                DataRow[] _rows = _table.Select("[ComputerName] = '" + Environment.MachineName.ToSqlValidString(true) + "' AND " +
                                                "[UserAccount] = '" + Environment.UserName.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    Cache.SyncTable(connection, "users");
                    bool      _exists      = false;
                    DataTable _cachedtable = Cache.GetCachedTable("users");
                    if (_cachedtable != null)
                    {
                        DataRow[] _exrows = _cachedtable.Select("[Username] LIKE '" + _rows[0]["Username"].ToString().ToSqlValidString(true) + "'");
                        if (_exrows.Length > 0)
                        {
                            _exists = true;
                        }
                    }

                    if (!_exists)
                    {
                        Cache.SyncTable(connection, "departments");
                        Cache.SyncTable(connection, "positions");

                        string _query = "";  _exists = false;

                        DataTable _depttable = Cache.GetCachedTable("departments");
                        if (_depttable != null)
                        {
                            DataRow[] _exrows = _depttable.Select("[Department] LIKE '" + _rows[0]["Department"].ToString().ToSqlValidString(true) + "'");
                            if (_exrows.Length > 0)
                            {
                                _exists = true;
                            }
                        }

                        if (!_exists)
                        {
                            _query += "INSERT INTO `departments`\n" +
                                      "(`Department`, `DateCreated`)\n" +
                                      "VALUES\n" +
                                      "('" + _rows[0]["Department"].ToString().ToSqlValidString() + "', NOW());\n";

                            object[]             _values = new object[_depttable.Columns.Count];
                            DataColumnCollection _cols   = _depttable.Columns;
                            _values[_cols["Department"].Ordinal]   = _rows[0]["Department"];
                            _values[_cols["DateCreated"].Ordinal]  = DateTime.Now;
                            _values[_cols["LastModified"].Ordinal] = DateTime.Now;

                            _depttable.Rows.Add(_values);
                        }

                        _exists = false;

                        DataTable _postntable = Cache.GetCachedTable("positions");
                        if (_postntable != null)
                        {
                            DataRow[] _exrows = _postntable.Select("[Position] LIKE '" + _rows[0]["Position"].ToString().ToSqlValidString(true) + "'");
                            if (_exrows.Length > 0)
                            {
                                _exists = true;
                            }
                        }

                        if (!_exists)
                        {
                            _query += "INSERT INTO `positions`\n" +
                                      "(`Position`, `DateCreated`)\n" +
                                      "VALUES\n" +
                                      "('" + _rows[0]["Position"].ToString().ToSqlValidString() + "', NOW());\n";

                            object[]             _values = new object[_postntable.Columns.Count];
                            DataColumnCollection _cols   = _postntable.Columns;
                            _values[_cols["Position"].Ordinal]     = _rows[0]["Position"];
                            _values[_cols["DateCreated"].Ordinal]  = DateTime.Now;
                            _values[_cols["LastModified"].Ordinal] = DateTime.Now;

                            _postntable.Rows.Add(_values);
                        }

                        StringBuilder _privileges = new StringBuilder();

                        for (int i = 1; i <= 700; i++)
                        {
                            _privileges.Append("1");
                        }

                        _query += "INSERT INTO `users`\n" +
                                  "(`Username`, `Password`, `FirstName`, `MiddleName`, `LastName`, `Department`, `Position`, `Active`, `Role`, `Privileges`, `AllCustomers`, `AllCompanies`, `DateCreated`)\n" +
                                  "VALUES\n" +
                                  "('" + _rows[0]["Username"].ToString().ToSqlValidString() + "', '" + _rows[0]["Password"].ToString().Encrypt(SCMS.EncryptionKey).ToSqlValidString() + "', " +
                                  "'" + _rows[0]["FirstName"].ToString().ToSqlValidString() + "', '" + _rows[0]["MiddleName"].ToString().ToSqlValidString() + "', '" + _rows[0]["LastName"].ToString().ToSqlValidString() + "', " +
                                  "'" + _rows[0]["Department"].ToString().ToSqlValidString() + "', '" + _rows[0]["Position"].ToString().ToSqlValidString() + "', 1, '" + SystemUserInfo.SuperUserRole.ToSqlValidString() + "', " +
                                  "'" + _privileges.ToString() + "', 1, 1, NOW());";

                        QueResult _result = Que.Execute(connection, _query);
                        if (String.IsNullOrEmpty(_result.Error.RLTrim()))
                        {
                            if (_depttable != null)
                            {
                                _depttable.AcceptChanges();
                            }
                            if (_postntable != null)
                            {
                                _postntable.AcceptChanges();
                            }
                            if (_cachedtable != null)
                            {
                                object[]             _values = new object[_cachedtable.Columns.Count];
                                DataColumnCollection _cols   = _cachedtable.Columns;
                                _values[_cols["Username"].Ordinal]     = _rows[0]["Username"];
                                _values[_cols["Password"].Ordinal]     = _rows[0]["Password"].ToString().Encrypt(SCMS.EncryptionKey);
                                _values[_cols["FirstName"].Ordinal]    = _rows[0]["FirstName"];
                                _values[_cols["MiddleName"].Ordinal]   = _rows[0]["MiddleName"];
                                _values[_cols["LastName"].Ordinal]     = _rows[0]["LastName"];
                                _values[_cols["Position"].Ordinal]     = _rows[0]["Position"];
                                _values[_cols["Department"].Ordinal]   = _rows[0]["Department"];
                                _values[_cols["Role"].Ordinal]         = SystemUserInfo.SuperUserRole;
                                _values[_cols["Privileges"].Ordinal]   = _privileges.ToString();
                                _values[_cols["AllCustomers"].Ordinal] = 1;
                                _values[_cols["AllCompanies"].Ordinal] = 1;
                                _values[_cols["DateCreated"].Ordinal]  = DateTime.Now;
                                _values[_cols["DateVoided"].Ordinal]   = DBNull.Value;

                                _cachedtable.Rows.Add(_values); _cachedtable.AcceptChanges();
                            }
                            Cache.Save();
                        }
                        else
                        {
                            if (_depttable != null)
                            {
                                _depttable.RejectChanges();
                            }
                            if (_postntable != null)
                            {
                                _postntable.RejectChanges();
                            }
                            if (_cachedtable != null)
                            {
                                _cachedtable.RejectChanges();
                            }
                        }

                        _result.Dispose(); Materia.RefreshAndManageCurrentProcess();
                    }
                }

                _table.Dispose(); _table = null;
                Materia.RefreshAndManageCurrentProcess();
            }
        }
Exemplo n.º 20
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();
            }
        }
Exemplo n.º 21
0
        private void CreateInitialCurrencies(IDbConnection connection)
        {
            string    _path = Application.StartupPath + "\\Xml\\defaultcurrencies.xml";
            DataTable _defaultcurrencies = SCMS.XmlToTable(_path);

            if (_defaultcurrencies != null)
            {
                Cache.SyncTable(connection, "currencies");
                DataTable _currencies = Cache.GetCachedTable("currencies");

                if (_currencies != null)
                {
                    string    _query = "";
                    long      _cashathandac = 54005; long _exrateac = 34625;
                    DataTable _accounts = Cache.GetCachedTable("accounts");

                    if (_accounts != null)
                    {
                        DataRow[] _rows = _accounts.Select("[AccountName] LIKE 'Cash at hand'");
                        if (_rows.Length > 0)
                        {
                            _cashathandac = (long)_rows[0]["AccountCode"];
                        }

                        _rows = _accounts.Select("[AccountName] LIKE 'Exchange rate differences'");
                        if (_rows.Length > 0)
                        {
                            _exrateac = (long)_rows[0]["AccountCode"];
                        }
                    }

                    for (int i = 0; i <= (_defaultcurrencies.Rows.Count - 1); i++)
                    {
                        DataRow   _row  = _defaultcurrencies.Rows[i];
                        DataRow[] _rows = _currencies.Select("[Currency] LIKE '" + _row["Currency"].ToString().ToSqlValidString(true) + "'");
                        if (_rows.Length <= 0)
                        {
                            _query += "INSERT INTO `currencies`\n" +
                                      "(`Currency`, `Description`, `AccountCode`, `ExchangeRateAccountCode`, `DateCreated`)\n" +
                                      "VALUES\n" +
                                      "('" + _row["Currency"].ToString().ToSqlValidString() + "', '" + _row["Description"].ToString().ToSqlValidString() + "', " + _cashathandac.ToString() + ", " + _exrateac.ToString() + ", NOW());";

                            DataColumnCollection _cols   = _currencies.Columns;
                            object[]             _values = new object[_cols.Count];
                            _values[_cols["Currency"].Ordinal]                = _row["Currency"];
                            _values[_cols["Description"].Ordinal]             = _row["Description"];
                            _values[_cols["AccountCode"].Ordinal]             = _cashathandac;
                            _values[_cols["ExchangeRateAccountCode"].Ordinal] = _exrateac;
                            _values[_cols["DateCreated"].Ordinal]             = DateTime.Now;
                            _values[_cols["LastModified"].Ordinal]            = DateTime.Now;
                            _currencies.Rows.Add(_values);
                        }
                    }

                    if (!String.IsNullOrEmpty(_query.RLTrim()))
                    {
                        QueResult _result = Que.Execute(connection, _query);
                        if (String.IsNullOrEmpty(_result.Error.RLTrim()))
                        {
                            _currencies.AcceptChanges(); Cache.Save();
                        }
                        else
                        {
                            _currencies.RejectChanges();
                        }
                        _result.Dispose(); _result = null; Materia.RefreshAndManageCurrentProcess();
                    }
                }

                _defaultcurrencies.Dispose(); _defaultcurrencies = null;
                Materia.RefreshAndManageCurrentProcess();
            }
        }
Exemplo n.º 22
0
        private void mnuExecuteScripts_Click(object sender, EventArgs e)
        {
            if (!mnuExecuteScripts.Enabled)
            {
                return;
            }

            OpenFileDialog _dialog = new OpenFileDialog();

            _dialog.CheckFileExists = true;
            _dialog.CheckPathExists = true;
            _dialog.DefaultExt      = SCMS.ScriptFileExtension;
            _dialog.Filter          = "SCMS Database Script Files (*." + SCMS.ScriptFileExtension + ")|*." + SCMS.ScriptFileExtension;
            _dialog.Title           = "Browse Database Script File";

            string _filename = "";

            if (_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _filename = (_dialog.FileName);
            }
            _dialog.Dispose(); _dialog = null;
            Materia.RefreshAndManageCurrentProcess();

            if (!string.IsNullOrEmpty(_filename.RLTrim()))
            {
                if (File.Exists(_filename))
                {
                    string _tempdir = Application.StartupPath + "\\Temp";

                    if (!Directory.Exists(_tempdir))
                    {
                        try { Directory.CreateDirectory(_tempdir); }
                        catch { }
                    }

                    if (Directory.Exists(_tempdir))
                    {
                        FileInfo _file      = new FileInfo(_filename);
                        string   _decrypted = _file.Decrypt(SCMS.EncryptionKey);
                        string   _tempfile  = _tempdir + "\\" + Path.GetFileNameWithoutExtension(_filename) + ".xml";

                        FileInfo _xmlfile = Materia.WriteToFile(_tempfile, _decrypted, false);
                        if (_xmlfile != null)
                        {
                            DataTable _table = SCMS.XmlToTable(_xmlfile.FullName);
                            if (_table != null)
                            {
                                if (_table.TableName == "scripts")
                                {
                                    if (_table.Rows.Count > 0)
                                    {
                                        DatabaseScriptInfo            _script = new DatabaseScriptInfo(_table);
                                        DatabaseScriptExecutionResult _result = _script.Execute();
                                    }
                                    else
                                    {
                                        MsgBoxEx.Shout("The specified file does not contain anyt releveant database script information.", "Execute Database Script");
                                    }
                                }
                                else
                                {
                                    MsgBoxEx.Shout("The specified file does not contain anyt releveant database script information.", "Execute Database Script");
                                }
                            }
                            else
                            {
                                MsgBoxEx.Alert("Failed to extract script information from the specified file.", "Execute Database Script");
                            }
                        }
                        else
                        {
                            MsgBoxEx.Alert("Failed to extract script information from the specified file.", "Execute Database Script");
                        }
                    }
                    else
                    {
                        MsgBoxEx.Alert("Failed to extract script information from the specified file.", "Execute Database Script");
                    }
                }
            }
        }