예제 #1
0
        private void InitializeInfo()
        {
            DataTable _currencies = Cache.GetCachedTable("currencies");

            if (_currencies != null)
            {
                DataRow[] _rows = _currencies.Select("[Currency] LIKE '" + _currency.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["Currency"]))
                    {
                        txtCurrency.Text = _row["Currency"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Description"]))
                    {
                        txtDescription.Text = _row["Description"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["AccountCode"]))
                    {
                        cboAccount.SelectedValue = _row["AccountCode"];
                    }
                    if (VisualBasic.IsNumeric(_row["ExchangeRateAccountCode"]))
                    {
                        cboExchangeRateDiff.SelectedValue = _row["ExchangeRateAccountCode"];
                    }
                }
            }
        }
예제 #2
0
        private void InitializePositions()
        {
            DataTable _positions = Cache.GetCachedTable("positions");

            if (_positions != null)
            {
                DataTable _datasource = _positions.Replicate();

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

                _datasource.DefaultView.Sort   = "[Position]";
                cboPosition.DataSource         = _datasource;
                cboPosition.DisplayMember      = "Position";
                cboPosition.ValueMember        = "Position";
                cboPosition.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                cboPosition.AutoCompleteSource = AutoCompleteSource.ListItems;

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

                cboPosition.Enabled = true;
            }
        }
예제 #3
0
        /// <summary>
        /// Creates a new instance of CompanyInfo.
        /// </summary>
        /// <param name="code"></param>
        public CompanyInfo(string code)
        {
            _company = code; _name = "";

            Action <IDbConnection, string> _delegate = new Action <IDbConnection, string>(Cache.SyncTable);
            IAsyncResult _result = _delegate.BeginInvoke(SCMS.Connection, "companies", null, _delegate);

            while (!_result.IsCompleted)
            {
                Thread.Sleep(1); Application.DoEvents();
            }
            _delegate.EndInvoke(_result);

            DataTable _table = Cache.GetCachedTable("companies");

            if (_table != null)
            {
                DataRow[] _rows = _table.Select("[Company] LIKE '" + _company.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    if (!Materia.IsNullOrNothing(_rows[0]["Name"]))
                    {
                        _name = _rows[0]["Name"].ToString();
                    }
                }
            }
        }
        private void InitializeInfo()
        {
            DataTable _paymentterms = Cache.GetCachedTable("paymentterms");

            if (_paymentterms != null)
            {
                DataRow[] _rows = _paymentterms.Select("[PaymentTerm] LIKE '" + _paymentterm.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["PaymentTerm"]))
                    {
                        txtPaymentTerm.Text = _row["PaymentTerm"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Description"]))
                    {
                        txtDescription.Text = _row["Description"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Term"]))
                    {
                        cboTerms.SelectedValue = _row["Term"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["Days"]))
                    {
                        txtDays.Value = VisualBasic.CInt(_row["Days"]);
                    }
                    if (VisualBasic.IsNumeric(_row["Months"]))
                    {
                        txtMonths.Value = VisualBasic.CInt(_row["Months"]);
                    }
                }
            }
        }
        private void InitializeInfo()
        {
            DataTable _additionalcharges = Cache.GetCachedTable("additionalcharges");

            if (_additionalcharges != null)
            {
                DataRow[] _rows = _additionalcharges.Select("[AdditionalCharge] LIKE '" + _additionalcharge.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["AdditionalCharge"]))
                    {
                        txtDescription.Text = _row["AdditionalCharge"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["ChargeGroup"]))
                    {
                        cboGroup.SelectedValue = _row["ChargeGroup"];
                    }
                    if (VisualBasic.IsNumeric(_row["AccountCode"]))
                    {
                        cboAccount.SelectedValue = _row["AccountCode"];
                    }
                }
            }
        }
예제 #6
0
        private void InitializeInfo()
        {
            DataTable _bankmisc = Cache.GetCachedTable("bankmiscellaneous");

            if (_bankmisc != null)
            {
                DataRow[] _rows = _bankmisc.Select("[BankMiscellaneous] LIKE '" + _bankmiscellaneous.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["BankMiscellaneous"]))
                    {
                        txtDescription.Text = _row["BankMiscellaneous"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["AccountCode"]))
                    {
                        cboAccount.SelectedValue = _row["AccountCode"];
                    }
                    if (VisualBasic.IsNumeric(_row["Type"]))
                    {
                        cboType.SelectedIndex = VisualBasic.CInt(_row["Type"]);
                    }
                }
            }
        }
        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"]);
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Loads a bank account information in this dialog thru the given bank account code.
        /// </summary>
        /// <param name="code"></param>
        public void LoadBankAccountInformation(string code)
        {
            DataTable _bankaccounts = Cache.GetCachedTable("bankaccounts");

            _bankaccountcode = code; _isnew = false; _withupdates = false;
            _updated         = false; _isshown = false; _isinbackground = false;

            Text = Text.Replace(" *", "").Replace("*", "");

            if (_bankaccounts != null)
            {
                DataRow[] _rows = _bankaccounts.Select("[BankAccountCode] LIKE '" + _bankaccountcode.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["AccountNo"]))
                    {
                        txtAccountNo.Text = _row["AccountNo"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["AccountName"]))
                    {
                        txtAccountName.Text = _row["AccountName"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Currency"]))
                    {
                        cboCurrency.SelectedValue = _row["Currency"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["AccountCode"]))
                    {
                        cboAccountCode.SelectedValue = _row["AccountCode"];
                    }
                    if (!Materia.IsNullOrNothing(_row["Swift"]))
                    {
                        txtSwift.Text = _row["Swift"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["IBAN"]))
                    {
                        txtIban.Text = _row["IBAN"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Bank"]))
                    {
                        cboBankingCompany.SelectedValue = _row["Bank"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Branch"]))
                    {
                        txtBranch.Text = _row["Branch"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Notes"]))
                    {
                        txtNotes.Text = _row["Notes"].ToString();
                    }
                }
            }

            if (!_isshown)
            {
                _isshown = true;
            }
        }
예제 #9
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();
            }
        }
예제 #10
0
        private void InitializeSearches()
        {
            DataTable _bankaccounts = Cache.GetCachedTable("bankaccounts");

            if (_bankaccounts != null)
            {
                if (txtSearch.AutoCompleteCustomSource == null)
                {
                    txtSearch.AutoCompleteCustomSource = new AutoCompleteStringCollection();
                }
                txtSearch.AutoCompleteCustomSource.Clear();

                for (int i = 0; i <= (_bankaccounts.Rows.Count - 1); i++)
                {
                    DataRow _row = _bankaccounts.Rows[i];

                    if (!Materia.IsNullOrNothing(_row["AccountNo"]))
                    {
                        if (!txtSearch.AutoCompleteCustomSource.Contains(_row["AccountNo"].ToString()))
                        {
                            txtSearch.AutoCompleteCustomSource.Add(_row["AccountNo"].ToString());
                        }
                    }

                    if (!Materia.IsNullOrNothing(_row["AccountName"]))
                    {
                        if (!txtSearch.AutoCompleteCustomSource.Contains(_row["AccountName"].ToString()))
                        {
                            txtSearch.AutoCompleteCustomSource.Add(_row["AccountName"].ToString());
                        }
                    }

                    if (VisualBasic.IsNumeric(_row["AccountCode"]))
                    {
                        if (!txtSearch.AutoCompleteCustomSource.Contains(_row["AccountCode"].ToString()))
                        {
                            txtSearch.AutoCompleteCustomSource.Add(_row["AccountCode"].ToString());
                        }
                    }

                    if (!Materia.IsNullOrNothing(_row["Bank"]))
                    {
                        if (!txtSearch.AutoCompleteCustomSource.Contains(_row["Bank"].ToString()))
                        {
                            txtSearch.AutoCompleteCustomSource.Add(_row["Bank"].ToString());
                        }
                    }
                }

                txtSearch.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
            }
        }
예제 #11
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();
                    }
                }
            }
        }
예제 #12
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();
            }
        }
예제 #13
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);
        }
예제 #14
0
        private void LocationInfoDialog_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false; this.ManageOnDispose();
            SCMS.Validators.Add(this); AttachEditorHandler();

            txtLocation.SetAsRequired();

            DataTable _locations = Cache.GetCachedTable("locations");

            if (_locations != null)
            {
                DataRow[] _rows = _locations.Select("[LocationCode] LIKE '" + _locationcode.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    _location = _rows[0]["Location"].ToString();
                }
            }
            txtLocation.Text = _location;
        }
        private void InitializeUsers()
        {
            if (grdUsers.Redraw)
            {
                grdUsers.BeginUpdate();
            }
            grdUsers.ClearRowsAndColumns();

            DataTable _users = Cache.GetCachedTable("users");

            if (_users != null)
            {
                var _query = from _usr in _users.AsEnumerable()
                             select new
                {
                    Username      = _usr.Field <string>("Username"),
                    AccountHolder = _usr.Field <string>("FirstName") + " " + _usr.Field <string>("LastName")
                };

                DataTable _datasource = new DataTable();
                _datasource.TableName = "users";
                DataColumn _pk = _datasource.Columns.Add("Username", typeof(string));
                _datasource.Columns.Add("AccountHolder", 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.Username, _row.AccountHolder, true });
                }

                _datasource.AcceptChanges(); _datasource.DefaultView.Sort = "[AccountHolder]";
                grdUsers.DataSource = _datasource;
                FormatGrid(grdUsers);

                while (!grdUsers.Redraw)
                {
                    grdUsers.EndUpdate();
                }
            }
        }
예제 #16
0
        private void InitializeInfo()
        {
            DataTable _units = Cache.GetCachedTable("measurements");

            if (_units != null)
            {
                DataRow[] _rows = _units.Select("[Unit] LIKE '" + _measurement.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["Unit"]))
                    {
                        txtUnit.Text = _row["Unit"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Description"]))
                    {
                        txtDescription.Text = _row["Description"].ToString();
                    }
                }
            }
        }
예제 #17
0
        private void InitializeInfo()
        {
            DataTable _partnames = Cache.GetCachedTable("partnames");

            if (_partnames != null)
            {
                DataRow[] _rows = _partnames.Select("[PartName] LIKE '" + _partname.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["PartName"]))
                    {
                        txtPartName.Text = _row["PartName"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["PartCategory"]))
                    {
                        cboPartCategory.SelectedValue = _row["PartCategory"];
                    }
                }
            }
        }
예제 #18
0
        private void InitializeInfo()
        {
            DataTable _models = Cache.GetCachedTable("models");

            if (_models != null)
            {
                DataRow[] _rows = _models.Select("[ModelCode] LIKE '" + _modelcode.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["Model"]))
                    {
                        txtModel.Text = _row["Model"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Brand"]))
                    {
                        cboBrand.SelectedValue = _row["Brand"].ToString();
                    }
                }
            }
        }
예제 #19
0
        private void InitializeInfo()
        {
            DataTable _signatories = Cache.GetCachedTable("signatories");
            DataTable _users       = Cache.GetCachedTable("users");

            if (_signatories != null &&
                _users != null)
            {
                var _query = from _signs in _signatories.AsEnumerable()
                             join _usr in _users.AsEnumerable() on _signs.Field <string>("Username") equals _usr.Field <string>("Username")
                                 where _signs.Field <long>("DetailId") == _id
                             select new
                {
                    Username   = _signs.Field <string>("Username"),
                    RoleId     = _signs.Field <int>("RoleId"),
                    FullName   = _usr.Field <string>("FirstName") + " " + _usr.Field <string>("LastName"),
                    Department = _usr.Field <string>("Department"),
                    Position   = _usr.Field <string>("Position"),
                    CashLimit  = _signs.Field <decimal>("CashLimit"),
                    BankLimit  = _signs.Field <decimal>("BankLimit")
                };

                foreach (var _row in _query)
                {
                    cboUsername.SelectedValue      = _row.Username;
                    cboRole.SelectedValue          = _row.RoleId;
                    txtFullName.Text               = _row.FullName;
                    txtDepartment.Text             = _row.Department;
                    txtPosition.Text               = _row.Position;
                    txtBankLimit.Value             = VisualBasic.CDbl(_row.BankLimit);
                    txtBankLimit.LockUpdateChecked = (_row.BankLimit > 0);
                    txtCashLimit.Value             = VisualBasic.CDbl(_row.CashLimit);
                    txtCashLimit.LockUpdateChecked = (_row.CashLimit > 0);
                }
            }
        }
예제 #20
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!btnSave.Enabled)
            {
                return;
            }

            Validator _validator = SCMS.Validators[this];

            if (!Materia.Valid(_validator, txtSystemVersion, !string.IsNullOrEmpty(txtSystemVersion.Text.RLTrim()), "Please specify the applicable system version for the current script."))
            {
                return;
            }
            if (!Materia.Valid(_validator, txtTitle, !string.IsNullOrEmpty(txtTitle.Text.RLTrim()), "Please specify database script's title."))
            {
                return;
            }
            if (!Materia.Valid(_validator, txtScript, !string.IsNullOrEmpty(txtScript.Text.RLTrim()), "Please specify database script's sql statement."))
            {
                return;
            }
            if (!Materia.Valid(_validator, txtDescription, !string.IsNullOrEmpty(txtDescription.Text.RLTrim()), "Please specify database script's description."))
            {
                return;
            }

            string _pattern = "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+";

            if (!Materia.Valid(_validator, txtSystemVersion, Regex.IsMatch(txtSystemVersion.Text, _pattern), "Please specify a valid system version."))
            {
                return;
            }

            MatchCollection _matches = Regex.Matches(txtSystemVersion.Text, _pattern);

            if (_matches.Count > 0)
            {
                string _match = _matches[0].Value;
                if (!Materia.Valid(_validator, txtSystemVersion, _match == txtSystemVersion.Text, "Please specify a valid system version."))
                {
                    return;
                }
            }
            DataTable _scripts = Cache.GetCachedTable("scripts");

            if (_scripts != null)
            {
                string _query = ""; string _refno = "";
                DataColumnCollection _cols = _scripts.Columns;

                if (_isnew)
                {
                    Func <string, bool, string> _delegate = new Func <string, bool, string>(SCMS.GetTableSeriesNumber);
                    IAsyncResult _result = _delegate.BeginInvoke("scripts", true, null, _delegate);

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

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

                        return;
                    }

                    string _seriesno = _delegate.EndInvoke(_result);
                    _refno = "SQL-" + SCMS.CurrentCompany.Company + "-" + _seriesno;

                    _query = "INSERT INTO `scripts`\n" +
                             "(`ReferenceNo`, `Title`, `Author`, `Script`, `SystemVersion`, `RequireBackup`, `RequireAppRestart`, `RequirePcRestart`, `Description`, `DateCreated`)\n" +
                             "VALUES\n" +
                             "('" + _refno.ToSqlValidString() + "', '" + txtTitle.Text.ToSqlValidString() + "', '" + txtAuthor.Text.ToSqlValidString() + "', '" + txtScript.Text.ToSqlValidString() + "', '" + txtSystemVersion.Text.ToSqlValidString() + "', " + (chkBackup.Checked ? "1" : "0") + ", " + (chkRestartApp.Checked ? "1" : "0") + ", " + (chkRestartPc.Checked ? "1" : "0") + ", '" + txtDescription.Text.ToSqlValidString() + "', NOW());";

                    object[] _values = new object[_cols.Count];
                    _values[_cols["ReferenceNo"].Ordinal]       = _refno;
                    _values[_cols["Title"].Ordinal]             = txtTitle.Text;
                    _values[_cols["Author"].Ordinal]            = txtAuthor.Text;
                    _values[_cols["Script"].Ordinal]            = txtScript.Text;
                    _values[_cols["SystemVersion"].Ordinal]     = txtSystemVersion.Text;
                    _values[_cols["RequireBackup"].Ordinal]     = (chkBackup.Checked? 1 : 0);
                    _values[_cols["RequireAppRestart"].Ordinal] = (chkRestartApp.Checked ? 1 : 0);
                    _values[_cols["RequirePcRestart"].Ordinal]  = (chkRestartPc.Checked ? 1 : 0);
                    _values[_cols["Description"].Ordinal]       = txtDescription.Text;
                    _values[_cols["DateCreated"].Ordinal]       = DateTime.Now;
                    _values[_cols["LastModified"].Ordinal]      = DateTime.Now;
                    _scripts.Rows.Add(_values);
                }
                else
                {
                    _query = "UPDATE `scripts` SET\n" +
                             "`Title` = '" + txtTitle.Text.ToSqlValidString() + "', `Author` = '" + txtAuthor.Text.ToSqlValidString() + "', `Author` = '" + txtAuthor.Text.ToSqlValidString() + "', `Script` = '" + txtScript.Text.ToSqlValidString() + "', `SystemVersion` = '" + txtSystemVersion.Text.ToSqlValidString() + "', `RequireBackup` = " + (chkBackup.Checked ? "1" : "0") + ", `RequireAppRestart` = " + (chkRestartApp.Checked ? "1" : "0") + ", `RequirePcRestart` = " + (chkRestartPc.Checked ? "1" : "0") + ", `Description` = '" + txtDescription.Text.ToSqlValidString() + "'\n" +
                             "WHERE\n" +
                             "(`ReferenceNo` LIKE '" + _referenceno.ToSqlValidString() + "');";

                    DataRow[] _existing = _scripts.Select("[ReferenceNo] LIKE '" + _referenceno.ToSqlValidString(true) + "'");

                    if (_existing.Length > 0)
                    {
                        _existing[0]["Title"]             = txtTitle.Text;
                        _existing[0]["Author"]            = txtAuthor.Text;
                        _existing[0]["Script"]            = txtScript.Text;
                        _existing[0]["SystemVersion"]     = txtSystemVersion.Text;
                        _existing[0]["RequireBackup"]     = (chkBackup.Checked? 1 : 0);
                        _existing[0]["RequireAppRestart"] = (chkRestartApp.Checked ? 1 : 0);
                        _existing[0]["RequirePcRestart"]  = (chkRestartPc.Checked? 1 : 0);
                        _existing[0]["Description"]       = txtDescription.Text;
                    }
                }


                if (!string.IsNullOrEmpty(_query.RLTrim()))
                {
                    btnSave.Enabled = false; btnSaveAndClose.Enabled = false;

                    IAsyncResult _result = Que.BeginExecution(SCMS.Connection, _query);

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

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

                        return;
                    }
                    else
                    {
                        QueResult _queresult = Que.EndExecution(_result);

                        if (string.IsNullOrEmpty(_queresult.Error.RLTrim()))
                        {
                            UserAction _action = UserAction.Add;
                            if (!_isnew)
                            {
                                _action = UserAction.Edit;
                            }

                            string _log = "Added a database script : " + _refno + ".";
                            if (!_isnew)
                            {
                                _log = "Updated database script : " + _referenceno + ".";
                            }

                            _scripts.AcceptChanges();
                            if (_isnew)
                            {
                                _referenceno = _refno;
                                _isnew       = false;

                                btnExport.Enabled = true;
                                btnExport.Show(); btnExport.BringToFront();

                                btnExecute.Enabled = true;
                                btnExecute.Show(); btnExecute.BringToFront();
                            }
                            if (_updated)
                            {
                                _updated = false;
                            }
                            if (!_withupdates)
                            {
                                _withupdates = true;
                            }
                            Text   = Text.Replace(" *", "").Replace("*", "");
                            Cursor = Cursors.WaitCursor;

                            IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(_action, _log, _referenceno);
                            _logresult.WaitToFinish();

                            Cursor = Cursors.Default;

                            if (sender == btnSaveAndClose)
                            {
                                DialogResult = System.Windows.Forms.DialogResult.OK; Close();
                            }
                        }
                        else
                        {
                            if (_queresult.Error.Contains("duplicate"))
                            {
                                btnSave_Click(sender, new EventArgs());
                            }
                            else
                            {
                                SCMS.LogError(this.GetType().Name, new Exception(_queresult.Error));
                                MsgBoxEx.Alert("Failed to save the current database script.", "Save Database Script");
                            }

                            _scripts.RejectChanges();
                        }

                        _queresult.Dispose();
                    }

                    btnSave.Enabled = true; btnSaveAndClose.Enabled = true;
                }
            }
            else
            {
                if (sender == btnSaveAndClose)
                {
                    DialogResult = System.Windows.Forms.DialogResult.None; Close();
                }
            }
        }
예제 #21
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!btnSave.Enabled)
            {
                return;
            }

            Validator _validator = SCMS.Validators[this];

            if (!Materia.Valid(_validator, txtBrand, !string.IsNullOrEmpty(txtBrand.Text.RLTrim()), "Please specify vehicle make name."))
            {
                return;
            }
            DataTable _brands = Cache.GetCachedTable("brands");

            if (_brands != null)
            {
                DataRow[] _rows = _brands.Select("([Brand] LIKE '" + txtBrand.Text.ToSqlValidString(true) + "') AND\n" +
                                                 "NOT ([Brand] LIKE '" + _brand.ToSqlValidString(true) + "')");

                if (!Materia.Valid(_validator, txtBrand, _rows.Length <= 0, "Brand already exists."))
                {
                    return;
                }

                string _query = "";
                DataColumnCollection _cols = _brands.Columns;

                if (_isnew)
                {
                    _query = "INSERT INTO `brands`\n" +
                             "(`Brand`, `DateCreated`)\n" +
                             "VALUES\n" +
                             "('" + txtBrand.Text.ToSqlValidString() + "', NOW());";

                    object[] _values = new object[_cols.Count];
                    _values[_cols["Brand"].Ordinal]        = txtBrand.Text;
                    _values[_cols["DateCreated"].Ordinal]  = DateTime.Now;
                    _values[_cols["LastModified"].Ordinal] = DateTime.Now;
                    _brands.Rows.Add(_values);
                }
                else
                {
                    _query = "UPDATE `brands` SET\n" +
                             "`Brand` = '" + txtBrand.Text.ToSqlValidString() + "'\n" +
                             "WHERE\n" +
                             "(`Brand` LIKE '" + _brand.ToSqlValidString() + "');";
                    DataRow[] _existing = _brands.Select("[Brand] LIKE '" + _brand.ToSqlValidString(true) + "'");
                    if (_existing.Length > 0)
                    {
                        _existing[0]["Brand"] = txtBrand.Text;
                    }
                }

                if (!string.IsNullOrEmpty(_query.RLTrim()))
                {
                    btnSave.Enabled = false; btnSaveAndClose.Enabled = false;

                    if (txtBrand.Text == _brand)
                    {
                        if (_isnew)
                        {
                            _isnew = false;
                        }
                        if (_updated)
                        {
                            _updated = false;
                        }
                        if (_withupdates)
                        {
                            _withupdates = false;
                        }

                        Text = Text.Replace(" *", "").Replace("*", "");

                        if (sender == btnSaveAndClose)
                        {
                            DialogResult = System.Windows.Forms.DialogResult.OK; Close();
                        }

                        return;
                    }

                    IAsyncResult _result = Que.BeginExecution(SCMS.Connection, _query);

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

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

                        return;
                    }
                    else
                    {
                        QueResult _queresult = Que.EndExecution(_result);

                        if (string.IsNullOrEmpty(_queresult.Error.RLTrim()))
                        {
                            UserAction _action = UserAction.Add;
                            if (!_isnew)
                            {
                                _action = UserAction.Edit;
                            }

                            string _log = "Added a new brand : " + txtBrand.Text + ".";
                            if (!_isnew)
                            {
                                _log = "Updated brand : " + _brand + (_brand != txtBrand.Text ? " to " + txtBrand.Text : "").ToString() + ".";
                            }

                            _brands.AcceptChanges(); _brand = txtBrand.Text;
                            if (_isnew)
                            {
                                _isnew = false;
                            }
                            if (_updated)
                            {
                                _updated = false;
                            }
                            if (!_withupdates)
                            {
                                _withupdates = true;
                            }
                            Text   = Text.Replace(" *", "").Replace("*", "");
                            Cursor = Cursors.WaitCursor;

                            IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(_action, _log);
                            _logresult.WaitToFinish();

                            Cursor = Cursors.Default;

                            if (sender == btnSaveAndClose)
                            {
                                DialogResult = System.Windows.Forms.DialogResult.OK; Close();
                            }
                        }
                        else
                        {
                            if (_queresult.Error.Contains("duplicate"))
                            {
                                bool _invalid = Materia.Valid(_validator, txtBrand, false, "Brand already exists.");
                            }
                            else
                            {
                                SCMS.LogError(this.GetType().Name, new Exception(_queresult.Error));
                                MsgBoxEx.Alert("Failed to save the current brand.", "Save Brand");
                            }

                            _brands.RejectChanges();
                        }

                        _queresult.Dispose();
                    }

                    btnSave.Enabled = true; btnSaveAndClose.Enabled = true;
                }
            }
            else
            {
                if (sender == btnSaveAndClose)
                {
                    DialogResult = System.Windows.Forms.DialogResult.None; Close();
                }
            }
        }
예제 #22
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!btnSave.Enabled)
            {
                return;
            }

            Validator _validator = SCMS.Validators[this];

            if (!Materia.Valid(_validator, txtLocation, !string.IsNullOrEmpty(txtLocation.Text.RLTrim()), "Please specify location name."))
            {
                return;
            }
            DataTable _locations = Cache.GetCachedTable("locations");

            if (_locations != null)
            {
                DataRow[] _rows = _locations.Select("([Location] LIKE '" + txtLocation.Text.ToSqlValidString(true) + "' AND\n" +
                                                    " [Company] LIKE '" + SCMS.CurrentCompany.Company.ToSqlValidString(true) + "') AND\n" +
                                                    "NOT ([LocationCode] LIKE '" + _locationcode.ToSqlValidString(true) + "')");

                if (!Materia.Valid(_validator, txtLocation, _rows.Length <= 0, "Location already exists."))
                {
                    return;
                }

                string _query = ""; string _refno = _locationcode;
                DataColumnCollection _cols = _locations.Columns;

                if (_isnew)
                {
                    Func <string, bool, string> _delegate = new Func <string, bool, string>(SCMS.GetTableSeriesNumber);
                    IAsyncResult _result = _delegate.BeginInvoke("locations", true, null, _delegate);

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

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

                        return;
                    }

                    string _seriesnumber = _delegate.EndInvoke(_result);
                    _refno = SCMS.CurrentCompany.Company + "-" + _seriesnumber;

                    _query = "INSERT INTO `locations`\n" +
                             "(`LocationCode`, `Location`, `Company`, `DateCreated`)\n" +
                             "VALUES\n" +
                             "('" + _refno.ToSqlValidString() + "', '" + txtLocation.Text.ToSqlValidString() + "', '" + SCMS.CurrentCompany.Company.ToSqlValidString() + "', NOW());";

                    object[] _values = new object[_cols.Count];
                    _values[_cols["LocationCode"].Ordinal] = _refno;
                    _values[_cols["Location"].Ordinal]     = txtLocation.Text;
                    _values[_cols["Company"].Ordinal]      = SCMS.CurrentCompany.Company;
                    _values[_cols["DateCreated"].Ordinal]  = DateTime.Now;
                    _values[_cols["LastModified"].Ordinal] = DateTime.Now;
                    _locations.Rows.Add(_values);
                }
                else
                {
                    _query = "UPDATE `locations` SET\n" +
                             "`Location` = '" + txtLocation.Text.ToSqlValidString() + "'\n" +
                             "WHERE\n" +
                             "(`LocationCode` LIKE '" + _locationcode.ToSqlValidString() + "');";

                    DataRow[] _existing = _locations.Select("[LocationCode] LIKE '" + _locationcode.ToSqlValidString(true) + "'");
                    if (_existing.Length > 0)
                    {
                        _existing[0]["Location"] = txtLocation.Text;
                    }
                }

                if (!string.IsNullOrEmpty(_query.RLTrim()))
                {
                    btnSave.Enabled = false; btnSaveAndClose.Enabled = false;

                    if (txtLocation.Text == _location)
                    {
                        if (_isnew)
                        {
                            _isnew = false;
                        }
                        if (_updated)
                        {
                            _updated = false;
                        }
                        if (_withupdates)
                        {
                            _withupdates = false;
                        }

                        Text = Text.Replace(" *", "").Replace("*", "");

                        if (sender == btnSaveAndClose)
                        {
                            DialogResult = System.Windows.Forms.DialogResult.OK; Close();
                        }

                        return;
                    }

                    IAsyncResult _result = Que.BeginExecution(SCMS.Connection, _query);

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

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

                        return;
                    }
                    else
                    {
                        QueResult _queresult = Que.EndExecution(_result);

                        if (string.IsNullOrEmpty(_queresult.Error.RLTrim()))
                        {
                            UserAction _action = UserAction.Add;
                            if (!_isnew)
                            {
                                _action = UserAction.Edit;
                            }

                            string _log = "Added a new location : " + txtLocation.Text + ".";
                            if (!_isnew)
                            {
                                _log = "Updated location : " + _location + (_location != txtLocation.Text ? " to " + txtLocation.Text : "").ToString() + ".";
                            }

                            _locations.AcceptChanges(); _locationcode = _refno;
                            _location = txtLocation.Text;
                            if (_isnew)
                            {
                                _isnew = false;
                            }
                            if (_updated)
                            {
                                _updated = false;
                            }
                            if (!_withupdates)
                            {
                                _withupdates = true;
                            }
                            Text   = Text.Replace(" *", "").Replace("*", "");
                            Cursor = Cursors.WaitCursor;

                            IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(_action, _log);
                            _logresult.WaitToFinish();

                            Cursor = Cursors.Default;

                            if (sender == btnSaveAndClose)
                            {
                                DialogResult = System.Windows.Forms.DialogResult.OK; Close();
                            }
                        }
                        else
                        {
                            if (_queresult.Error.Contains("duplicate"))
                            {
                                bool _invalid = Materia.Valid(_validator, txtLocation, false, "Location already exists.");
                            }
                            else
                            {
                                SCMS.LogError(this.GetType().Name, new Exception(_queresult.Error));
                                MsgBoxEx.Alert("Failed to save the current location.", "Save Location");
                            }

                            _locations.RejectChanges();
                        }

                        _queresult.Dispose();
                    }

                    btnSave.Enabled = true; btnSaveAndClose.Enabled = true;
                }
            }
            else
            {
                if (sender == btnSaveAndClose)
                {
                    DialogResult = System.Windows.Forms.DialogResult.None; Close();
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!btnSave.Enabled)
            {
                return;
            }

            Validator _validator = SCMS.Validators[this];

            if (!Materia.Valid(_validator, txtValue, txtValue.Value > 0, "Please specify currency denomination value."))
            {
                return;
            }
            if (!Materia.Valid(_validator, cboCurrency, cboCurrency.SelectedIndex >= 0, "Please specify a valid currency."))
            {
                return;
            }

            DataTable _denominations = Cache.GetCachedTable("currencydenominations");
            DataRow   _newrow        = null;

            if (_denominations != null)
            {
                DataRow[] _rows = _denominations.Select("([Denomination] = " + txtValue.Value.ToSqlValidString() + " AND\n" +
                                                        " [Currency] LIKE '" + cboCurrency.SelectedValue.ToString().ToSqlValidString(true) + "') AND\n" +
                                                        "([DetailId] <> " + _id.ToString() + ")");

                if (!Materia.Valid(_validator, txtValue, _rows.Length <= 0, "Currency denomination already exists."))
                {
                    return;
                }

                string _query = "";
                DataColumnCollection _cols = _denominations.Columns;

                if (_isnew)
                {
                    _query = "INSERT INTO `currencydenominations`\n" +
                             "(`Currency`, `Denomination`, `Active`, `DateCreated`)\n" +
                             "VALUES\n" +
                             "('" + cboCurrency.SelectedValue.ToString().ToSqlValidString(true) + "', " + txtValue.Value.ToSqlValidString() + ", " + (chkActive.Checked? "1" : "0").ToString() + ", NOW());\n" +
                             "SELECT LAST_INSERT_ID() AS `Id`;";

                    object[] _values = new object[_cols.Count];
                    _values[_cols["Currency"].Ordinal]     = cboCurrency.SelectedValue;
                    _values[_cols["Denomination"].Ordinal] = txtValue.Value;
                    _values[_cols["Active"].Ordinal]       = (chkActive.Checked ? 1 : 0);
                    _values[_cols["DateCreated"].Ordinal]  = DateTime.Now;
                    _values[_cols["LastModified"].Ordinal] = DateTime.Now;
                    _newrow = _denominations.Rows.Add(_values);
                }
                else
                {
                    _query = "UPDATE `currencydenominations` SET\n" +
                             "`Currency` = '" + cboCurrency.SelectedValue.ToString().ToSqlValidString() + "', `Denomination` = " + txtValue.Value.ToSqlValidString() + ", `Active` = " + (chkActive.Checked? "1" : "0").ToString() + "\n" +
                             "WHERE\n" +
                             "(`DetailId` = " + _id.ToString() + ");";

                    DataRow[] _existing = _denominations.Select("[DetailId] = " + _id.ToString());
                    if (_existing.Length > 0)
                    {
                        _existing[0]["Currency"]     = cboCurrency.SelectedValue;
                        _existing[0]["Denomination"] = txtValue.Value;
                        _existing[0]["Active"]       = (chkActive.Checked? 1 : 0);
                    }
                }

                if (!string.IsNullOrEmpty(_query.RLTrim()))
                {
                    btnSave.Enabled = false; btnSaveAndClose.Enabled = false;

                    IAsyncResult _result = Que.BeginExecution(SCMS.Connection, _query);

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

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

                        return;
                    }
                    else
                    {
                        QueResult _queresult = Que.EndExecution(_result);

                        if (string.IsNullOrEmpty(_queresult.Error.RLTrim()))
                        {
                            UserAction _action = UserAction.Add;
                            if (!_isnew)
                            {
                                _action = UserAction.Edit;
                            }

                            string _log = "Added a new currency denomination : " + txtValue.Value.ToSqlValidString() + " " + cboCurrency.SelectedValue.ToString() + ".";
                            if (!_isnew)
                            {
                                _log = "Updated currency denomination : " + txtValue.Value.ToSqlValidString() + " " + cboCurrency.SelectedValue.ToString() + ".";
                            }

                            if (_isnew)
                            {
                                if (_queresult.ResultSet.Tables.Count > 0)
                                {
                                    DataTable _table = _queresult.ResultSet.Tables[0];
                                    if (_table.Rows.Count > 0)
                                    {
                                        DataRow _row = _table.Rows[0];
                                        if (VisualBasic.IsNumeric(_row["Id"]))
                                        {
                                            _id = VisualBasic.CLng(_row["Id"]);
                                            if (_newrow != null)
                                            {
                                                _newrow["DetailId"] = _id;
                                            }
                                        }
                                    }
                                }
                            }

                            _denominations.AcceptChanges();

                            if (_isnew)
                            {
                                _isnew = false;
                            }
                            if (_updated)
                            {
                                _updated = false;
                            }
                            if (!_withupdates)
                            {
                                _withupdates = true;
                            }
                            Text   = Text.Replace(" *", "").Replace("*", "");
                            Cursor = Cursors.WaitCursor;

                            IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(_action, _log);
                            _logresult.WaitToFinish();

                            Cursor = Cursors.Default;

                            if (sender == btnSaveAndClose)
                            {
                                DialogResult = System.Windows.Forms.DialogResult.OK; Close();
                            }
                        }
                        else
                        {
                            if (_queresult.Error.Contains("duplicate"))
                            {
                                bool _invalid = Materia.Valid(_validator, txtValue, false, "Currency denomination already exists.");
                            }
                            else
                            {
                                SCMS.LogError(this.GetType().Name, new Exception(_queresult.Error));
                                MsgBoxEx.Alert("Failed to save the current currency denomination.", "Save Currency Denomination");
                            }

                            _denominations.RejectChanges();
                        }

                        _queresult.Dispose();
                    }

                    btnSave.Enabled = true; btnSaveAndClose.Enabled = true;
                }
            }
            else
            {
                if (sender == btnSaveAndClose)
                {
                    DialogResult = System.Windows.Forms.DialogResult.None; Close();
                }
            }
        }
예제 #24
0
        /// <summary>
        /// Retrieves the specified company's application settings and cofigurations.
        /// </summary>
        /// <param name="companycode"></param>
        public static void Refresh(string companycode)
        {
            ClearInformation(); _company = new CompanyInfo(companycode);
            Cache.SyncTable(SCMS.Connection, "settings");
            DataTable _settings = Cache.GetCachedTable("settings");

            if (_settings != null)
            {
                DataRow[] _rows = _settings.Select("[Company] LIKE '" + companycode.ToSqlValidString(true) + "'");

                if (_rows.Length <= 0)
                {
                    object[]             _values = new object[_settings.Columns.Count];
                    DataColumnCollection _cols   = _settings.Columns;

                    _values[_cols["Company"].Ordinal]     = companycode;
                    _values[_cols["Address"].Ordinal]     = "";
                    _values[_cols["Country"].Ordinal]     = "";
                    _values[_cols["Phone"].Ordinal]       = "";
                    _values[_cols["Mobile"].Ordinal]      = "";
                    _values[_cols["Fax"].Ordinal]         = "";
                    _values[_cols["Email"].Ordinal]       = "";
                    _values[_cols["CompanyLogo"].Ordinal] = Properties.Resources.CSPTColored.ToByteArray();
                    _values[_cols["ReportLogo"].Ordinal]  = Properties.Resources.CSPTBlackAndWhite.ToByteArray();

                    Cache.SyncTable(SCMS.Connection, "accounts");
                    DataTable _accounts = Cache.GetCachedTable("accounts");
                    if (_accounts != null)
                    {
                        long      _accountcode = 0; string _accountname = "Raw materials & consumables - spare parts";
                        DataRow[] _selrows = _accounts.Select("[AccountName] LIKE '" + _accountname.ToSqlValidString(true) + "'");
                        if (_selrows.Length > 0)
                        {
                            _accountcode = (long)_selrows[0]["AccountCode"];
                            _values[_cols["RawMaterialAccountCode"].Ordinal] = _accountcode;
                        }

                        _accountname = "Cash advances";
                        _selrows     = _accounts.Select("[AccountName] LIKE '" + _accountname.ToSqlValidString(true) + "'");
                        if (_selrows.Length > 0)
                        {
                            _accountcode = (long)_selrows[0]["AccountCode"];
                            _values[_cols["CashAdvanceAccountCode"].Ordinal] = _accountcode;
                        }

                        _accountname = "Parts consumption";
                        _selrows     = _accounts.Select("[AccountName] LIKE '" + _accountname.ToSqlValidString(true) + "'");
                        if (_selrows.Length > 0)
                        {
                            _accountcode = (long)_selrows[0]["AccountCode"];
                            _values[_cols["StockConsumptionAccountCode"].Ordinal] = _accountcode;
                        }

                        _accountname = "Stock adjustments";
                        _selrows     = _accounts.Select("[AccountName] LIKE '" + _accountname.ToSqlValidString(true) + "'");
                        if (_selrows.Length > 0)
                        {
                            _accountcode = (long)_selrows[0]["AccountCode"];
                            _values[_cols["StockAdjustmentAccountCode"].Ordinal] = _accountcode;
                        }

                        _accountname = "Unallocated payments / cheques";
                        _selrows     = _accounts.Select("[AccountName] LIKE '" + _accountname.ToSqlValidString(true) + "'");
                        if (_selrows.Length > 0)
                        {
                            _accountcode = (long)_selrows[0]["AccountCode"];
                            _values[_cols["UnallocatedPaymentAccountCode"].Ordinal] = _accountcode;
                        }

                        _accountname = "Result carried forward previous years";
                        _selrows     = _accounts.Select("[AccountName] LIKE '" + _accountname.ToSqlValidString(true) + "'");
                        if (_selrows.Length > 0)
                        {
                            _accountcode = (long)_selrows[0]["AccountCode"];
                            _values[_cols["RollForwardAccountCode"].Ordinal] = _accountcode;
                        }
                    }

                    _values[_cols["DateCreated"].Ordinal] = DateTime.Now;
                    _settings.Rows.Add(_values);

                    QueryGenerator _generator = new QueryGenerator(_settings);
                    _generator.ExcludedFields.Add("LastModified");
                    string _query = _generator.ToString();

                    if (!String.IsNullOrEmpty(_query.RLTrim()))
                    {
                        QueResult _result = Que.Execute(SCMS.Connection, _query);
                        if (String.IsNullOrEmpty(_result.Error.RLTrim()))
                        {
                            _settings.AcceptChanges();
                        }
                        _result.Dispose(); _result = null; Materia.RefreshAndManageCurrentProcess();
                    }
                }

                _rows = _settings.Select("[Company] LIKE '" + companycode.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (!Materia.IsNullOrNothing(_row["Address"]))
                    {
                        _address = _row["Address"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["CashAdvanceAccountCode"]))
                    {
                        _cashadvanceaccountcode = (long)_row["CashAdvanceAccountCode"];
                    }
                    if (!Materia.IsNullOrNothing(_row["CompanyLogo"]))
                    {
                        try { _companylogo = ((byte[])_row["CompanyLogo"]).ToImage(); }
                        catch { }
                    }
                    if (!Materia.IsNullOrNothing(_row["Country"]))
                    {
                        _country = _row["Country"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Email"]))
                    {
                        _email = _row["Email"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Fax"]))
                    {
                        _fax = _row["Fax"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Mobile"]))
                    {
                        _mobile = _row["Mobile"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Phone"]))
                    {
                        _phone = _row["Phone"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["RawMaterialAccountCode"]))
                    {
                        _rawmaterialaccountcode = (long)_row["RawMaterialAccountCode"];
                    }
                    if (!Materia.IsNullOrNothing(_row["ReportLogo"]))
                    {
                        try { _reportlogo = ((byte[])_row["ReportLogo"]).ToImage(); }
                        catch { }
                    }
                    if (VisualBasic.IsNumeric(_row["RollForwardAccountCode"]))
                    {
                        _rollforwardaccountcode = (long)_row["RollForwardAccountCode"];
                    }
                    if (VisualBasic.IsNumeric(_row["StockAdjustmentAccountCode"]))
                    {
                        _stockadjustmentaccountcode = (long)_row["StockAdjustmentAccountCode"];
                    }
                    if (VisualBasic.IsNumeric(_row["StockConsumptionAccountCode"]))
                    {
                        _stockconsumptionaccountcode = (long)_row["StockConsumptionAccountCode"];
                    }
                    if (VisualBasic.IsNumeric(_row["UnallocatedPaymentAccountCode"]))
                    {
                        _unallocatedpaymentaccountcode = (long)_row["UnallocatedPaymentAccountCode"];
                    }
                }
            }
        }
예제 #25
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (!btnImport.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           = "Import Database Script File";

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

            string _filename = _dialog.FileName;

            _dialog.Dispose(); _dialog = null;
            Materia.RefreshAndManageCurrentProcess();
            btnAdd.Enabled           = false; btnEdit.Enabled = false; btnDelete.Enabled = false;
            btnExecuteScript.Enabled = false; btnExport.Enabled = false; btnImport.Enabled = false;

            Func <string, bool, DataTable> _delegate = new Func <string, bool, DataTable>(SCMS.ImportData);
            IAsyncResult _result = _delegate.BeginInvoke(_filename, true, null, _delegate);

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

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

                return;
            }
            else
            {
                DataTable _table = _delegate.EndInvoke(_result);
                if (_table != null)
                {
                    if (_table.TableName != "scripts")
                    {
                        MsgBoxEx.Shout("The specified file does not contain any relevant database script information.", "Import Database Script");
                    }
                    else
                    {
                        if (_table.Rows.Count > 0)
                        {
                            DataRow   _row     = _table.Rows[0];
                            DataTable _scripts = Cache.GetCachedTable("scripts");
                            if (_scripts != null)
                            {
                                DataRow[] _rows = _scripts.Select("[ReferenceNo] LIKE '" + _row["ReferenceNo"].ToString().ToSqlValidString(true) + "'");
                                if (_rows.Length <= 0)
                                {
                                    DataColumnCollection _cols   = _scripts.Columns;
                                    object[]             _values = new object[_cols.Count];

                                    for (int i = 0; i <= (_cols.Count - 1); i++)
                                    {
                                        if (_table.Columns.Contains(_cols[i].ColumnName))
                                        {
                                            _values[i] = _row[_cols[i].ColumnName];
                                        }
                                    }

                                    _scripts.Rows.Add(_values);
                                    QueryGenerator _generator = new QueryGenerator(_scripts);
                                    string         _query     = _generator.ToString();
                                    _generator = null; Materia.RefreshAndManageCurrentProcess();

                                    if (!string.IsNullOrEmpty(_query.RLTrim()))
                                    {
                                        IAsyncResult _execresult = Que.BeginExecution(SCMS.Connection, _query);

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

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

                                                return;
                                            }
                                        }
                                        else
                                        {
                                            QueResult _queresult = Que.EndExecution(_execresult);

                                            if (string.IsNullOrEmpty(_queresult.Error.RLTrim()))
                                            {
                                                Cursor = Cursors.WaitCursor;
                                                IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(UserAction.ImportEdi, "Imported database script from : " + _filename + ".", _row["ReferenceNo"].ToString());
                                                _logresult.WaitToFinish(); Cursor = Cursors.Default;

                                                _scripts.AcceptChanges(); InitializeScripts();
                                            }
                                            else
                                            {
                                                SCMS.LogError(this.GetType().Name, new Exception(_queresult.Error));
                                                MsgBoxEx.Alert("Failed to import the specified database script file.", "Import Database Script");
                                            }

                                            _queresult.Dispose();
                                        }
                                    }
                                }
                                else
                                {
                                    MsgBoxEx.Shout("Database script : <font color=\"blue\">" + _row["ReferenceNo"].ToString() + "</font> already exists.", "Import Database Script");
                                }
                            }
                            else
                            {
                                MsgBoxEx.Shout("Cannot import database script information.", "Import Database Script");
                            }
                        }
                        else
                        {
                            MsgBoxEx.Shout("The specified file does not contain any relevant database script information.", "Import Database Script");
                        }
                    }
                    _table.Dispose(); _table = null;
                    Materia.RefreshAndManageCurrentProcess();
                }
                else
                {
                    MsgBoxEx.Alert("Failed to import the specified database script file.", "Import Database Script");
                }
            }

            EnableButtons(); DisplayInfo();
        }
예제 #26
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (!btnExport.Enabled)
            {
                return;
            }

            if (_updated)
            {
                if (MsgBoxEx.Shout("Changes in the current database script will be saved<br />first? Continue with the exportation?", "Export Database Script", MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button1) != System.Windows.Forms.DialogResult.Yes)
                {
                    return;
                }
                btnSave_Click(btnSave, new EventArgs());
                if (_updated)
                {
                    return;
                }
            }

            SaveFileDialog _dialog = new SaveFileDialog();

            _dialog.DefaultExt = SCMS.ScriptFileExtension;
            _dialog.Filter     = "SCMS database script file (*." + SCMS.ScriptFileExtension + ")|*." + SCMS.ScriptFileExtension;
            _dialog.Title      = "Export Database Script";
            _dialog.FileName   = _referenceno + "." + SCMS.ScriptFileExtension;
            if (_dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                _dialog.Dispose(); _dialog = null;
                Materia.RefreshAndManageCurrentProcess(); return;
            }

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

            if (_scripts != null)
            {
                var _query = from _scr in _scripts.AsEnumerable()
                             where _scr.Field <string>("ReferenceNo") == _referenceno
                             select _scr;

                DataTable _script = _query.CopyToDataTable();
                _script.TableName = "scripts";
                FileInfo _exportedfile = _script.ExportData(_dialog.FileName, true);
                if (_exportedfile != null)
                {
                    Cursor = Cursors.WaitCursor;
                    IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(UserAction.ExportEdi, "Exported database script into : " + _dialog.FileName + ".", _referenceno);
                    _logresult.WaitToFinish(); Cursor = Cursors.Default;
                    Process.Start("explorer.exe", "/select, \"" + _exportedfile.FullName + "\"");
                }
                else
                {
                    MsgBoxEx.Alert("Failed to export the current database script into the specified path.", "Export Database Script");
                }
                _script.Dispose(); _script = null; _exportedfile = null;
                Materia.RefreshAndManageCurrentProcess();
            }
            else
            {
                MsgBoxEx.Alert("Failed to export the current database script into the specified path.", "Export Database Script");
            }

            _dialog.Dispose(); _dialog = null;
            Materia.RefreshAndManageCurrentProcess();
        }
예제 #27
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();
                    }
                }
            }
        }
예제 #28
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();
            }
        }
예제 #29
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (!btnExport.Enabled)
            {
                return;
            }
            if (!grdScripts.Redraw)
            {
                return;
            }
            if (grdScripts.DataSource == null)
            {
                return;
            }
            if (grdScripts.RowSel < (grdScripts.Rows.Fixed))
            {
                return;
            }

            string _referenceno = grdScripts[grdScripts.RowSel, "ReferenceNo"].ToString();

            SaveFileDialog _dialog = new SaveFileDialog();

            _dialog.DefaultExt = SCMS.ScriptFileExtension;
            _dialog.Filter     = "SCMS database script file (*." + SCMS.ScriptFileExtension + ")|*." + SCMS.ScriptFileExtension;
            _dialog.Title      = "Export Database Script";
            _dialog.FileName   = _referenceno + "." + SCMS.ScriptFileExtension;
            if (_dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                _dialog.Dispose(); _dialog = null;
                Materia.RefreshAndManageCurrentProcess(); return;
            }

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

            if (_scripts != null)
            {
                var _query = from _scr in _scripts.AsEnumerable()
                             where _scr.Field <string>("ReferenceNo") == _referenceno
                             select _scr;

                DataTable _script = _query.CopyToDataTable();
                _script.TableName = "scripts";
                FileInfo _exportedfile = _script.ExportData(_dialog.FileName, true);
                if (_exportedfile != null)
                {
                    Cursor = Cursors.WaitCursor;
                    IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(UserAction.ExportEdi, "Exported database script into : " + _dialog.FileName + ".", _referenceno);
                    _logresult.WaitToFinish(); Cursor = Cursors.Default;
                    Process.Start("explorer.exe", "/select, \"" + _exportedfile.FullName + "\"");
                }
                else
                {
                    MsgBoxEx.Alert("Failed to export the current database script into the specified path.", "Export Database Script");
                }
                _script.Dispose(); _script = null; _exportedfile = null;
                Materia.RefreshAndManageCurrentProcess();
            }
            else
            {
                MsgBoxEx.Alert("Failed to export the current database script into the specified path.", "Export Database Script");
            }

            _dialog.Dispose(); _dialog = null;
            Materia.RefreshAndManageCurrentProcess();
        }
예제 #30
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);
        }