Exemplo n.º 1
0
        public bool AddSalesman(User u)
        {
            DbCommunicator dc    = new DbCommunicator();
            string         query = $"SELECT* FROM Users WHERE UserName = '******'";
            SqlDataReader  data  = dc.GetData(query);

            while (data.Read())
            {
                u.ErrorMessage = "This user is already exist";
                dc.DbConnection.Close();
                return(false);
            }
            dc.DbConnection.Close();
            query = $"INSERT INTO Users VALUES ('{u.UserName}','{u.Password}','{u.Role}')";
            int row = dc.WriteData(query);

            dc.DbConnection.Close();
            if (row > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool LoginAction(User u)
        {
            DbCommunicator dc    = new DbCommunicator();
            string         query = $"SELECT * FROM Users WHERE UserName = '******' AND Password = '******'";
            SqlDataReader  data  = dc.GetData(query);

            while (data.Read())
            {
                u.Role = data.GetString(2);
                if (u.Role.Equals("admin"))
                {
                    new AdminForm().Show();
                }
                else if (u.Role.Equals("Salesman"))
                {
                    SalesForm.user = u;
                    new SalesForm().Show();
                }

                dc.DbConnection.Close();
                return(true);
            }
            u.ErrorMessage = "Login credentials do not match";
            return(false);
        }
Exemplo n.º 3
0
        public ReportModel GetReport(DateTime dt)
        {
            ReportModel    rp = new ReportModel();
            string         query = $"SELECT Profit, SalesPrice FROM Sales WHERE Date = '{dt.Date}'";
            DbCommunicator dc = new DbCommunicator();
            SqlDataReader  data = dc.GetData(query);
            double         profit = 0, total = 0;

            while (data.Read())
            {
                profit += data.GetDouble(0);
                total  += data.GetDouble(1);
            }
            dc.DbConnection.Close();
            rp.Profit = profit.ToString();
            rp.Total  = total.ToString();
            return(rp);
        }
Exemplo n.º 4
0
        public List <Product> GetAllProducts()
        {
            DbCommunicator dc     = new DbCommunicator();
            string         query  = "SELECT * FROM Products";
            SqlDataReader  data   = dc.GetData(query);
            List <Product> ppList = new List <Product>();

            while (data.Read())
            {
                ppList.Add(new Product()
                {
                    Id           = data.GetInt32(0),
                    ProductName  = data.GetString(1),
                    CurrentStock = data.GetInt32(2),
                    Description  = data.GetString(3),
                    BuyingCost   = data.GetDouble(4),
                    Price        = data.GetDouble(5)
                });
            }
            dc.DbConnection.Close();
            return(ppList);
        }