public static void fill_church_group_types(xing xd) { string _str = string.Empty; string _table_name = "church_group_types_tb"; if (DATA_CG_TYPES == null) { datam.DATA_CG_TYPES = new SortedList <int, ic.church_group_typeC>(); } 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; var _stamp = xd.GetTimeStamp(_table_name); if (DATA_CG_TYPES.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.church_group_typeC _obj = null; #region database fill try { using (var _dr = xd.SelectCommand(_str)) { while (_dr.Read()) { _obj = null; if (load_all) { _obj = new ic.church_group_typeC(); is_new = true; } else { try { _obj = datam.DATA_CG_TYPES[_dr["cg_type_id"].ToInt32()]; is_new = false; } catch (Exception ex) { if (_obj == null) { _obj = new ic.church_group_typeC(); is_new = true; } } } if (is_new) { _obj.cg_type_id = _dr["cg_type_id"].ToInt32(); datam.DATA_CG_TYPES.Add(_obj.cg_type_id, _obj); } _obj.cg_type_name = _dr["cg_type_name"].ToStringNullable(); _obj.sys_account_id = _dr["sys_account_id"].ToInt32(); _obj.is_default = _dr["is_default"].ToInt32() == 0 ? false : true; } _dr.Close(); _dr.Dispose(); } #endregion if (datam.DATA_CG_TYPES.Count == 0) { //no db records datam.DATA_CG_TYPES = new SortedList <int, ic.church_group_typeC>(); string[] _types = new string[] { "Family", "City", "Building Class", "Lesson Class", "Prayer Group", "FellowShip Group", "Cell", "Bible Class", "Cooking Class" }; int j = -200; foreach (var k in _types) { datam.DATA_CG_TYPES.Add(j, new ic.church_group_typeC() { cg_type_id = j, cg_type_name = k }); xd.SingleInsertCommandOnDuplicate(_table_name, new string[] { "cg_type_id", "cg_type_name", "fs_time_stamp", "lch_id" }, new object[] { datam.DATA_CG_TYPES[j].cg_type_id, datam.DATA_CG_TYPES[j].cg_type_name, 0, sdata.ChurchID }, string.Format("ON DUPLICATE KEY UPDATE fs_time_stamp={0}", SQLH.UnixStamp)); j++; } } if (load_all) { var _keys = (from k in xso.xso.DATA_MEM_COL_DET.Values where k.col_cat_id == 13 select k.col_id).ToList(); foreach (var k in _keys) { xso.xso.DATA_MEM_COL_DET.Remove(k); } int j = -1000; short disp_index = 1; foreach (var t in datam.DATA_CG_TYPES.Values) { xso.xso.DATA_MEM_COL_DET.Add(j, new xso.ic.Mem_col_det() { col_cat_id = 13, col_id = j, col_name = t.cg_type_name, disp_index = disp_index }); t.col_id = j; disp_index++; j++; } } else { var _col = (from k in xso.xso.DATA_MEM_COL_DET.Values where k.col_cat_id == 13 orderby k.col_id descending select k).FirstOrDefault(); int j = _col.col_id + 1; short disp_index = (_col.disp_index + 1).ToInt16(); foreach (var t in datam.DATA_CG_TYPES.Values.Where(f => f.col_id == 0)) { xso.xso.DATA_MEM_COL_DET.Add(j, new xso.ic.Mem_col_det() { col_cat_id = 13, col_id = j, col_name = t.cg_type_name, disp_index = disp_index }); t.col_id = j; disp_index++; j++; } } } catch (VistaDB.Diagnostic.VistaDBException ex) { MessageBox.Show(ex.Message); throw new Exception("Data Loading Failed"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonsave_Click(object sender, EventArgs e) { #region get type ic.church_group_typeC _type = comboBoxEx1.SelectedItem as ic.church_group_typeC; //em.church_group_typeS _type = em.church_group_typeS.Family; //switch (comboBoxEx1.SelectedIndex) //{ // case 0: // { // _type = em.church_group_typeS.Family; break; // } // case 1: // { // _type = em.church_group_typeS.City; break; // } // case 2: // { // _type = em.church_group_typeS.LessonClass; break; // } // case 3: // { // _type = em.church_group_typeS.BuildingClass; break; // } // case 4: // { // _type = em.church_group_typeS.FellowShipGroup; break; // } // case 5: // { // _type = em.church_group_typeS.PrayerGroup; break; // } // case 6: // { // _type = em.church_group_typeS.CookingClass; break; // } //} #endregion string _str = textBoxSender.Text.Trim(); if (datam.DATA_CHURCH_GROUPS != null) { var cnt = (from v in datam.DATA_CHURCH_GROUPS.Values where v.cg_type_id == _type.cg_type_id & v.cg_name.ToLower() == _str.ToLower() select v).Count(); if (cnt > 0) { _str = "A Group Name With The Same Name Already Exists"; dbm.ErrorMessage(_str, "Duplicate Group Name"); return; } } ic.church_groupC _c = new MTOMS.ic.church_groupC(); _c.cg_type_id = _type.cg_type_id; _c.cg_name = _str.ToProperCase(); string[] _cols = new string[] { "cg_name", "cg_type_id", "exp_type", "lch_id", "lch_type_id", "fs_time_stamp" }; object[] _row = new object[] { _c.cg_name, _c.cg_type_id, 33, datam.LCH_ID, datam.LCH_TYPE_ID, 0 }; using (var xd = new xing()) { if (xd.ExecuteScalarInt(string.Format("select count(cg_type_id) as cnt from church_group_tb where cg_type_id={0}", _c.cg_type_id)) == 0) { _type.sys_account_id = accn.CreateChildGroupAccount(xd, -2368, _type.cg_type_name).account_id; xd.SingleUpdateCommandALL("church_group_types_tb", new string[] { "sys_account_id", "cg_type_id" }, new object[] { _type.sys_account_id, _type.cg_type_id }, 1); } if (_type.sys_account_id == 0) { _type.sys_account_id = xd.ExecuteScalarInt("select sys_account_id from church_group_types_tb where cg_type_id=" + _type.cg_type_id); } _c.cg_id = xd.SingleInsertCommandInt("church_group_tb", _cols, _row); _c.sys_account_id = accn.CreateChildGroupAccount(xd, _type.sys_account_id, _c.cg_name).account_id; xd.SingleUpdateCommandALL("church_group_tb", new string[] { "sys_account_id", "cg_id" }, new object[] { _c.sys_account_id, _c.cg_id }, 1); //create general expense account for this xd.CommitTransaction(); } if (datam.DATA_CHURCH_GROUPS == null) { datam.DATA_CHURCH_GROUPS = new SortedList <int, MTOMS.ic.church_groupC>(); } datam.DATA_CHURCH_GROUPS.Add(_c.cg_id, _c); if (this.Owner is ChurchGroupManager2) { (this.Owner as ChurchGroupManager2).NewGroup(_c); } sdata.ClearFormCache(em.fm.chart_of_accounts.ToInt16()); sdata.ClearFormCache(em.fm.income_accounts_settings.ToInt16()); sdata.ClearFormCache(em.fm.creditors.ToInt16()); is_edited = true; textBoxSender.Clear(); textBoxSender.Focus(); }
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 _cg = _grid.Rows[e.RowIndex].Tag as ic.church_group_typeC; using (var xd = new xing()) { if (xd.ExecuteScalarInt("select TOP 1 cg_id from church_group_tb where cg_type_id=" + _cg.cg_type_id) == 0) { xd.SingleDeleteCommandExp("church_group_types_tb", new string[] { "cg_type_id" }, new int[] { _cg.cg_type_id }); xd.CommitTransaction(); } else { _grid.Rows[e.RowIndex].Cells[0].Value = _cg.cg_type_name; dbm.ErrorMessage("There Are Some Church Groups Which Are Attached To This Church Group Type", "Delete Operation Will Be Cancelled"); return; } } _grid.Rows[e.RowIndex].Tag = null; datam.DATA_CG_TYPES.Remove(_cg.cg_type_id); _grid.Rows.RemoveAt(e.RowIndex); this.Tag = 1; } return; } else { if (_grid.Rows[e.RowIndex].Tag == null) { //insert using (var xd = new xing()) { var ret_val = xd.ExecuteScalerInt(new string[] { "cg_type_name" }, string.Format("select count(cg_type_id) as cnt from church_group_types_tb where lower(cg_type_name)=@cg_type_name"), new object[] { _grid.Rows[e.RowIndex].Cells[0].Text.ToLower() }); if (ret_val > 0) { MessageBox.Show("You Have Already Entered This Item", "Duplicate Item Entry"); _grid.Rows[e.RowIndex].Cells[0].Value = null; return; } } var _cg = new ic.church_group_typeC(); using (var xd = new xing()) { _cg.cg_type_name = _grid.Rows[e.RowIndex].Cells[0].Text.ToProperCase(); _cg.cg_type_id = xd.SingleInsertCommandTSPInt("church_group_types_tb", new string[] { "cg_type_name", "fs_time_stamp", "lch_id" }, new object[] { _cg.cg_type_name, 0, datam.LCH_ID }); xd.CommitTransaction(); } _grid.Rows[e.RowIndex].Tag = _cg; datam.DATA_CG_TYPES.Add(_cg.cg_type_id, _cg); this.Tag = 1; } else { var _cg = _grid.Rows[e.RowIndex].Tag as ic.church_group_typeC; _cg.cg_type_name = _grid.Rows[e.RowIndex].Cells[0].Value.ToStringNullable(); using (var xd = new xing()) { xd.SingleUpdateCommandALL("church_group_types_tb", new string[] { "cg_type_name", "cg_type_id" }, new object[] { _cg.cg_type_name, _cg.cg_type_id }, 1); xd.CommitTransaction(); } this.Tag = 1; //update } Application.DoEvents(); using (var xd = new xing()) { datam.fill_church_group_types(xd); xd.CommitTransaction(); } } #endregion } if (((e.RowIndex + 1) == _grid.Rows.Count)) { AddRowX(_grid); } }
private void LoadDropDownLists() { m_Deparments = fnn.CreateCombo(); m_church_groups = fnn.CreateCombo(); m_members = fnn.CreateCombo(); m_CG_Shared = fnn.CreateCombo(); if (datam.DATA_CHURCH_GROUPS != null) { foreach (var k in datam.DATA_CHURCH_GROUPS.Values) { m_church_groups.Items.Add(new fnn.iGComboItemEX() { ID = k.cg_id, Value = string.Format("{0} :: {1}", datam.DATA_CG_TYPES[k.cg_type_id].cg_type_name, k.cg_name) }); } // var dlist = (from l in datam.DATA_CHURCH_GROUPS.Values select l.cg_type_id).Distinct().ToList(); ic.church_group_typeC _cg_type = null; foreach (var k in dlist) { _cg_type = datam.DATA_CG_TYPES[k]; m_CG_Shared.Items.Add(new fnn.iGComboItemEX() { ID = _cg_type.cg_type_id, Value = string.Format("{0} Shared", _cg_type.cg_type_name), ForeColor = Color.DarkBlue }); } } // if (datam.DATA_DEPARTMENT != null) { var nlist = from k in datam.DATA_DEPARTMENT.Values where k.dept_type == em.dept_typeS.main orderby k.dept_name select k; foreach (var k in nlist) { m_Deparments.Items.Add(new fnn.iGComboItemEX() { ID = k.dept_id, Value = k.dept_name }); } } // if (datam.DATA_MEMBER != null) { var nlist = from k in datam.DATA_MEMBER.Values where k.IsCurrentMember select k; foreach (var k in nlist) { m_members.Items.Add(new fnn.iGComboItemEX() { ID = k.mem_id, Value = string.Format("{0}-{1}", k.mem_name, k.mem_code) }); } } }