예제 #1
0
        public List <ProductModel> RetrieveProducts(string SqlCmd, int SupplierId = 0)
        {
            var output = new List <ProductModel>();

            using (SqlConnection conn = new SqlConnection(DatabaseConnectionString))
            {
                using (SqlCommand comm = new SqlCommand(SqlCmd, conn)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                })
                {
                    if (SupplierId != 0)
                    {
                        comm.Parameters.Clear();
                        comm.Parameters.Add("@suppId", System.Data.SqlDbType.Int).Value = SupplierId;
                    }

                    try
                    {
                        conn.Open();

                        try
                        {
                            using (SqlDataReader reader = comm.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    var objValidateString = new ValidateReaderString();

                                    while (reader.Read())
                                    {
                                        output.Add(new ProductModel()
                                        {
                                            Id           = reader.GetInt32(0),
                                            Description  = objValidateString.Validate(reader.GetValue(1)),
                                            Code         = objValidateString.Validate(reader.GetValue(2)),
                                            Amount       = (double)reader.GetValue(3),
                                            SupplierId   = reader.GetInt32(4),
                                            SupplierName = objValidateString.Validate(reader.GetValue(5)),
                                            Error        = string.Empty
                                        });
                                    }
                                }
                                else
                                {
                                    output = null;
                                }

                                return(output);
                            }
                        }
                        catch (Exception ex)
                        {
                            output.Add(new ProductModel()
                            {
                                Id    = 0,
                                Error = ex.Message.ToString()
                            });

                            return(output);
                        }
                    }
                    catch (Exception ex)
                    {
                        output.Add(new ProductModel()
                        {
                            Id    = 0,
                            Error = ex.Message.ToString()
                        });

                        return(output);
                    }
                    finally
                    {
                        if (conn.State != System.Data.ConnectionState.Closed)
                        {
                            conn.Close();
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// The RetrieveSuppliers
        /// </summary>
        /// <param name="SqlCmd">The SqlCmd<see cref="string"/></param>
        /// <returns>The <see cref="List{SupplierModel}"/></returns>
        public List <SupplierModel> RetrieveSuppliers(string SqlCmd)
        {
            var output = new List <SupplierModel>();

            using (SqlConnection conn = new SqlConnection(DatabaseConnectionString))
            {
                using (SqlCommand comm = new SqlCommand(SqlCmd, conn)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                })
                {
                    try
                    {
                        conn.Open();

                        try
                        {
                            using (SqlDataReader reader = comm.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    var objValidateString = new ValidateReaderString();

                                    while (reader.Read())
                                    {
                                        output.Add(new SupplierModel()
                                        {
                                            Id    = reader.GetInt32(0),
                                            Name  = objValidateString.Validate(reader.GetValue(1)),
                                            Error = string.Empty
                                        });
                                    }
                                }
                                else
                                {
                                    output.Add(new SupplierModel()
                                    {
                                        Id    = 0,
                                        Error = reader.GetString(0)
                                    });
                                }

                                return(output);
                            }
                        }
                        catch (Exception ex)
                        {
                            output.Add(new SupplierModel()
                            {
                                Id    = 0,
                                Error = ex.Message.ToString()
                            });

                            return(output);
                        }
                    }
                    catch (Exception ex)
                    {
                        output.Add(new SupplierModel()
                        {
                            Id    = 0,
                            Error = ex.Message.ToString()
                        });

                        return(output);
                    }
                    finally
                    {
                        if (conn.State != System.Data.ConnectionState.Closed)
                        {
                            conn.Close();
                        }
                    }
                }
            }
        }
예제 #3
0
        public List <PurchaseOrderDetailModel> RetrievPOSDetail(string SqlCmd, int PurchaseOrderId)
        {
            var output = new List <PurchaseOrderDetailModel>();

            using (SqlConnection conn = new SqlConnection(DatabaseConnectionString))
            {
                using (SqlCommand comm = new SqlCommand(SqlCmd, conn)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                })
                {
                    comm.Parameters.Clear();
                    comm.Parameters.Add("@poId", System.Data.SqlDbType.Int).Value = PurchaseOrderId;

                    try
                    {
                        conn.Open();

                        try
                        {
                            using (SqlDataReader reader = comm.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    var objValidateString = new ValidateReaderString();

                                    while (reader.Read())
                                    {
                                        output.Add(new PurchaseOrderDetailModel()
                                        {
                                            Id                 = reader.GetInt32(0),
                                            ProductId          = reader.GetInt32(1),
                                            PurchaseOrderId    = reader.GetInt32(2),
                                            DateCreated        = reader.GetDateTime(3),
                                            Amount             = (double)reader.GetValue(4),
                                            Qty                = reader.GetInt32(5),
                                            ProductDescription = objValidateString.Validate(reader.GetValue(6)),
                                            Error              = string.Empty
                                        });
                                    }
                                }
                                else
                                {
                                    output.Add(new PurchaseOrderDetailModel()
                                    {
                                        Id    = 0,
                                        Error = reader.GetString(0)
                                    });
                                }

                                return(output);
                            }
                        }
                        catch (Exception ex)
                        {
                            output.Add(new PurchaseOrderDetailModel()
                            {
                                Id    = 0,
                                Error = ex.Message.ToString()
                            });

                            return(output);
                        }
                    }
                    catch (Exception ex)
                    {
                        output.Add(new PurchaseOrderDetailModel()
                        {
                            Id    = 0,
                            Error = ex.Message.ToString()
                        });

                        return(output);
                    }
                    finally
                    {
                        if (conn.State != System.Data.ConnectionState.Closed)
                        {
                            conn.Close();
                        }
                    }
                }
            }
        }
예제 #4
0
        public List <PurchaseOrderModel> RetrievePOS(string SqlCmd)
        {
            var output = new List <PurchaseOrderModel>();

            using (SqlConnection conn = new SqlConnection(DatabaseConnectionString))
            {
                using (SqlCommand comm = new SqlCommand(SqlCmd, conn)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                })
                {
                    try
                    {
                        conn.Open();

                        try
                        {
                            using (SqlDataReader reader = comm.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    var objValidateString = new ValidateReaderString();

                                    while (reader.Read())
                                    {
                                        output.Add(new PurchaseOrderModel()
                                        {
                                            Id          = reader.GetInt32(0),
                                            Description = objValidateString.Validate(reader.GetValue(1)),
                                            Supplier    = objValidateString.Validate(reader.GetValue(2)),
                                            Created     = reader.GetDateTime(3),
                                            Amount      = (reader.GetValue(4) == DBNull.Value)? 0 : (double)reader.GetValue(4),
                                            SupplierId  = reader.GetInt32(5),
                                            Error       = string.Empty
                                        });
                                    }
                                }
                                else
                                {
                                    output.Add(new PurchaseOrderModel()
                                    {
                                        Id    = 0,
                                        Error = reader.GetString(0)
                                    });
                                }

                                return(output);
                            }
                        }
                        catch (Exception ex)
                        {
                            output.Add(new PurchaseOrderModel()
                            {
                                Id    = 0,
                                Error = ex.Message.ToString()
                            });

                            return(output);
                        }
                    }
                    catch (Exception ex)
                    {
                        output.Add(new PurchaseOrderModel()
                        {
                            Id    = 0,
                            Error = ex.Message.ToString()
                        });

                        return(output);
                    }
                    finally
                    {
                        if (conn.State != System.Data.ConnectionState.Closed)
                        {
                            conn.Close();
                        }
                    }
                }
            }
        }