示例#1
0
        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            var x = this.DataContext as ExternalFamilySupport;

            if (x.ExternalFamilySupportID != null)
            {
                var efs = new ExternalFamilySupport();
                efs.FamilyID     = FamilyID;
                this.DataContext = efs;
            }
        }
        public static ExternalFamilySupport GetExternalFamilySupportByID(int id)
        {
            ExternalFamilySupport x   = new ExternalFamilySupport();
            SqlConnection         con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand            com = new SqlCommand("sp_GetExternalFamilySupportByID", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter pr = new SqlParameter("@ExternalFamilySupportID", id);

            com.Parameters.Add(pr);
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                if (rd.Read())
                {
                    if (!(rd["ExternalFamilySupportID"] is DBNull))
                    {
                        x.ExternalFamilySupportID = System.Int32.Parse(rd["ExternalFamilySupportID"].ToString());
                    }
                    if (!(rd["FamilyID"] is DBNull))
                    {
                        x.FamilyID = System.Int32.Parse(rd["FamilyID"].ToString());
                    }
                    x.SupportType   = rd["SupportType"].ToString();
                    x.SupportSourse = rd["SupportSourse"].ToString();
                    x.Value         = rd["Value"].ToString();
                    if (!(rd["Date"] is DBNull))
                    {
                        x.Date = System.DateTime.Parse(rd["Date"].ToString());
                    }
                    x.Notes = rd["Notes"].ToString();
                }
                rd.Close();
            }
            catch
            {
                x = null;
            }
            finally
            {
                con.Close();
            }
            return(x);
        }