public static void GetMemberID(xing xd)
 {
     mem_id = xd.IDCtrlGet(mem_id_tb, 2012, 1001);
     if (mem_id == 666 || mem_id == 1000)
     {
         xd.IDCtrlDelete(mem_id_tb);
         mem_id = dbm.IDCtrlGet(mem_id_tb, 2012, 1001);
     }
     mem_code = fn.GetMemberCode(mem_id);
     mem_id   = (string.Format("{0}{1}", datam.LCH_ID, mem_id)).ToInt32();
 }
        //
        public static bool Save_member(xing xd, ic.memberC mem_obj)
        {
            if (xd == null)
            {
                return(false);
            }
            if (mem_obj == null)
            {
                return(false);
            }

            string[] tb_col = null;
            object[] _row   = null;
            object   _bdate = null;
            object   _jdate = null;

            //if (!string.IsNullOrEmpty(mem_obj.mem_birth_date))
            //{
            //    _bdate = Convert.ToDateTime(mem_obj.mem_birth_date);
            //}
            GetMemberID(xd);
            mem_obj.mem_id        = mem_id;
            mem_obj.mem_code      = mem_code;
            mem_obj.mem_u_code    = string.Format("{0}-{1}", mem_obj.mem_code, datam.LCH_ID);
            mem_obj.mem_status_id = em.xmem_status.Normal.ToByte();
            mem_obj.country_id    = -1;
            if (mem_obj.join_date != null)
            {
                _jdate = mem_obj.join_date.Value;
            }
            Int64 _stamp = xd.CreateFsTimeStamp();

            tb_col = new string[]
            {
                #region MyRegion
                "mem_id",
                "mem_code",
                "mem_u_code",
                "mem_title_id",
                "mem_name",
                "mem_o_name",
                "mem_gender_id",
                "mem_birth_yr",
                "mem_birth_date",
                "mem_birth_fs_id",
                "marital_type_id",
                "e_fs_id",
                "e_date",
                "baptismal_type_id",
                "mem_status_type_id",
                "mem_educ_level_id",
                "prev_church",
                "lch_type_id",
                "lch_id",
                "exp_type",
                "country_id",
                "tribe_id",
                "join_year",
                "join_date",
                "join_fs_id",
                "national_id",
                "national_id_type",
                "fs_time_stamp",
                "pc_us_id",
                "xfield1",
                "xfield2",
                "mem_type_id",
                "prev_religion",
                "empl_status_id",
                "mem_church_code"
                #endregion
            };

            _row = new object[]
            {
                #region MyRegion
                mem_obj.mem_id,
                mem_obj.mem_code,
                mem_obj.mem_u_code,
                mem_obj.mem_title_id,
                mem_obj.mem_name,
                mem_obj.mem_o_name,
                mem_obj.gender_id,
                mem_obj.birth_yr,
                _bdate,
                mem_obj.mem_birth_fs_id,
                mem_obj.marital_type_id,
                datam.CURR_FS.fs_id,
                datam.CURR_DATE,
                mem_obj.baptismal_type_id,
                mem_obj.mem_status_id,
                mem_obj.educ_level_id,
                mem_obj.prev_church,
                datam.LCH_TYPE_ID,
                datam.LCH_ID,
                emm.export_type.insert.ToByte(),
                mem_obj.country_id,
                0,//tribe name
                mem_obj.join_year,
                _jdate,
                mem_obj.join_fs_id,
                0, // national id
                0, //national_id_type
                _stamp,
                datam.PC_US_ID,
                0,
                0,
                mem_obj.mem_type.ToByte(),
                mem_obj.prev_religion,
                mem_obj.employment_status.ToByte(),
                mem_obj.mem_church_code
                #endregion
            };
            xd.SingleInsertCommand("member_tb", tb_col, _row);
            xd.IDCtrlDelete(mem_id_tb);
            return(true);
        }
        private void buttonadd_Click(object sender, EventArgs e)
        {
            if (m_action == action_type.create)
            {
                #region Insert Region
                ic.accountC _account = new MTOMS.ic.accountC();
                _account.account_status = em.account_statusS.Enabled;
                _account.a_index        = curr_node.Index.ToInt16();
                _account.a_level        = curr_node.Level.ToInt16();
                int gp_id = 0;
                var _sect = GetRoot(curr_node);
                _account.account_dept_category = (em.account_d_categoryS)_sect.acc_d_cat_id;
                _account.account_dept_type     = (em.account_d_typeS)_sect.acc_d_type_id;
                if (curr_node.Level > 1)
                {
                    _account.p_account_id = curr_node.Parent == null ? 0 : (curr_node.Parent.Tag as ic.accountC).account_id;
                }
                using (var xd = new xing())
                {
                    switch (m_object)
                    {
                    case object_type.GroupAccount:
                    {
                        #region Add New Types
                        _account.account_type = curr_node.Level == 1 ? em.account_typeS.GroupAccount : em.account_typeS.SubGroupAccount;
                        curr_node.Text        = textBox1.Text.Trim().ToProperCase();
                        _account.account_name = curr_node.Text;
                        curr_node.Style       = _folder_style;
                        curr_node.ContextMenu = contextMenuFolder;
                        //  curr_node.Image = MUTTICO.Properties.Resources.Folder;
                        m_action = action_type.none;
                        if (_account.account_type == em.account_typeS.SubGroupAccount)
                        {
                            gp_id = (curr_node.Parent.Tag as ic.accountC).account_id;
                        }
                        break;
                        #endregion
                    }

                    case object_type.Account:
                    {
                        if (datam.DuplicateAccountName(textBox1.Text.Trim().ToProperCase(), xd))
                        {
                            MessageBox.Show("The Account Name You Have Entered Already Exists", "Duplicate Account Name");
                            buttonclose.PerformClick();
                            return;
                        }
                        #region Add New Types
                        _account.account_type = em.account_typeS.ActualAccount;
                        curr_node.Text        = textBox1.Text.Trim().ToProperCase();
                        _account.account_name = curr_node.Text;
                        curr_node.Style       = _folder_style;
                        curr_node.ContextMenu = contextMenuFile;
                        // curr_node.Image = MUTTICO.Properties.Resources.email;
                        m_action = action_type.none;
                        switch (curr_node.Level)
                        {
                        case 2:
                        case 3:
                        {
                            gp_id = (curr_node.Parent.Tag as ic.accountC).account_id;
                            break;
                        }
                        }
                        break;
                        #endregion
                    }
                    }
                    string[] _cols = new string[]
                    {
                        "account_id",
                        "acc_d_cat_id",
                        "acc_d_type_id",
                        "account_name",
                        "account_type_id",
                        "account_alias",
                        "a_level",
                        "a_index",
                        "p_account_id",
                        "exp_type",
                        "fs_time_stamp",
                        "edate",
                        "pc_us_id",
                        "account_status_id",
                        "search_alias",
                        "is_sys_account",
                        "post_type_id",
                        "owner_type_id",
                        "owner_id",
                        "owner_name",
                        "start_date",
                        "end_date", "opening_balance",
                        "account_short_name", "account_code", "description", "lch_id"
                    };
                    object[] _row = new object[]
                    {
                        _account.account_id = xd.IDCtrlGet("acc_id_xxx", 2013, -500),
                        _account.account_dept_category.ToByte(),
                        _account.account_dept_type.ToByte(),
                        _account.account_name,
                        _account.account_type.ToByte(),
                        _account.account_alias,
                        _account.a_level,
                        _account.a_index,
                        _account.p_account_id = gp_id,
                        emm.export_type.insert.ToByte(),
                        0,
                        datam.CURR_DATE,
                        datam.PC_US_ID,
                        _account.account_status.ToByte(),
                        null, //search_alias
                        0,    // is_sys_account
                        0,    //post_type
                        0,    //owner_type
                        0,    //owner_id
                        null, //owner name
                        sdata.CURR_DATE,
                        null,
                        0,    //opening balance
                        null, //account_short_name
                        null, // account_code
                        null, //description
                        sdata.App_station_id
                    };
                    xd.SingleInsertCommandInt("accounts_tb", _cols, _row);
                    xd.IDCtrlDelete("acc_id_xxx");
                    curr_node.Name = string.Format("Account{0}", _account.account_id);
                    xd.CommitTransaction();
                }
                #endregion
                curr_node.Tag = _account;
                datam.DATA_ACCOUNTS.Add(_account.account_id, _account);
                labelclient.Text = _account.account_name;
                if (_account.account_type == em.account_typeS.ActualAccount)
                {
                    curr_node.Style = _file_style;
                }
                else
                {
                    curr_node.Style = _folder_style;
                }

                _account = null;
                buttonclose.PerformClick();
            }
            if (m_action == action_type.update)
            {
                if (curr_node != null && curr_node.Tag != null)
                {
                    var _folder = curr_node.Tag as ic.accountC;
                    if (_folder != null)
                    {
                        using (var xd = new xing())
                        {
                            if (datam.DuplicateAccountName(textBox1.Text.Trim().ToProperCase(), xd, _folder.account_id))
                            {
                                MessageBox.Show("The Account Name You Have Entered Already Exists", "Duplicate Account Name");
                                buttonclose.PerformClick();
                                return;
                            }
                            xd.SingleUpdateCommandALL("accounts_tb", new string[] { "account_name", "account_id" }, new object[] { textBox1.Text.Trim().ToProperCase(), _folder.account_id }, 1);
                            xd.CommitTransaction();
                        }
                        _folder.account_name = textBox1.Text.Trim().ToProperCase();
                        curr_node.Text       = _folder.account_name;
                        buttonclose.PerformClick();
                    }
                }
            }
        }