public BillDTO getBillByID(Connection conn, int id)
        {
            string queryString = "select * from bill where id=" + id;

            conn.cmd.CommandText = queryString;

            using (DbDataReader reader = conn.cmd.ExecuteReader())
            {
                if (!reader.HasRows)
                {
                    return(new BillDTO());
                }
                else
                {
                    BillDTO temp = new BillDTO();
                    while (reader.Read())
                    {
                        temp = new BillDTO(
                            reader.GetInt32(0),
                            reader.GetDateTime(1),
                            reader.GetString(2),
                            reader.GetString(3),
                            reader.GetString(5),
                            reader.GetString(6));
                        break;
                    }
                    string[]       listPID  = temp.productsID.Trim().Split(' ');
                    string[]       listDPID = temp.defectiveProductsID.Trim().Split(' ');
                    List <ItemDTO> items    = new List <ItemDTO>();
                    for (int j = 0; j < listPID.Length; j++)
                    {
                        ItemDAO itemDAO = new ItemDAO();
                        if (itemDAO.getItemByID(conn, Convert.ToInt32(listPID[j])).ID != -1)
                        {
                            temp.products.Add(itemDAO.getItemByID(conn, Convert.ToInt32(listPID[j])));
                        }
                    }
                    for (int j = 0; j < listDPID.Length; j++)
                    {
                        ItemDAO itemDAO = new ItemDAO();
                        if (itemDAO.getItemByID(conn, Convert.ToInt32(listDPID[j])).ID != -1)
                        {
                            temp.defectiveProducts.Add(itemDAO.getItemByID(conn, Convert.ToInt32(listDPID[j])));
                        }
                    }
                    return(temp);
                }
            }
        }
Example #2
0
        public List <ItemOrderDTO> getAllItemOrder(Connection conn)
        {
            List <ItemOrderDTO> result = new List <ItemOrderDTO>();
            string queryString         = "select* from ItemOrder where isApproved = false and isDeleted = false";

            conn.cmd.CommandText = queryString;

            using (DbDataReader reader = conn.cmd.ExecuteReader())
            {
                if (!reader.HasRows)
                {
                    return(new List <ItemOrderDTO>());
                }
                else
                {
                    while (reader.Read())
                    {
                        ItemOrderDTO temp = new ItemOrderDTO(
                            reader.GetInt32(0),
                            reader.GetDateTime(1),
                            reader.GetString(2),
                            reader.GetInt32(3),
                            reader.GetString(4),
                            reader.GetBoolean(5));
                        result.Add(temp);
                    }
                }
            }
            for (int i = 0; i < result.Count; i++)
            {
                string[]       listSPID      = result[i].listItemID.Trim().Split(' ');
                List <ItemDTO> listOrderItem = new List <ItemDTO>();
                for (int j = 0; j < listSPID.Length; j++)
                {
                    ItemDAO itemDAO = new ItemDAO();
                    if (itemDAO.getItemByID(conn, Convert.ToInt32(listSPID[j])).ID != -1)
                    {
                        listOrderItem.Add(itemDAO.getItemByID(conn, Convert.ToInt32(listSPID[j])));
                    }
                }
                result[i].listSP = listOrderItem;
            }

            return(result);
        }