private void buttonadd_Click(object sender, EventArgs e) { if (m_action == action_type.create) { #region Insert Region ic.church_sub_unitC _unit = new MTOMS.ic.church_sub_unitC(); _unit.sb_unit_name = textBox1.Text.Trim().ToProperCase(); _unit.sb_unit_category = (em.sb_unit_categoryS)curr_node.Parent.Tag.ToByte(); string[] _cols = new string[] { "sb_unit_name", "sb_unit_cat_id", "exp_type", "fs_time_stamp", "lch_id", }; object[] _row = new object[] { _unit.sb_unit_name, _unit.sb_unit_category.ToByte(), 33, 0, sdata.App_station_id, }; using (var xd = new xing()) { //if (datam.DuplicateDepartmentName(_unit.dept_name, xd)) //{ // MessageBox.Show("The Department Name You Have Entered Already Exists", "Duplicate Department Name"); // buttonclose.PerformClick(); // return; //} _unit.sb_unit_id = xd.SingleInsertCommandTSPInt("church_sub_unit_tb", _cols, _row); curr_node.Tag = _unit; curr_node.Text = _unit.sb_unit_name; curr_node.Name = string.Format("DEPT{0}", _unit.sb_unit_id); switch (curr_node.Level) { case 1: { curr_node.Style = _sb_dept_style; break; } case 2: { curr_node.Style = _sb_dept_style; break; } } curr_node.ContextMenu = contextMenuFile; accn.CreateSubUnitCrExpAccount(_unit, xd); xd.CommitTransaction(); } #endregion datam.DATA_CHURCH_SUB_UNIT.Add(_unit.sb_unit_id, _unit); _unit = null; m_action = action_type.none; if (!is_edited) { is_edited = true; } buttonclose.PerformClick(); } if (m_action == action_type.update) { if (curr_node != null && curr_node.Tag != null) { var _unit = curr_node.Tag as ic.church_sub_unitC; if (_unit != null) { using (var xd = new xing()) { //if (datam.DuplicateDepartmentName(textBox1.Text.Trim().ToProperCase(), xd, _dept.dept_id)) //{ // MessageBox.Show("The Department Name You Have Entered Already Exists", "Duplicate Department Name"); // buttonclose.PerformClick(); // return; //} xd.SingleUpdateCommandALL("church_sub_unit_tb", new string[] { "sb_unit_name", "sb_unit_id" }, new object[] { textBox1.Text.Trim().ToProperCase(), _unit.sb_unit_id }, 1); xd.CommitTransaction(); } _unit.sb_unit_name = textBox1.Text.Trim().ToProperCase(); curr_node.Text = _unit.sb_unit_name; if (!is_edited) { is_edited = true; } buttonclose.PerformClick(); } } } }
public static void FillChurchSubUnits(xing xd) { if (DATA_CHURCH_SUB_UNIT == null) { DATA_CHURCH_SUB_UNIT = new SortedList <int, MTOMS.ic.church_sub_unitC>(); } bool is_new = false; bool load_all = false; string _str = string.Empty; if (wdata.TABLE_STAMP == null) { wdata.TABLE_STAMP = new SortedList <string, long>(); } string _table_name = "church_sub_unit_tb"; if (wdata.TABLE_STAMP.IndexOfKey(_table_name) == -1) { wdata.TABLE_STAMP.Add(_table_name, 0); } var _stamp = xd.GetTimeStamp(_table_name); if (DATA_CHURCH_SUB_UNIT.Keys.Count == 0) { _str = "select * from church_sub_unit_tb"; load_all = true; } else { if (_stamp == wdata.TABLE_STAMP[_table_name]) { return; } _str = string.Format("select * from church_sub_unit_tb where fs_time_stamp > {0}", wdata.TABLE_STAMP[_table_name]); } wdata.TABLE_STAMP[_table_name] = _stamp; ic.church_sub_unitC _obj = null; #region database fill using (var _dr = xd.SelectCommand(_str)) { while (_dr.Read()) { _obj = null; if (load_all) { _obj = new MTOMS.ic.church_sub_unitC(); is_new = true; } else { try { _obj = datam.DATA_CHURCH_SUB_UNIT[_dr["sb_unit_id"].ToInt32()]; is_new = false; } catch (Exception ex) { if (_obj == null) { _obj = new MTOMS.ic.church_sub_unitC(); is_new = true; } } } if (is_new) { _obj.sb_unit_id = _dr["sb_unit_id"].ToInt32(); _obj.sb_unit_category = (em.sb_unit_categoryS)_dr["sb_unit_cat_id"].ToInt32(); _obj.sb_unit_name = _dr["sb_unit_name"].ToStringNullable(); _obj.sys_gp_account_id = _dr["sys_gp_account_id"].ToInt32(); datam.DATA_CHURCH_SUB_UNIT.Add(_obj.sb_unit_id, _obj); } _obj.sb_unit_name = _dr["sb_unit_name"].ToStringNullable(); } _dr.Close(); _dr.Dispose(); } #endregion }