Exemple #1
0
        public Pawn PawnGetDetails(int pawnid)
        {
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("PawnGetDetails", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@PawnId", pawnid);

            try
            {
                conn.Open();

                SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);
                if (reader.Read())
                {
                    DateTime dti;
                    decimal ir;
                    Pawn currentpawn = new Pawn(pawnid,
                        DateTime.Parse(reader["PawnDate"].ToString()),
                        int.Parse(reader["FirstPawnId"].ToString()),
                        DateTime.Parse(reader["FirstPawnDate"].ToString()),
                        reader["Location"].ToString(),
                        Char.Parse(reader["PawnStatusId"].ToString()),
                        DateTime.TryParse(reader["PawnStatusDate"].ToString(), out dti) ? dti : (DateTime?)null,
                        decimal.TryParse(reader["InterestReceived"].ToString(), out ir) ? ir : (decimal?)null,
                        null,
                        decimal.Parse(reader["Amount"].ToString()),
                        0,
                        reader["Note"].ToString());
                    currentpawn.Customer = PartyGetDetails(Int32.Parse(reader["CustomerId"].ToString()));

                    currentpawn.Items = new ObservableCollection<Item>();

                    reader.NextResult();

                    Item currentitem;

                    while (reader.Read())
                    {
                        int ig;
                        currentitem = new Item(
                        int.Parse(reader["ItemId"].ToString()), int.Parse(reader["ItemTypeId"].ToString()), int.Parse(reader["ItemSubTypeId"].ToString()), int.Parse(reader["ItemTableId"].ToString()),
                            //int.Parse(reader["DisplayOrder"].ToString()),
                        (decimal)reader["Amount"], reader["Description"].ToString(), int.TryParse(reader["GunLogNumber"].ToString(), out ig) ? ig : (int?)null,
                        reader["Make"].ToString(), reader["Model"].ToString(), reader["Serial"].ToString(),
                        reader["Caliber"].ToString(), reader["Action"].ToString(), reader["Barrel"].ToString()
                        );

                        currentpawn.Items.Add(currentitem);
                    }

                    return currentpawn;
                    //if (i.ItemTypeId == 3)
                    //    l.IsGun = true;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Exemple #2
0
        public int PawnSave(Pawn pawn, int employee)
        {
            //pawn.Customer.PartyId = PartySave(pawn.Customer, employee);

            SqlConnection conn = new SqlConnection(connectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("PawnSave", conn);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlParameter pawnidparam = cmd.Parameters.Add("@PawnId", SqlDbType.Int);
            if (pawn.PawnId == 0)
                pawnidparam.Direction = ParameterDirection.Output;
            else
                pawnidparam.Direction = ParameterDirection.Input;
            pawnidparam.Value = pawn.PawnId;
            cmd.Parameters.AddWithValue("@FirstPawnId", pawn.FirstPawnId);
            cmd.Parameters.AddWithValue("@EmployeeId", employee);
            cmd.Parameters.AddWithValue("@PawnDate", pawn.Date);
            cmd.Parameters.AddWithValue("@CustomerId", pawn.Customer.PartyId);

            cmd.Parameters.AddWithValue("@Location", pawn.Location);
            cmd.Parameters.AddWithValue("@PawnStatusId", pawn.PawnStatusId);
            cmd.Parameters.AddWithValue("@PawnStatusDate", pawn.PawnStatusDate);
            cmd.Parameters.AddWithValue("@InterestReceived", pawn.InterestReceived);

            cmd.Parameters.AddWithValue("@ItemsXml", pawn.ItemsXml);
            cmd.Parameters.AddWithValue("@PawnNote", pawn.PawnNote);

            try
            {
                cmd.ExecuteNonQuery();
                return Int32.Parse(pawnidparam.Value.ToString());
            }
            catch (Exception Ex)
            {
                throw new Exception("Failed to save Pawn\n" + Ex.Message);
            }
        }
Exemple #3
0
        public ObservableCollection<Pawn> PawnGet(int partyid, int top, bool showall)
        {
            SqlConnection conn = new SqlConnection(connectionString);
            //Create Command w/Parameters
            SqlCommand cmd = new SqlCommand("PawnGet", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@PartyId", partyid);
            cmd.Parameters.AddWithValue("@Top", top);
            cmd.Parameters.AddWithValue("@ShowAll", showall);
            try
            {
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleResult);

                ObservableCollection<Pawn> pawns = new ObservableCollection<Pawn>();

                Pawn currentpawn;

                while (reader.Read())
                {
                    DateTime dti;
                    currentpawn = new Pawn(
                        int.Parse(reader["PawnId"].ToString()),
                        DateTime.Parse(reader["PawnDate"].ToString()),
                        int.Parse(reader["FirstPawnId"].ToString()),
                        DateTime.Parse(reader["FirstPawnDate"].ToString()),
                        reader["Location"].ToString(),
                        Char.Parse(reader["PawnStatusId"].ToString()),
                        DateTime.TryParse(reader["PawnStatusDate"].ToString(), out dti) ? dti : (DateTime?)null,
                        null,// interest received
                        reader["ItemDescriptionTicket"].ToString(),
                        decimal.Parse(reader["Amount"].ToString()),
                        int.Parse(reader["NumberOfFirearms"].ToString()),
                        reader["Note"].ToString()
                        );
                    currentpawn.Customer = PartyGetDetails(Int32.Parse(reader["PartyId"].ToString())
                    );
                    pawns.Add(currentpawn);
                }
                return pawns;
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
            finally
            {
                conn.Close();
            }
        }