Esempio n. 1
0
        void iGridCategory_AfterCommitEdit(object sender, iGAfterCommitEditEventArgs e)
        {
            iGrid _grid = sender as iGrid;

            if (_grid.Rows[e.RowIndex].Cells[0].Value != null)
            {
                _grid.Rows[e.RowIndex].Cells[0].Value = _grid.Rows[e.RowIndex].Cells[0].Value.ToProperCase();
            }
            if (sender == iGridCategory)
            {
                #region Item Category
                if (_grid.Rows[e.RowIndex].Cells[0].Value == null)
                {
                    if (_grid.Rows[e.RowIndex].Tag != null)
                    {
                        var _category = _grid.Rows[e.RowIndex].Tag as ic.expense_catC;
                        using (var xd = new xing())
                        {
                            if (xd.ExecuteScalarInt("select TOP 1 exp_acc_id from acc_expense_accounts_tb where exp_cat_id=" + _category.exp_cat_id) == 0)
                            {
                                xd.SingleDeleteCommandExp("acc_expense_cat_tb", new string[] { "exp_cat_id" }, new int[] { _category.exp_cat_id }); xd.CommitTransaction();
                            }
                            else
                            {
                                _grid.Rows[e.RowIndex].Cells[0].Value = _category.exp_cat_name;
                                dbm.ErrorMessage("There Are Some Expense Accounts Which Are Attached To This Category", "Delete Operation Will Be Cancelled");
                                return;
                            }
                        }
                        var _dp_item = (from r in (fGrid.Rows["item_cat"].Cells["desc"].DropDownControl as iGDropDownList).Items.Cast <fnn.iGComboItemEX>()
                                        where r.Tag == _category
                                        select r).FirstOrDefault();
                        if (_dp_item != null)
                        {
                            (fGrid.Rows["item_cat"].Cells["desc"].DropDownControl as iGDropDownList).Items.Remove(_dp_item);
                            fGrid.Rows["item_cat"].Cells["desc"].AuxValue = null;
                            fGrid.Rows["item_cat"].Cells["desc"].Value    = null;
                        }
                        _grid.Rows[e.RowIndex].Tag = null;
                        datam.DATA_EXPENSE_CATEGORY.Remove(_category.exp_cat_id);
                        _grid.Rows.RemoveAt(e.RowIndex);
                    }
                    return;
                }
                else
                {
                    if (_grid.Rows[e.RowIndex].Tag == null)
                    {
                        //insert
                        if (datam.DATA_EXPENSE_CATEGORY.Values.FirstOrDefault(k => k.exp_cat_name.ToLower() == _grid.Rows[e.RowIndex].Cells[0].Text.ToLower()) != null)
                        {
                            dbm.ErrorMessage("Duplicate Entry Found", "Duplicate Error");
                            _grid.Rows[e.RowIndex].Cells[0].Value = null;
                            return;
                        }
                        var _category = new ic.expense_catC();
                        using (var xd = new xing())
                        {
                            _category.exp_cat_name = _grid.Rows[e.RowIndex].Cells[0].Text.ToProperCase();
                            _category.exp_cat_id   = xd.SingleInsertCommandTSPInt("acc_expense_cat_tb", new string[] { "exp_cat_name", "exp_type", "fs_time_stamp", "lch_id" },
                                                                                  new object[] { _category.exp_cat_name, emm.export_type.insert.ToByte(), 0, datam.LCH_ID });
                            xd.CommitTransaction();
                        }
                        _grid.Rows[e.RowIndex].Tag = _category;
                        datam.DATA_EXPENSE_CATEGORY.Add(_category.exp_cat_id, _category);
                        (fGrid.Rows["item_cat"].Cells["desc"].DropDownControl as iGDropDownList).Items.Add(new fnn.iGComboItemEX {
                            Tag = _category, Text = _category.exp_cat_name, Value = _category.exp_cat_name
                        });
                    }
                    else
                    {
                        var _category = _grid.Rows[e.RowIndex].Tag as ic.expense_catC;
                        _category.exp_cat_name = _grid.Rows[e.RowIndex].Cells[0].Value.ToStringNullable();
                        using (var xd = new xing())
                        {
                            xd.SingleUpdateCommandALL("acc_expense_cat_tb", new string[] { "exp_cat_name", "exp_cat_id" }, new object[] { _category.exp_cat_name, _category.exp_cat_id }, 1);
                            xd.CommitTransaction();
                        }
                        //update
                    }
                }
                #endregion
            }
            if (((e.RowIndex + 1) == _grid.Rows.Count))
            {
                AddRowX(_grid);
            }
        }
Esempio n. 2
0
        public static void FillExpenseCategories(xing xd)
        {
            if (DATA_EXPENSE_CATEGORY == null)
            {
                DATA_EXPENSE_CATEGORY = new SortedList <int, ic.expense_catC>();
            }
            string _table_name = "acc_expense_cat_tb";

            if (wdata.TABLE_STAMP == null)
            {
                wdata.TABLE_STAMP = new SortedList <string, long>();
            }
            if (wdata.TABLE_STAMP.IndexOfKey(_table_name) == -1)
            {
                wdata.TABLE_STAMP.Add(_table_name, 0);
            }
            bool   is_new   = false;
            bool   load_all = false;
            string _str     = string.Empty;
            long   _stamp   = xd.GetTimeStamp(_table_name);

            if (DATA_EXPENSE_CATEGORY.Keys.Count == 0)
            {
                _str     = "select * from " + _table_name;
                load_all = true;
            }
            else
            {
                if (wdata.TABLE_STAMP[_table_name] == _stamp)
                {
                    return;
                }
                _str = string.Format("select * from " + _table_name + " where fs_time_stamp > {0}", wdata.TABLE_STAMP[_table_name]);
            }
            wdata.TABLE_STAMP[_table_name] = _stamp;
            ic.expense_catC _obj = null;
            #region database fill
            using (var _dr = xd.SelectCommand(_str))
            {
                while (_dr.Read())
                {
                    _obj = null;
                    if (load_all)
                    {
                        _obj   = new ic.expense_catC();
                        is_new = true;
                    }
                    else
                    {
                        try
                        {
                            _obj   = datam.DATA_EXPENSE_CATEGORY[_dr["exp_cat_id"].ToInt32()];
                            is_new = false;
                        }
                        catch (Exception ex)
                        {
                            if (_obj == null)
                            {
                                _obj   = new ic.expense_catC();
                                is_new = true;
                            }
                        }
                    }
                    if (is_new)
                    {
                        _obj.exp_cat_id = _dr["exp_cat_id"].ToInt32();
                        datam.DATA_EXPENSE_CATEGORY.Add(_obj.exp_cat_id, _obj);
                    }
                    _obj.exp_cat_name = _dr["exp_cat_name"].ToStringNullable();
                }
                _dr.Close(); _dr.Dispose();
            }


            #endregion
        }