Пример #1
0
        //  set or update product qty
        public static async Task CheckAndSetProduct(Product product)
        {
            List <Product> products = await GetProductsAsync();

            foreach (Product pro in products)
            {
                if (pro.ProuductCode == product.ProuductCode)
                {
                    List <SqlParameter> sqlParams = new List <SqlParameter>();
                    sqlParams.Add(new SqlParameter("productid", pro.ProductId));
                    sqlParams.Add(new SqlParameter("code", pro.ProuductCode));
                    sqlParams.Add(new SqlParameter("name", pro.ProductName));
                    sqlParams.Add(new SqlParameter("supli", pro.SupplierId));
                    sqlParams.Add(new SqlParameter("category", pro.CategoryId));
                    sqlParams.Add(new SqlParameter("unitpricesale", pro.UnitPriceSales));
                    sqlParams.Add(new SqlParameter("unitpricebuy", pro.UnitPriceBuy));
                    sqlParams.Add(new SqlParameter("discount", pro.Discount));
                    sqlParams.Add(new SqlParameter("tax", pro.Tax));
                    sqlParams.Add(new SqlParameter("qty", product.Qty + pro.Qty));

                    await DataAccessAsync.ExecSPAsync("Production.updateProduct", sqlParams);

                    return;
                }
            }
            await SetProductAsync(product);

            return;
        }
Пример #2
0
        // set Order , order details and get order
        public static async Task <Orders> SetOrderAsync(Orders orders, List <OrderDetail> orderDetail)
        {
            Orders orderRes = new Orders();

            try
            {
                List <SqlParameter> sqlParameters = new List <SqlParameter>();
                sqlParameters.Add(new SqlParameter("custid", orders.CustId));
                sqlParameters.Add(new SqlParameter("empid", orders.EmpId));
                sqlParameters.Add(new SqlParameter("orderDate", orders.OrderDate));
                sqlParameters.Add(new SqlParameter("profit", orders.Profit));
                sqlParameters.Add(new SqlParameter("amountsell", orders.AmountSell));
                sqlParameters.Add(new SqlParameter("amountbuy", orders.AmountBuy));

                DataTable dtRes = await DataAccessAsync.ExecSPAsync("sales.setorder", sqlParameters);

                orderRes = DataTableToList <Orders>(dtRes).FirstOrDefault <Orders>();


                await SetOrderDetailAsync(orderDetail, orderRes.OrderId);

                return(orderRes);
            }
            catch (Exception ex)
            {
                await DeleteOrderAsync(orderRes);

                throw ex;
            }
        }
Пример #3
0
        // setOrderDetails
        public static async Task SetOrderDetailAsync(List <OrderDetail> orderDetails, int orderId)
        {
            List <Product> products = await GetProductsAsync();

            foreach (OrderDetail orderDetail in orderDetails)
            {
                if (products.Find(x => x.ProductId == orderDetail.ProductId).Equals(null))
                {
                    throw new Exception(String.Format("محصول وجود ندارد لطفا بررسی نمایید"));
                }
                else if (orderDetail.qty <= products.Where(x => x.ProductId == orderDetail.ProductId).FirstOrDefault <Product>().Qty)
                {
                    List <SqlParameter> sqlParams = new List <SqlParameter>();
                    sqlParams.Add(new SqlParameter("orderid", orderId));
                    sqlParams.Add(new SqlParameter("productid", orderDetail.ProductId));
                    sqlParams.Add(new SqlParameter("unitpricesales", orderDetail.UnitPriceSale));
                    sqlParams.Add(new SqlParameter("unitpricebuy", orderDetail.UnitPriceBuy));
                    sqlParams.Add(new SqlParameter("discount", orderDetail.discount));
                    sqlParams.Add(new SqlParameter("qty", orderDetail.qty));
                    sqlParams.Add(new SqlParameter("tax", orderDetail.Tax));
                    await DataAccessAsync.ExecSPAsync("sales.setorderdetails", sqlParams);
                }
                else if (orderDetail.qty > products.Where(x => x.ProductId == orderDetail.ProductId).FirstOrDefault <Product>().Qty)
                {
                    throw new Exception(String.Format("محصول {0} به تعداد کافی موجود نمی باشد",
                                                      products.Where(x => x.ProductId == orderDetail.ProductId).FirstOrDefault <Product>().ProductName));
                }
            }
        }
Пример #4
0
        // delete order and orderdetails
        public static async Task DeleteOrderAsync(Orders orders)
        {
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            sqlParameters.Add(new SqlParameter("orderid", orders.OrderId));

            await DataAccessAsync.ExecSPAsync("sales.deleteorder", sqlParameters);
        }
Пример #5
0
        //set category
        public static async Task SetCategoryAsync(Category category)
        {
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            sqlParameters.Add(new SqlParameter("name", category.CategoryName));
            sqlParameters.Add(new SqlParameter("desc", category.Description));
            await DataAccessAsync.ExecSPAsync("Production.setcategory", sqlParameters);
        }
Пример #6
0
        //set suplier
        public static async Task SetSuplierAsync(Suppliers supplier)
        {
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            sqlParameters.Add(new SqlParameter("name", supplier.CompanyName));
            sqlParameters.Add(new SqlParameter("phone", supplier.Phone));
            await DataAccessAsync.ExecSPAsync("Production.setsuplier", sqlParameters);
        }
Пример #7
0
        // findOrder by code
        public static async Task <List <Orders> > GetOrdersAsync(int code)
        {
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            sqlParameters.Add(new SqlParameter("orderid", code));

            DataTable dtRes = await DataAccessAsync.ExecSPAsync("", sqlParameters);

            return(DataTableToList <Orders>(dtRes));
        }
Пример #8
0
        // get list of product
        public static async Task <List <Product> > GetProductsAsync()
        {
            List <Product> products = new List <Product>();

            DataTable dtCustomers = await DataAccessAsync.ExecSPAsync("Production.getproduct");

            products = DataTableToList <Product>(dtCustomers);


            return(products);
        }
Пример #9
0
        // get list of supliers
        public static async Task <List <Suppliers> > GetSupliersAsync()
        {
            List <Suppliers> suppliers = new List <Suppliers>();

            DataTable dt = await DataAccessAsync.ExecSPAsync("Production.getsupliers");

            suppliers = DataTableToList <Suppliers>(dt);


            return(suppliers);
        }
Пример #10
0
        // get list of category
        public static async Task <List <Category> > GetCategoryAsync()
        {
            List <Category> categories = new List <Category>();

            DataTable dtCustomers = await DataAccessAsync.ExecSPAsync("Production.getcategory");

            categories = DataTableToList <Category>(dtCustomers);


            return(categories);
        }
Пример #11
0
        //get list of Customer
        public static async Task <List <Customers> > GetCustomersAsync()
        {
            List <Customers> customers = new List <Customers>();

            DataTable dtCustomers = await DataAccessAsync.ExecSPAsync("sales.getcustomers");

            customers = DataTableToList <Customers>(dtCustomers);


            return(customers);
        }
Пример #12
0
 //delete suplier
 public static async Task DeleteSupplier(Suppliers suppliers)
 {
     try
     {
         List <SqlParameter> sqlParameters = new List <SqlParameter>();
         sqlParameters.Add(new SqlParameter("supId", suppliers.SupplierId));
         await DataAccessAsync.ExecSPAsync("Production.deleteSupplier", sqlParameters);
     }catch (Exception ex)
     {
         throw new Exception("امکان حدف فروشنده وجود ندارد ");
     }
 }
Пример #13
0
        //getOrders by time
        public static async Task <List <Orders> > GetOrdersAsync(DateTime time1, DateTime time2, int empId)
        {
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            sqlParameters.Add(new SqlParameter("time1", time1));
            sqlParameters.Add(new SqlParameter("time2", time2));
            sqlParameters.Add(new SqlParameter("empid", empId));

            DataTable dtRes = await DataAccessAsync.ExecSPAsync("sales.getorderbytime", sqlParameters);

            return(DataTableToList <Orders>(dtRes));
        }
Пример #14
0
 //delete product
 public static async Task DeleteProduct(Product product)
 {
     try
     {
         List <SqlParameter> sqlParameters = new List <SqlParameter>();
         sqlParameters.Add(new SqlParameter("productId", product.ProductId));
         await DataAccessAsync.ExecSPAsync("Production.deleteProduct", sqlParameters);
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("امکان حذف وجود ندارد می توانید مقدار محصول را به صفر تغییر دهید " + ex.Message));
     }
 }
Пример #15
0
 //delete category
 public static async Task DeleteCategory(Category category)
 {
     try
     {
         List <SqlParameter> sqlParameters = new List <SqlParameter>();
         sqlParameters.Add(new SqlParameter("catId", category.CategoryId));
         await DataAccessAsync.ExecSPAsync("Production.deleteCategory", sqlParameters);
     }
     catch (Exception ex)
     {
         throw new Exception("امکان حدف دسته بندی وجود ندارد ");
     }
 }
Пример #16
0
        //uncompited
        public static async Task <List <OrderDetail> > GetOrderDetailsAsync(Orders orders)
        {
            List <OrderDetail> orderDetails = new List <OrderDetail>();

            List <SqlParameter> sql = new List <SqlParameter>();

            sql.Add(new SqlParameter("OrderId", orders.OrderId));
            DataTable dtOrderDetail = await DataAccessAsync.ExecSPAsync("Sales.getOrderDetails", sql);

            orderDetails = DataTableToList <OrderDetail>(dtOrderDetail);


            return(orderDetails);
        }
Пример #17
0
        //get cust by id
        public static async Task <List <Customers> > GetCustomersAsync(int id)
        {
            List <Customers> customers = new List <Customers>();

            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            sqlParameters.Add(new SqlParameter("custid", id));
            DataTable dtCustomers = await DataAccessAsync.ExecSPAsync("sales.getcustomersbyid", sqlParameters);

            customers = DataTableToList <Customers>(dtCustomers);


            return(customers);
        }
Пример #18
0
 //setCustomer
 public static async Task SetCustomerAsync(Customers customers)
 {
     try
     {
         List <SqlParameter> sqlParams = new List <SqlParameter>();
         sqlParams.Add(new SqlParameter("name", customers.CompanyName));
         sqlParams.Add(new SqlParameter("phone", customers.Phone));
         DataTable dtLoginRe = await DataAccessAsync.ExecSPAsync("sales.setcustomer", sqlParams);
     }catch (Exception e)
     {
         MessageBox.Show("لطفا مقادیر را برسی نمایید  " + "\n" + e.Message.ToString(),
                         "خطا",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }
Пример #19
0
        // setProduct
        public static async Task SetProductAsync(Product product)
        {
            List <SqlParameter> sqlParams = new List <SqlParameter>();

            sqlParams.Add(new SqlParameter("code", product.ProuductCode));
            sqlParams.Add(new SqlParameter("name", product.ProductName));
            sqlParams.Add(new SqlParameter("supli", product.SupplierId));
            sqlParams.Add(new SqlParameter("category", product.CategoryId));
            sqlParams.Add(new SqlParameter("unitpricesale", product.UnitPriceSales));
            sqlParams.Add(new SqlParameter("unitpricebuy", product.UnitPriceBuy));
            sqlParams.Add(new SqlParameter("discount", product.Discount));
            sqlParams.Add(new SqlParameter("tax", product.Tax));
            sqlParams.Add(new SqlParameter("qty", product.Qty));

            await DataAccessAsync.ExecSPAsync("Production.setproduct", sqlParams);
        }
Пример #20
0
        //login
        public static async Task <bool> LoginAsync(String Username, String Password)
        {
            List <SqlParameter> sqlParams = new List <SqlParameter>();

            sqlParams.Add(new SqlParameter("Username", Username.Trim().ToLower()));
            sqlParams.Add(new SqlParameter("Password", Password));

            DataTable dtLoginRe = await DataAccessAsync.ExecSPAsync("HR.loginSP", sqlParams);


            //check info
            if (dtLoginRe.Rows.Count == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #21
0
        //set emp uncompited
        public static async Task <String> SetEmp(EMP emp)
        {
            try
            {
                List <SqlParameter> sqlParameters = new List <SqlParameter>();
                sqlParameters.Add(new SqlParameter("company", emp.Company));
                sqlParameters.Add(new SqlParameter("first", emp.FirstName));
                sqlParameters.Add(new SqlParameter("last", emp.LastName));
                sqlParameters.Add(new SqlParameter("hire", emp.HireDate));
                sqlParameters.Add(new SqlParameter("title", emp.Title));

                DataTable table = await DataAccessAsync.ExecSPAsync("HR.setEmp", sqlParameters);

                return(table.Rows[0][0].ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("خطا در ثبت مشخصات کارمند " + ex.Message);
            }
        }
Пример #22
0
        //getEmp by username
        public static async Task <EMP> GetEmpAsync(String Username)
        {
            List <SqlParameter> sqlParams = new List <SqlParameter>();

            sqlParams.Add(new SqlParameter("Username", Username.Trim().ToLower()));

            DataTable dtLoginRe = await DataAccessAsync.ExecSPAsync("HR.GetEMP", sqlParams);


            //check info
            if (dtLoginRe.Rows.Count == 1)
            {
                List <EMP> emps = DataTableToList <EMP>(dtLoginRe);
                return(emps.FirstOrDefault <EMP>());
            }
            else
            {
                return(null);
            }
        }
Пример #23
0
        // check for product qty
        public static async Task <bool> CheckProductQtyAndSet(List <Product> products, Product product)
        {
            foreach (Product produc in products)
            {
                if (produc.ProductId == product.ProductId)
                {
                    if (produc.Qty > product.Qty)
                    {
                        List <SqlParameter> sqlParameters = new List <SqlParameter>();
                        sqlParameters.Add(new SqlParameter("productId", product.ProductId));
                        sqlParameters.Add(new SqlParameter("qty", product.Qty));

                        await DataAccessAsync.ExecSPAsync("Production.decreaseproduct", sqlParameters);

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }