示例#1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvConnections.Rows.Count > 0)
            {
                MemberConnection con = (MemberConnection)dgvConnections.SelectedRows[0].DataBoundItem;

                string message = "You are about to delete the connection between {0} and {1}.\n\nAre you sure that you want to do this?";
                var    dResult = MessageBox.Show(string.Format(message, con.KeyMemberName, con.ConnectedPartyName),
                                                 "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dResult == DialogResult.Yes)
                {
                    try
                    {
                        DataSource.DeleteConnection(con.KeyMemberNameID, con.ConnectedPartyNameID);
                        // reload data grid
                        LoadConnections(con.KeyMemberNameID);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Oops! Something went wrong. \n\n" + ex.Message,
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        public static List <MemberConnection> GetConnections(int keyMemNameId)
        {
            List <MemberConnection> connections = new List <MemberConnection>();


            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DependTest"].ConnectionString);
            SqlCommand    cmd  = new SqlCommand("getConnections", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@keyMemNameID", keyMemNameId);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                MemberConnection memCon = new MemberConnection()
                {
                    KeyMemberNameID      = (int)reader["KeyMemberNameID"],
                    ConnectedPartyNameID = (int)reader["ConnectedPartyNameID"],
                    Relationship         = reader["Relationship"].ToString(),
                    EnteredBy            = reader["USER_NAME"].ToString(),
                    EnteredAt            = (DateTime)reader["EnteredAt"]
                };

                connections.Add(memCon);
            }


            return(connections);
        }
        public static List <MemberConnection> GetConnections(int keyMemNameId)
        {
            List <MemberConnection> connections = new List <MemberConnection>();

            using (SqlConnection conn = new SqlConnection(ConnStr))
            {
                string query = @"select USERSHADOW.USER_NAME,
	                    RSUDepend.dbo.CP_Connections.*,
	                    RSUDepend.dbo.CP_Relationships.Relationship	
                    from
	                    RSUDepend.dbo.CP_Connections
	                    left join RSUDepend.dbo.CP_Relationships on
		                    RSUDepend.dbo.CP_Relationships.RelationshipID = RSUDepend.dbo.CP_Connections.RelationshipID
	                    left join USERSHADOW on USERSHADOW.USER_ID = RSUDepend.dbo.CP_Connections.EnteredByUserID
	                    left join DEPOUSER on USERSHADOW.USER_ID = DEPOUSER.DEPOUSER_USER
	                    left join DEPOPART on DEPOPART.DEPOPART_ID = DEPOUSER.DEPOUSER_PART_ID
	                    where KeyMemberNameID = "     + keyMemNameId.ToString();

                conn.Open();
                SqlCommand    cmd    = new SqlCommand(query, conn);
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    MemberConnection memCon = new MemberConnection()
                    {
                        KeyMemberNameID      = (int)reader["KeyMemberNameID"],
                        ConnectedPartyNameID = (int)reader["ConnectedPartyNameID"],
                        Relationship         = reader["Relationship"].ToString(),
                        EnteredBy            = reader["USER_NAME"].ToString(),
                        EnteredAt            = (DateTime)reader["EnteredAt"]
                    };

                    connections.Add(memCon);
                }
            }

            return(connections);
        }