Exemple #1
0
 private void btnUpdateSponsor_Click(object sender, RoutedEventArgs e)
 {
     if (dgSponsor.SelectedIndex >= 0)
     {
         var        s = Sponsor.GetSponsorByID((int)(dgSponsor.Items[dgSponsor.SelectedIndex] as DataRowView)[0], true);
         MainWindow m = App.Current.MainWindow as MainWindow;
         m.SendTabItem(new TabItem()
         {
             Header = s.Name, Content = new SponsorControl(s)
         });
     }
 }
        public static List <AvailableSponsorship> GetAllAvailableSponsorship()
        {
            List <AvailableSponsorship> xx = new List <AvailableSponsorship>();
            SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand    com = new SqlCommand("sp_Get_All_AvailableSponsorship", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                while (rd.Read())
                {
                    AvailableSponsorship x = new AvailableSponsorship();

                    if (!(rd["ID"] is DBNull))
                    {
                        x.ID = int.Parse(rd["ID"].ToString());
                    }
                    x.RelatedSponsor = Sponsor.GetSponsorByID(int.Parse(rd["SponsorID"].ToString()));
                    x.NOB            = int.Parse(rd["NOB"].ToString());
                    x.remainingNOB   = int.Parse(rd["RemainingNOB"].ToString());
                    if (!(rd["Duration"] is DBNull))
                    {
                        x.Duration = double.Parse(rd["Duration"].ToString());
                    }
                    if (!(rd["SponsorshipValue"] is DBNull))
                    {
                        x.SponsorshipValue = double.Parse(rd["SponsorshipValue"].ToString());
                    }
                    x.SponsorshipType = rd["SponsorshipType"].ToString();
                    x.Notes           = rd["Notes"].ToString();
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }
                    if (!(rd["IsCompensated"] is DBNull))
                    {
                        x.IsCompensated = bool.Parse(rd["IsCompensated"].ToString());
                    }
                    if (!(rd["OverMonths"] is DBNull))
                    {
                        x.OverMonths = int.Parse(rd["OverMonths"].ToString());
                    }
                    x.SponsorType = rd["SponsorType"].ToString();
                    if (!(rd["CreateDate"] is DBNull))
                    {
                        x.CreateDate = DateTime.Parse(rd["CreateDate"].ToString());
                    }
                    xx.Add(x);
                }
                rd.Close();
            }
            catch
            {
                xx = null;
            }
            finally
            {
                con.Close();
            }
            return(xx);
        }