コード例 #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 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"]);
                    }
                }
            }
        }
コード例 #3
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"]);
                    }
                }
            }
        }
コード例 #4
0
        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"];
                    }
                }
            }
        }
コード例 #5
0
        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"]);
                    }
                }
            }
        }
コード例 #6
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;
            }
        }
コード例 #7
0
        /// <summary>
        /// Creates a new instance of DatabaseScriptInfo.
        /// </summary>
        /// <param name="table"></param>
        public DatabaseScriptInfo(DataTable table)
        {
            ClearInfo();

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

                if (table.Rows.Count > 0)
                {
                    DataRow _row = table.Rows[0];
                    if (!Materia.IsNullOrNothing(_row["Author"]))
                    {
                        _author = _row["Author"].ToString();
                    }
                    if (VisualBasic.IsDate(_row["DateCreated"]))
                    {
                        _datecreated = VisualBasic.CDate(_row["DateCreated"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Description"]))
                    {
                        _description = _row["Description"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["ReferenceNo"]))
                    {
                        _referenceno = _row["ReferenceNo"].ToString();
                    }
                    if (VisualBasic.IsNumeric(_row["RequireAppRestart"]))
                    {
                        _requiresapprestartafterexecution = VisualBasic.CBool(_row["RequireAppRestart"]);
                    }
                    if (VisualBasic.IsNumeric(_row["RequireBackup"]))
                    {
                        _requiresbackupbeforeexecution = VisualBasic.CBool(_row["RequireBackup"]);
                    }
                    if (VisualBasic.IsNumeric(_row["RequirePcRestart"]))
                    {
                        _requirespcrestartafterexecution = VisualBasic.CBool(_row["RequirePcRestart"]);
                    }
                    if (!Materia.IsNullOrNothing(_row["Script"]))
                    {
                        _sqlstatement = _row["Script"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["SystemVersion"]))
                    {
                        _systemversion = _row["SystemVersion"].ToString();
                    }
                    if (!Materia.IsNullOrNothing(_row["Title"]))
                    {
                        _title = _row["Title"].ToString();
                    }
                }
            }
        }
コード例 #8
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;
            }
        }
コード例 #9
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();
                    }
                }
            }
        }
コード例 #10
0
        private void trvwModules_AfterNodeSelect(object sender, DevComponents.AdvTree.AdvTreeNodeEventArgs e)
        {
            if (_nodesloading)
            {
                return;
            }
            if (e.Node == null)
            {
                return;
            }
            _selectedsubmodule = SubModule.None;

            if (e.Node.Nodes.Count > 0)
            {
                DisableButtons(); grdRecords.Hide();
                if (lstvwRecords.Redraw)
                {
                    lstvwRecords.BeginUpdate();
                }
                lstvwRecords.ImageList = _images32; lstvwRecords.Show();
                lstvwRecords.ListItems.Clear();

                for (int i = 0; i <= (e.Node.Nodes.Count - 1); i++)
                {
                    ListViewGridItem _item = new ListViewGridItem(e.Node.Nodes[i].Name, e.Node.Nodes[i].Text.Replace(" ", "\n"), e.Node.Nodes[i].Name);
                    _item.Tag = e.Node.Nodes[i].Tag;
                    lstvwRecords.ListItems.Add(_item);
                }

                while (!lstvwRecords.Redraw)
                {
                    lstvwRecords.EndUpdate();
                }
            }
            else
            {
                if (VisualBasic.IsNumeric(e.Node.Tag))
                {
                    if (VisualBasic.CInt(e.Node.Tag) > 0)
                    {
                        try { _selectedsubmodule = (SubModule)e.Node.Tag; }
                        catch { _selectedsubmodule = SubModule.None; }

                        grdRecords.Show(); lstvwRecords.Hide();
                        InitializeDataSource();
                    }
                }
            }
        }
コード例 #11
0
        private void cboGroup_SelectedValueChanged(object sender, EventArgs e)
        {
            if (!_isshown)
            {
                return;
            }
            if (!cboGroup.Enabled)
            {
                return;
            }
            if (cboGroup.DataSource == null)
            {
                return;
            }
            if (cboGroup.SelectedIndex < 0)
            {
                return;
            }
            if (cboAccount.SelectedIndex >= 0)
            {
                return;
            }
            if (cboAccount.DataSource == null)
            {
                return;
            }
            if (!VisualBasic.IsNumeric(cboGroup.SelectedValue))
            {
                return;
            }

            DataTable _datasource = null;

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

            if (_datasource != null)
            {
                DataRow[] _rows = _datasource.Select("[Id] = " + cboGroup.SelectedValue.ToString());
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    try { cboAccount.SelectedValue = _row["DefaultAccount"]; }
                    catch { }
                }
            }
        }
コード例 #12
0
ファイル: MainWindow.cs プロジェクト: AsimKhan2019/SCM-System
        /// <summary>
        /// Renders the main window to select the specified module.
        /// </summary>
        /// <param name="module"></param>
        public void SelectModule(Module module)
        {
            if (module == Module.None)
            {
                return;
            }

            switch (module)
            {
            case Module.Bank:
            case Module.CashPosition:
            case Module.Customers:
            case Module.GeneralLedger:
            case Module.JournalEntries:
            case Module.Suppliers:
                if (_selectedmodulegroup != ModuleGroup.Finance)
                {
                    InitializeModules(ModuleGroup.Finance);
                }
                break;

            default:
                if (_selectedmodulegroup != ModuleGroup.Operations)
                {
                    InitializeModules(ModuleGroup.Operations);
                }
                break;
            }

            foreach (BaseItem _button in brModules.Items)
            {
                if (_button is ButtonItem)
                {
                    if (VisualBasic.IsNumeric(_button.Tag))
                    {
                        if (!(_button.Tag is ModuleGroup))
                        {
                            if (((Module)_button.Tag) == module)
                            {
                                _button_Click(_button, new EventArgs()); break;
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!btnSave.Enabled)
            {
                return;
            }

            Validator _validator = SCMS.Validators[this];

            if (!Materia.Valid(_validator, cboUsername, cboUsername.SelectedIndex >= 0, "Please specify signatory from the existing accounts."))
            {
                return;
            }
            if (!Materia.Valid(_validator, cboRole, cboRole.SelectedIndex >= 0, "Please specify signatory role."))
            {
                return;
            }

            DataTable _signatories = Cache.GetCachedTable("signatories");

            if (_signatories != null)
            {
                DataRow[] _rows = _signatories.Select("([Username] LIKE '" + cboUsername.SelectedValue.ToString().ToSqlValidString(true) + "' AND\n" +
                                                      " [RoleId] = " + cboRole.SelectedValue.ToString() + " AND\n" +
                                                      " [Company] LIKE '" + SCMS.CurrentCompany.Company.ToSqlValidString(true) + "') AND\n" +
                                                      "([DetailId] <> " + _id.ToString() + ")");

                if (!Materia.Valid(_validator, cboUsername, _rows.Length <= 0, "Signatory under the specified role already exists."))
                {
                    return;
                }

                string _query = "";
                DataColumnCollection _cols = _signatories.Columns;
                DataRow _newrow            = null;

                if (_isnew)
                {
                    _query = "INSERT INTO `signatories`\n" +
                             "(`Username`, `RoleId`, `CashLimit`, `BankLimit`, `Company`)\n" +
                             "VALUES\n" +
                             "('" + cboUsername.SelectedValue.ToString().ToSqlValidString() + "', " + cboRole.SelectedValue.ToString() + ", " + (txtCashLimit.LockUpdateChecked? txtCashLimit.Value.ToSqlValidString() : "0") + ", " + (txtBankLimit.LockUpdateChecked? txtBankLimit.Value.ToSqlValidString() : "0") + ", '" + SCMS.CurrentCompany.Company.ToSqlValidString() + "');\n" +
                             "SELECT LAST_INSERT_ID() AS `Id`;";

                    object[] _values = new object[_cols.Count];
                    _values[_cols["Username"].Ordinal]     = cboUsername.SelectedValue;
                    _values[_cols["RoleId"].Ordinal]       = cboRole.SelectedValue;
                    _values[_cols["CashLimit"].Ordinal]    = (txtCashLimit.LockUpdateChecked ? txtCashLimit.Value : 0);
                    _values[_cols["BankLimit"].Ordinal]    = (txtCashLimit.LockUpdateChecked ? txtCashLimit.Value : 0);
                    _values[_cols["LastModified"].Ordinal] = DateTime.Now;
                    _newrow = _signatories.Rows.Add(_values);
                }
                else
                {
                    _query = "UPDATE `signatories` SET\n" +
                             "`Username` = '" + cboUsername.SelectedValue.ToString() + "', `RoleId` = " + cboRole.SelectedValue.ToString() + ", `CashLimit` = " + (txtCashLimit.LockUpdateChecked? txtCashLimit.Value.ToSqlValidString() : "0") + ", `BankLimit` = " + (txtBankLimit.LockUpdateChecked ? txtBankLimit.Value.ToSqlValidString() : "0") + "\n" +
                             "WHERE\n" +
                             "(`DetailId` = " + _id.ToString() + ");";

                    DataRow[] _existing = _signatories.Select("[DetailId] = " + _id.ToString());
                    if (_existing.Length > 0)
                    {
                        _existing[0]["Username"]  = cboUsername.SelectedValue;
                        _existing[0]["RoleId"]    = cboRole.SelectedValue;
                        _existing[0]["CashLimit"] = (txtCashLimit.LockUpdateChecked ? txtCashLimit.Value : 0);
                        _existing[0]["BankLimit"] = (txtBankLimit.LockUpdateChecked ? txtBankLimit.Value : 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 signatory : " + txtFullName.Text + " as " + cboRole.Text.ToLower() + ".";
                            if (!_isnew)
                            {
                                _log = "Updated signatory : " + txtFullName.Text + " as " + cboRole.Text.ToLower() + ".";
                            }

                            if (_queresult.ResultSet != null)
                            {
                                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"]))
                                        {
                                            if (_newrow != null)
                                            {
                                                _id = VisualBasic.CLng(_row["Id"]);
                                                _newrow["DetailId"] = _row["Id"];
                                            }
                                        }
                                    }
                                }
                            }

                            _signatories.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, cboUsername, false, "Signatory with the specified role already exists.");
                            }
                            else
                            {
                                SCMS.LogError(this.GetType().Name, new Exception(_queresult.Error));
                                MsgBoxEx.Alert("Failed to save the current signatory.", "Save Signatory");
                            }

                            _signatories.RejectChanges();
                        }

                        _queresult.Dispose();
                    }

                    btnSave.Enabled = true; btnSaveAndClose.Enabled = true;
                }
            }
            else
            {
                if (sender == btnSaveAndClose)
                {
                    DialogResult = System.Windows.Forms.DialogResult.None; Close();
                }
            }
        }
コード例 #14
0
        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();
                }
            }
        }
コード例 #15
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();
                    }
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Applies table updates from the specified DataTable object into the current DataObjectMap's table.
        /// </summary>
        /// <param name="table"></param>
        public void ApplyUpdatesFromTable(DataTable table)
        {
            if (_table != null &&
                table != null)
            {
                DataTable _updates = table.GetChanges();
                if (_updates != null)
                {
                    foreach (DataRow _row in _updates.Rows)
                    {
                        string _pk = "";

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

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

                        object _pkvalue = null;

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

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

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

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

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

                            default: break;
                            }
                        }
                    }
                }
            }
        }
コード例 #17
0
        private string Generate()
        {
            StringBuilder _sql = new StringBuilder();

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

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

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

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

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

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

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

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

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

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

                        string _query = "";

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

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

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

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

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

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

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

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

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

                                    _values[_column.Ordinal] = _value;
                                }

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

                                case DataRowState.Modified:
                                    _query = _update; break;

                                case DataRowState.Deleted:
                                    _query = _delete; break;

                                case DataRowState.Detached:
                                default: break;
                                }

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

            return(_sql.ToString());
        }
コード例 #18
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"];
                    }
                }
            }
        }
コード例 #19
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (!btnDelete.Enabled)
            {
                return;
            }
            if (!grdStockAdjustments.Redraw)
            {
                return;
            }
            if (grdStockAdjustments.DataSource == null)
            {
                return;
            }
            if (grdStockAdjustments.RowSel < grdStockAdjustments.Rows.Fixed)
            {
                return;
            }
            if (Materia.IsNullOrNothing(grdStockAdjustments[grdStockAdjustments.RowSel, "ReferenceNo"]))
            {
                return;
            }

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

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

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

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

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

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

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

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

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

                            DataTable _datasource = null;

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

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

                            FormatGrid(); ResizeGrid();

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

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

                        _result.Dispose(); EnableButtons(); DisplayInfo();
                    }
                }
            }
        }
コード例 #20
0
ファイル: MainWindow.cs プロジェクト: AsimKhan2019/SCM-System
        private void _button_Click(object sender, EventArgs e)
        {
            if (sender != null)
            {
                if (sender.GetType() == typeof(ButtonItem))
                {
                    ButtonItem _button = (ButtonItem)sender;
                    if (!_button.Enabled)
                    {
                        return;
                    }

                    foreach (BaseItem _control in brModules.Items)
                    {
                        if (_control.GetType() == typeof(ButtonItem))
                        {
                            ((ButtonItem)_control).Checked = false;
                        }
                    }

                    _button.Checked = true;

                    if (_button.Tag != null)
                    {
                        if (_button.Tag.GetType() == typeof(ModuleGroup))
                        {
                            ModuleGroup _tag = (ModuleGroup)_button.Tag;
                            switch (_tag)
                            {
                            case ModuleGroup.Finance:
                                InitializeModules(ModuleGroup.Finance); break;

                            case ModuleGroup.Operations:
                                InitializeModules(ModuleGroup.Operations); break;

                            default: break;
                            }

                            _selectedmodulegroup = _tag;
                        }
                        else
                        {
                            if (VisualBasic.IsNumeric(_button.Tag))
                            {
                                ModuleWindow _modulewindow = null;
                                _selectedmodule = (Module)_button.Tag;

                                foreach (Form _form in MdiChildren)
                                {
                                    if (_form is ModuleWindow)
                                    {
                                        ModuleWindow _current = (ModuleWindow)_form;
                                        if (_current.SelectedModule == (Module)_button.Tag)
                                        {
                                            _modulewindow = _current; break;
                                        }
                                    }
                                }

                                if (_modulewindow == null)
                                {
                                    _modulewindow = new ModuleWindow((Module)_button.Tag);
                                }

                                _modulewindow.MdiParent   = this; _modulewindow.WindowState = FormWindowState.Maximized;
                                _modulewindow.MinimizeBox = false; _modulewindow.MaximizeBox = false;
                                _modulewindow.ControlBox  = false; _modulewindow.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                                _modulewindow.Dock        = DockStyle.Fill; _modulewindow.TopMost = true;
                                _modulewindow.Show();  _modulewindow.Activate();
                                _modulewindow.Size        = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
                                _modulewindow.WindowState = FormWindowState.Normal;
                                _modulewindow.WindowState = FormWindowState.Maximized;
                            }
                        }
                    }
                }
            }
        }
コード例 #21
0
        private void GetInfo(string code)
        {
            ClearInfo();
            DataTable _parts     = Cache.GetCachedTable("parts");
            DataTable _partnames = Cache.GetCachedTable("partnames");
            DataTable _models    = Cache.GetCachedTable("models");

            if (_parts != null &&
                _partnames != null)
            {
                var _query = from _part in _parts.AsEnumerable()
                             join _names in _partnames.AsEnumerable() on _part.Field <string>("PartName") equals _names.Field <string>("PartName")
                             join _mdl in _models.AsEnumerable() on _part.Field <string>("ModelCode") equals _mdl.Field <string>("ModelCode") into _m
                                 where _part.Field <string>("PartCode") == _partcode
                             from _mdl in _m.DefaultIfEmpty(_models.NewRow())
                             select new
                {
                    PartNo      = _part.Field <string>("PartNo"),
                    PartName    = _part.Field <string>("PartName"),
                    Description = _part.Field <string>("Description"),
                    Brand       = _part.Field <string>("Brand"),
                    Model       = _mdl.Field <string>("Model"),
                    Category    = _names.Field <string>("PartCategory"),
                    Unit        = _part.Field <string>("Unit"),
                    Status      = _part.Field <Int16>("Active"),
                    Type        = _part.Field <int>("StockType")
                };

                try
                {
                    foreach (var _row in _query)
                    {
                        if (!Materia.IsNullOrNothing(_row.PartNo))
                        {
                            _partno = _row.PartNo;
                        }
                        if (!Materia.IsNullOrNothing(_row.PartName))
                        {
                            _partname = _row.PartName;
                        }
                        if (!Materia.IsNullOrNothing(_row.Description))
                        {
                            _description = _row.Description;
                        }
                        if (!Materia.IsNullOrNothing(_row.Category))
                        {
                            _category = _row.Category;
                        }
                        if (!Materia.IsNullOrNothing(_row.Brand))
                        {
                            _brand = _row.Brand;
                        }
                        if (!Materia.IsNullOrNothing(_row.Model))
                        {
                            _model = _row.Model;
                        }
                        if (!Materia.IsNullOrNothing(_row.Unit))
                        {
                            _unit = _row.Unit;
                        }
                        if (VisualBasic.IsNumeric(_row.Status))
                        {
                            _status = (PartStatus)_row.Status;
                        }
                        if (VisualBasic.IsNumeric(_row.Type))
                        {
                            _type = (PartStockingType)_row.Type;
                        }
                    }
                }
                catch { }
            }
        }