/// <summary>
        /// 
        /// </summary>
        /// <param name="AgentID"></param>
        /// <returns></returns>
        internal int DeleteIAgentGroupByAgentID(int AgentID)
        {
            int Result = -1;
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.IAgentGroupTableAdapter adap = new DSTableAdapters.IAgentGroupTableAdapter();

            try
            {
                conn.Open();
                adap.Connection = conn;
                Result = adap.DeleteIAgentGroupByAgentID(AgentID);
            }
            catch (Exception ex)
            {
                Result = -1;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return Result;
        }
예제 #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="AgentID"></param>
        /// <param name="AgentGroupID"></param>
        /// <param name="Name"></param>
        internal bool UpdateAgent(Business.Agent agent)
        {
            bool Result = false;
            System.Data.SqlClient.SqlTransaction trans = null;
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.AgentTableAdapter adapAgent = new DSTableAdapters.AgentTableAdapter();
            DSTableAdapters.IAgentGroupTableAdapter adapIAgentGroup = new DSTableAdapters.IAgentGroupTableAdapter();
            try
            {
                conn.Open();
                trans                          = conn.BeginTransaction();
                adapAgent.Connection           = conn;
                adapAgent.Transaction          = trans;

                adapIAgentGroup.Connection     = conn;
                adapIAgentGroup.Transaction    = trans;

                int Record                     = adapAgent.UpdateAgent(agent.AgentGroupID, agent.Name, agent.Comment, agent.IsDisable, agent.IsIpFilter, agent.IpForm, agent.IpTo, agent.GroupCondition, agent.AgentID);
                if (Record > 0)
                {
                    Result                     = true;
                }
                else
                {
                    throw new Exception("Data error");
                }
                adapIAgentGroup.DeleteIAgentGroupByAgentID(agent.AgentID);
                List<int> listInvestorGroupIDs = new List<int>();
                listInvestorGroupIDs           = agent.MakeListIAgentGroupManager(agent.GroupCondition);
                int count                      = listInvestorGroupIDs.Count;
                for (int i = 0; i < count; i++)
                {

                    int idIAgentGroup = int.Parse(adapIAgentGroup.AddIAgentGroup(agent.AgentID, listInvestorGroupIDs[i]).ToString());
                    if (idIAgentGroup < 1)
                    {
                        throw new Exception("Data error");
                    }
                }

                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                Result = false;
            }
            finally
            {
                adapAgent.Connection.Close();
                adapIAgentGroup.Connection.Close();
                conn.Close();
            }
            return Result;
        }