예제 #1
0
        private void buttoncreate_Click(object sender, EventArgs e)
        {
            if (fGrid.CurCell != null)
            {
                fGrid.CommitEditCurCell();
            }
            if (!CanSave())
            {
                return;
            }
            ic.foreign_exchange_convC _c = new ic.foreign_exchange_convC();
            _c.curr_sys_exch_rate = fGrid.Rows["curr_exch_rate"].Cells[1].Value.ToFloat();
            _c.curr_sys_amount    = fGrid.Rows["curr_amount"].Cells[1].AuxValue.ToInt32();
            _c.sys_account_id     = (fGrid.Rows["currency"].Cells[1].AuxValue as fnn.iGComboItemEX).Tag.ToInt32();
            _c.currency_id        = datam.DATA_FOREIGN_CURRENCY.Values.Where(d => d.sys_account_id == _c.sys_account_id).FirstOrDefault().fr_currency_id;
            _c.fs_date            = System.Convert.ToDateTime(fGrid.Rows["date"].Cells[1].Value);
            _c.fs_id            = fn.GetFSID(_c.fs_date);
            _c.used_exch_rate   = fGrid.Rows["exch_rate"].Cells[1].Value.ToFloat();
            _c.exchanged_amount = fGrid.Rows["exch_amount"].Cells[1].Value.ToInt32();
            _c.m_partition_id   = string.Format("{0}{1}", _c.fs_date.Year, _c.fs_date.Month).ToInt32();
            _c.pc_us_id         = sdata.PC_US_ID;
            _c.status           = em.foreign_exch_statusS.valid;
            //
            string _str = "Are You Sure You Want To Save This Record ??";

            if (!dbm.WarningMessage(_str, "Save Warning"))
            {
                return;
            }
            using (var xd = new xing())
            {
                var _ts_id = accn.AccountsTransaction(xd, string.Format("Foreign Exchange for {0}", datam.DATA_FOREIGN_CURRENCY[_c.currency_id].fr_currency_name), _c.fs_date);
                _c.un_id = xd.SingleInsertCommandTSPInt("acc_foreign_exchange_tb", new string[]
                {
                    "fs_date",
                    "fs_id",
                    "currency_id",
                    "sys_account_id",
                    "curr_sys_exch_rate",
                    "curr_sys_amount",
                    "used_exch_rate",
                    "exchanged_amount",
                    "status",
                    "m_partition_id",
                    "pc_us_id",
                    "fs_time_stamp",
                    "lch_id",
                    "transaction_id",
                    "edate"
                }, new object[]
                {
                    _c.fs_date,
                    _c.fs_id,
                    _c.currency_id,
                    _c.sys_account_id,
                    _c.curr_sys_exch_rate,
                    _c.curr_sys_amount,
                    _c.used_exch_rate,
                    _c.exchanged_amount,
                    _c.status.ToByte(),
                    _c.m_partition_id,
                    _c.pc_us_id,
                    0,
                    datam.LCH_ID,
                    _ts_id,
                    sdata.CURR_DATE
                });

                //
                int _val = _c.exch_loss == 0 ? (_c.exchanged_amount * _c.curr_sys_exch_rate).ToInt32() : _c.converted_ug_amount;
                accn.JournalBook(xd, _c.fs_date, em.j_sectionS.unbanked, _ts_id, accn.GetAccountByAlias("UNBANKED_CASH").account_id, _val, 0);
                accn.JournalBook(xd, _c.fs_date, em.j_sectionS.unbanked, _ts_id, _c.sys_account_id, 0, _val);
                //
                if (_c.exch_loss > 0)
                {
                    accn.JournalBook(xd, _c.fs_date, em.j_sectionS.unbanked, _ts_id, _c.sys_account_id, 0, _c.exch_loss);
                    accn.JournalBook(xd, _c.fs_date, em.j_sectionS.loss, _ts_id, accn.GetAccountByAlias("FOREIGN_EXCHANGE_LOSS").account_id, _c.exch_loss, 0);
                }
                if (_c.exch_gain > 0)
                {
                    accn.JournalBook(xd, _c.fs_date, em.j_sectionS.unbanked, _ts_id, accn.GetAccountByAlias("UNBANKED_CASH").account_id, _c.exch_gain, 0);
                    accn.JournalBook(xd, _c.fs_date, em.j_sectionS.income, _ts_id, accn.GetAccountByAlias("FOREIGN_EXCHANGE_GAIN").account_id, 0, _c.exch_gain);
                }
                accn.ForeignCurrencyMVT(xd, datam.DATA_FOREIGN_CURRENCY[_c.currency_id], 0, _c.exchanged_amount, _c.fs_date);
                //
                xd.SingleUpdateCommandALL("acc_foreign_currency_tb",
                                          new string[]
                {
                    "last_exchange_date",
                    "last_exchange_id",
                    "fr_currency_id",
                    "lch_id"
                }, new object[]
                {
                    _c.fs_date,
                    _c.un_id,
                    _c.currency_id,
                    datam.LCH_ID
                }, 2);
                //
                xd.CommitTransaction();
            }
            m_process = _process.after_insert;
            backworker.RunWorkerAsync();
            ClearGrid();
        }
        public static bool GetMonthForeignExchange(int m_partition_id)
        {
            if (DATA_MONTH_FOREIGN_EXCHANGE == null)
            {
                DATA_MONTH_FOREIGN_EXCHANGE = new SortedList <int, SortedList <int, ic.foreign_exchange_convC> >();
            }
            if (DATA_MONTH_FOREIGN_EXCHANGE.Keys.IndexOf(m_partition_id) == -1)
            {
                DATA_MONTH_FOREIGN_EXCHANGE.Add(m_partition_id, new SortedList <int, ic.foreign_exchange_convC>());
            }
            if (wdata.DATA_MONTH_STAMP == null)
            {
                wdata.DATA_MONTH_STAMP = new SortedList <string, SortedList <int, long> >();
            }

            string _table_name = "acc_foreign_exchange_tb";

            if (wdata.DATA_MONTH_STAMP.IndexOfKey(_table_name) == -1)
            {
                wdata.DATA_MONTH_STAMP.Add(_table_name, new SortedList <int, long>());
                wdata.DATA_MONTH_STAMP[_table_name].Add(m_partition_id, 0);
            }
            string _str       = null;
            bool   load_all   = false;
            bool   is_new     = false;
            bool   is_updated = false;
            long   _stamp     = 0;

            using (var xd = new xing())
            {
                _stamp = xd.GetTimeStamp(_table_name);
                datam.FillForeignCurrency(xd);
                if (datam.DATA_MONTH_FOREIGN_EXCHANGE[m_partition_id].Keys.Count == 0)
                {
                    _str     = string.Format("select * from " + _table_name + " where m_partition_id={0} and status={1}", m_partition_id, em.foreign_exch_statusS.valid.ToByte());
                    load_all = true;
                    is_new   = true;
                }
                else
                {
                    if (_stamp == wdata.DATA_MONTH_STAMP[_table_name][m_partition_id])
                    {
                        xd.RollBackTransaction();
                        return(false);
                    }
                    _str = string.Format("select * from " + _table_name + " where m_partition_id={0} and fs_time_stamp > {1}", m_partition_id, wdata.DATA_MONTH_STAMP[_table_name][m_partition_id]);
                }
                wdata.DATA_MONTH_STAMP[_table_name][m_partition_id] = _stamp;
                using (var _dr = xd.SelectCommand(_str))
                {
                    if (_dr == null)
                    {
                        return(false);
                    }
                    ic.foreign_exchange_convC _obj = null;
                    while (_dr.Read())
                    {
                        if (!is_updated)
                        {
                            is_updated = true;
                        }
                        _obj = null;
                        if (load_all)
                        {
                            _obj = new ic.foreign_exchange_convC();
                        }
                        else
                        {
                            try
                            {
                                _obj   = DATA_MONTH_FOREIGN_EXCHANGE[m_partition_id][_dr["un_id"].ToInt32()];
                                is_new = false;
                            }
                            catch (Exception)
                            {
                                if (_obj == null)
                                {
                                    _obj   = new ic.foreign_exchange_convC();
                                    is_new = true;
                                }
                            }
                        }
                        //
                        if (is_new)
                        {
                            _obj.un_id              = _dr["un_id"].ToInt32();
                            _obj.used_exch_rate     = _dr.GetFloat("used_exch_rate");
                            _obj.exchanged_amount   = _dr["exchanged_amount"].ToInt32();
                            _obj.curr_sys_amount    = _dr["curr_sys_amount"].ToInt32();
                            _obj.curr_sys_exch_rate = _dr.GetFloat("curr_sys_exch_rate");
                            _obj.m_partition_id     = _dr["m_partition_id"].ToInt32();
                            _obj.sys_account_id     = _dr["sys_account_id"].ToInt32();
                            _obj.currency_id        = _dr["currency_id"].ToInt32();
                            _obj.fs_id              = _dr["fs_id"].ToInt32();
                            _obj.fs_date            = _dr.GetDateTime("fs_date");
                            //
                        }
                        _obj.status     = (em.foreign_exch_statusS)_dr["status"].ToInt16();
                        _obj.is_updated = true;
                        if (_dr["del_fs_date"] != null)
                        {
                            if (_obj.objDelInfo == null)
                            {
                                _obj.objDelInfo = new ic.deleteBaseC();
                            }
                            _obj.objDelInfo.del_fs_date  = _dr.GetDateTime("del_fs_date");
                            _obj.objDelInfo.del_fs_id    = fn.GetFSID(_obj.objDelInfo.del_fs_date.Value);
                            _obj.objDelInfo.del_fs_time  = _dr["del_fs_time"].ToStringNullable();
                            _obj.objDelInfo.del_pc_us_id = _dr["del_pc_us_id"].ToInt32();
                        }
                        if (is_new)
                        {
                            DATA_MONTH_FOREIGN_EXCHANGE[m_partition_id].Add(_obj.un_id, _obj);
                        }
                    }
                }

                xd.CommitTransaction();
            }
            return(is_updated);
        }