private void btn_Buy_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { productRepository = new ProductRepository(context); var userid = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[7].Value.ToString()); var user = context.Users.Where(u => u.Id == userid).FirstOrDefault(); Product product = new Product() { Id = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[0].Value), Name = dgw_ProductTable.CurrentRow.Cells[1].Value.ToString(), CategoryId = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[5].Value.ToString()), Price = Convert.ToDecimal(dgw_ProductTable.CurrentRow.Cells[2].Value.ToString()), Count = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[3].Value.ToString()) - 1, CreatedUserId = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[7].Value.ToString()), PhoneNumber = user.Phone, Status = 0, }; productRepository.Update(product); if (product.Count == 0) { product.Status = 1; } GetAllProduct(); } }
public void GetProductInsertedByUser() { using (ShopManagementContext context = new ShopManagementContext()) { SortByExpireDate(); int userid = Convert.ToInt32(lbl_UserId.Text); var query = context.Products.Where(y => y.Status == (int)Status.Active && y.UserId == userid).Select(product => new { product.Id, product.Name, product.Price, product.Count, Category = product.Category.Name, UserName = product.User.Name, product.UserId, product.CategoryId, Status = ((Enums.Status)product.Status), product.PhoneNumber, product.SoldedCount, product.SoldedTotal, product.ExpireDate }).ToList(); dgw_ProductTable.DataSource = query; } }
public void UserSearchByName() { using (ShopManagementContext context = new ShopManagementContext()) { int currentUserId = Convert.ToInt32(lbl_UserId.Text); var currentUser = context.Users.Where(y => y.Id == currentUserId).FirstOrDefault(); var query = context.Products.Where(y => y.Status == (int)Status.Active && y.UserId == currentUserId && y.Name.Contains(txb_SearchNameByUSer.Text)).Select(product => new { product.Id, product.Name, product.Price, product.Count, Category = product.Category.Name, product.CategoryId, product.Status, product.UserId, product.PhoneNumber, product.SoldedCount }).ToList(); //var search = query.Where(p => p.Name.Contains(txb_SearchNameByUSer.Text)).ToList(); dgw_ProductTable.DataSource = query; } }
private void SearchCategory() { using (ShopManagementContext context = new ShopManagementContext()) { int currentUserId = Convert.ToInt32(lbl_UserId.Text); var currentUser = context.Users.Where(y => y.Id == currentUserId).FirstOrDefault(); var query = context.Products.Where(y => y.Status == (int)Status.Active && y.UserId == currentUserId).Select(product => new { product.Id, product.Name, product.Price, product.Count, Category = product.Category.Name, product.CategoryId, product.Status, product.UserId, product.PhoneNumber, product.SoldedCount }).ToList(); if (cmb_SearchByUserCategory.SelectedIndex != 0) { var search = query.Where(product => product.CategoryId == Convert.ToInt32(cmb_SearchByUserCategory.Text.Split('.')[0])).ToList(); dgw_ProductTable.DataSource = search; } else { dgw_ProductTable.DataSource = query; } } }
public List <T> GetAll() { using (ShopManagementContext context = new ShopManagementContext()) { return(context.Set <T>().ToList()); } }
private void GetAllProduct() { using (ShopManagementContext context = new ShopManagementContext()) { SortByExpireDate(); var query = context.Products.Where(y => y.Status == (int)Status.Active).Select(product => new { product.Id, product.Name, product.Price, product.Count, Category = product.Category.Name, UserName = product.User.Name, product.UserId, product.CategoryId, Status = ((Enums.Status)product.Status), product.PhoneNumber, product.SoldedCount, product.SoldedTotal, product.ExpireDate }).ToList(); dgw_ProductTable.DataSource = query; } }
private void btnUpdate_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { _productRepository = new ProductRepository(context); _logProductRepository = new LogProductRepository(context); int userid = Convert.ToInt32(lbl_UserId.Text); var user = context.Users.Where(y => y.Id == userid).FirstOrDefault(); if (String.IsNullOrEmpty(tbx_productName.Text) || String.IsNullOrEmpty(txb_Count.Text) || String.IsNullOrEmpty(txb_Price.Text) || String.IsNullOrEmpty(cmb_Category.Text) || rtb_Description.Text == "") { MessageBox.Show("İzahat hissəsin doldurun"); } else { Product product = new Product() { Id = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[0].Value), Name = tbx_productName.Text, CategoryId = Convert.ToInt32(cmb_Category.Text.Split('.')[0]), Price = Convert.ToDecimal(txb_Price.Text), Count = Convert.ToInt32(txb_Count.Text), UserId = user.Id, PhoneNumber = user.Phone, Status = (int)Status.Active, ExpireDate = dtp_Expire.Value }; LogProduct logProduct = new LogProduct() { ProductId = product.Id, Description = rtb_Description.Text, Status = (int)Status.Modified, UserId = user.Id, Date = DateTime.Now }; _productRepository.Update(product); _productRepository.Save(); _logProductRepository.Insert(logProduct); _logProductRepository.Save(); Clear(); if (user.RoleId == (int)Enums.Role.Admin) { GetAllProduct(); } else { GetProductInsertedByUser(); } } } }
private void GetAll() { using (ShopManagementContext context = new ShopManagementContext()) { repository = new CategoryRepository(context); var query = repository.GetAll(); var t = query.Where(y => y.Status == 0).ToList(); dgw_Table.DataSource = t; } }
public ReportForm() { InitializeComponent(); ShopManagementContext context = new ShopManagementContext(); _catrepository = new CategoryRepository(context); _userRepository = new UserRepository(context); SetCategory(); }
private void SetCategory() { using (ShopManagementContext context = new ShopManagementContext()) { repository = new CategoryRepository(context); foreach (Category category in repository.GetAll()) { cmb_Category.Items.Add(category.Id + "." + category.Name); cmb_UpdatePr.Items.Add(category.Id + "." + category.Name); } } }
private void btn_Delete_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { _productRepository = new ProductRepository(context); _logProductRepository = new LogProductRepository(context); int userid = Convert.ToInt32(lbl_UserId.Text); var user = context.Users.Where(y => y.Id == userid).FirstOrDefault(); if (rtb_Description.Text == "") { MessageBox.Show("Izahat mətnini daxil edin"); } else { Product product = new Product() { Id = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[0].Value), Name = dgw_ProductTable.CurrentRow.Cells[1].Value.ToString(), CategoryId = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[7].Value.ToString()), Price = Convert.ToDecimal(dgw_ProductTable.CurrentRow.Cells[2].Value.ToString()), Count = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[3].Value.ToString()), UserId = user.Id, PhoneNumber = user.Phone, Status = (int)Status.Deactive, ExpireDate = dtp_Expire.Value }; LogProduct logProduct = new LogProduct() { ProductId = product.Id, Description = rtb_Description.Text, Status = (int)Status.Deleted, UserId = user.Id, Date = DateTime.Now }; _productRepository.Update(product); _logProductRepository.Insert(logProduct); _productRepository.Update(product); _productRepository.Save(); if (user.RoleId == (int)Enums.Role.Admin) { GetAllProduct(); } else { GetProductInsertedByUser(); } } } }
private void btn_GetAllUser_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { int userid = Convert.ToInt32(lbl_UserId.Text); var user = context.Users.Where(u => u.Id == userid).FirstOrDefault(); cmb_UserSearch.SelectedIndex = 0; cmb_SearchDetail.SelectedIndex = 0; ReportForUser(userid); } }
private void SetUser() { using (ShopManagementContext context = new ShopManagementContext()) { _userRepository = new UserRepository(context); cmb_User.Items.Insert(0, "select"); cmb_User.SelectedIndex = 0; foreach (User user in _userRepository.GetAll()) { cmb_User.Items.Add(user.Id + "." + user.Name); } } }
public void Actions() { int userid = Convert.ToInt32(lbl_UserId.Text); using (ShopManagementContext context = new ShopManagementContext()) { var user = context.Users.Where(u => u.Id == userid).FirstOrDefault(); if (user.RoleId != (int)Enums.Role.Admin) { tabControl1.TabPages.Remove(tabPage1); } } }
private void btn_Update_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { repository = new CategoryRepository(context); Category book = new Category() { Id = Convert.ToInt32(dgw_Table.CurrentRow.Cells[0].Value), Name = txb_UpdateName.Text, }; repository.Update(book); GetAll(); } }
private void btn_Login_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { _repository = new UserRepository(context); var userList = _repository.GetAll(); string email = txb_Email.Text; string password = txb_Password.Text; if (string.IsNullOrEmpty(txb_Email.Text) && string.IsNullOrEmpty(txb_Password.Text)) { MessageBox.Show("Email və ya şifrə daxil edilməyib"); } else { var user = userList.Where(p => p.Email == email).FirstOrDefault(); var result = _repository.IfExist(email, password, userList); //if(!string.IsNullOrEmpty(txb_Email.Text) && !string.IsNullOrEmpty(txb_Password.Text) // && userList.Any(user=> user.Email.ToLower()==txb_Email.Text.ToLower() && user.Password == txb_Password.Text)) if (result) { if (user.RoleId == 1) { textBox1.Text = Convert.ToString(user.Id); IndexForm index = new IndexForm(); CategoryForm form = new CategoryForm(); delPassData del = new delPassData(index.funData); del(this.textBox1); index.Show(); } else { textBox1.Text = Convert.ToString(user.Id); IndexForm index = new IndexForm(); CategoryForm form = new CategoryForm(); delPassData del = new delPassData(index.funData); del(this.textBox1); index.Show(); } } else { MessageBox.Show("Email və ya şifrə doğru daxil edilməyib"); } } } }
private void IndexForm_Load(object sender, EventArgs e) { delPassData del = new delPassData(productForm.funData); del(this.textBox1); using (ShopManagementContext context = new ShopManagementContext()) { int userid = Convert.ToInt32(textBox1.Text); var query = context.Users.Where(u => u.Id == userid).FirstOrDefault(); if (query.RoleId == (int)Enums.Role.User) { btn_Category.Visible = false; } } }
private void btn_Insert_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { repository = new CategoryRepository(context); Category category = new Category() { Name = txb_Name.Text, Status = 0 }; repository.Insert(category); GetAll(); } }
private void ReportForm_Load(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { int userid = Convert.ToInt32(lbl_UserId.Text); var user = context.Users.Where(u => u.Id == userid).FirstOrDefault(); if (user.RoleId == (int)Enums.Role.User) { lbl_Prices.Visible = false; txbSearchPrice.Visible = false; lbl_Status.Visible = false; textBStatus.Visible = false; } ReportForUser(userid); } }
private void btn_DeleteCategory_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { repository = new CategoryRepository(context); Category product = new Category() { Id = Convert.ToInt32(dgw_Table.CurrentRow.Cells[0].Value), Name = dgw_Table.CurrentRow.Cells[1].Value.ToString(), Status = 1 }; repository.Update(product); GetAll(); } }
public void ButtonAction() { int userid = Convert.ToInt32(lbl_UserId.Text); using (ShopManagementContext context = new ShopManagementContext()) { var user = context.Users.Where(u => u.Id == userid).FirstOrDefault(); if (user.RoleId == (int)Enums.Role.Admin) { btn_Buy.Visible = true; } else { btn_Buy.Visible = false; } } }
private void btn_Insert_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { _productRepository = new ProductRepository(context); int userid = Convert.ToInt32(lbl_UserId.Text); var user = context.Users.Where(y => y.Id == userid).FirstOrDefault(); if (String.IsNullOrEmpty(tbx_productName.Text) || String.IsNullOrEmpty(txb_Count.Text) || String.IsNullOrEmpty(txb_Price.Text) || String.IsNullOrEmpty(cmb_Category.Text) || cmb_Category.SelectedIndex == 0) { MessageBox.Show("Xanalari doldurun"); } else { Product pr = new Product() { Name = tbx_productName.Text, CategoryId = Convert.ToInt32(cmb_Category.Text.Split('.')[0]), Price = Convert.ToDecimal(txb_Price.Text), Count = Convert.ToInt32(txb_Count.Text), UserId = user.Id, PhoneNumber = user.Phone, Status = (int)Status.Active, SoldedTotal = 0, SoldedCount = 0, ExpireDate = dtp_Expire.Value }; _productRepository.Insert(pr); _productRepository.Save(); if (user.RoleId == (int)Enums.Role.Admin) { GetAllProduct(); } else { GetProductInsertedByUser(); } Clear(); } } }
private void SearchbyUser() { using (ShopManagementContext context = new ShopManagementContext()) { int currentUserId = Convert.ToInt32(lbl_UserId.Text); var currentUser = context.Users.Where(y => y.Id == currentUserId).FirstOrDefault(); var query = context.Products.Where(y => y.Status == (int)Status.Active && y.UserId == currentUserId).Select(product => new { product.Id, product.Name, product.Price, product.Count, Category = product.Category.Name, product.CategoryId, product.Status, product.UserId, product.PhoneNumber, product.SoldedCount }).ToList(); if (!String.IsNullOrEmpty(txb_SearchDetailName.Text)) { query = query.Where(x => x.Name.ToLower().Contains(txb_SearchDetailName.Text.ToLower())).ToList(); } if (!String.IsNullOrEmpty(txbSearchPrice.Text)) { query = query.Where(x => x.Price == Convert.ToDecimal(txbSearchPrice.Text)).ToList(); } if (!String.IsNullOrEmpty(txbSerachCount.Text)) { query = query.Where(x => x.Count == Convert.ToInt32(txbSerachCount.Text)).ToList(); } if (!String.IsNullOrEmpty(cmb_User.Text)) { query = query.Where(x => x.UserId == Convert.ToInt32(cmb_User.Text.Split('.')[0])).ToList(); } if (!String.IsNullOrEmpty(cmb_SearchDetail.Text)) { query = query.Where(x => x.CategoryId == Convert.ToInt32(cmb_SearchDetail.Text.Split('.')[0])).ToList(); } dgw_ProductTable.DataSource = query; } }
private void GetAllProduct() { using (ShopManagementContext context = new ShopManagementContext()) { var query = context.Products.Where(y => y.Status == 0).Select(product => new { product.Id, product.Name, product.Price, product.Count, Category = product.Category.Name, product.CategoryId, product.Status, product.CreatedUserId, product.PhoneNumber }).ToList(); dgw_ProductTable.DataSource = query; } }
private void btnUpdate_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { productRepository = new ProductRepository(context); logProductRepository = new LogProductRepository(context); int userid = Convert.ToInt32(lbl_UserId.Text); var user = context.Users.Where(y => y.Id == userid).FirstOrDefault(); Product product = new Product() { Id = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[0].Value), Name = txb_PrUpdateName.Text, CategoryId = Convert.ToInt32(cmb_UpdatePr.Text.Split('.')[0]), Price = Convert.ToDecimal(txb_PrUpdatePrice.Text), Count = Convert.ToInt32(txb_PrUpdateCount.Text), CreatedUserId = user.Id, PhoneNumber = user.Phone, Status = 0, }; if (rtb_Description.Text == null) { MessageBox.Show("Izahat mətnini daxil edin"); } else { LogProduct logProduct = new LogProduct() { ProductId = product.Id, Description = rtb_Description.Text, Status = 1, UserId = user.Id, Date = DateTime.Now }; productRepository.Update(product); logProductRepository.Insert(logProduct); } GetAllProduct(); } }
private void SortByExpireDate() { using (ShopManagementContext context = new ShopManagementContext()) { _productRepository = new ProductRepository(context); _logProductRepository = new LogProductRepository(context); var list = _productRepository.GetAll(); var user = context.Users.Where(u => u.RoleId == (int)Enums.Role.Admin).FirstOrDefault(); var sortedList = list.Where(p => p.ExpireDate.Day.CompareTo(DateTime.Now.Day) == 0); foreach (var i in sortedList) { i.Status = (int)Enums.Status.Expired; i.Name = i.Name; i.Id = i.Id; i.PhoneNumber = i.PhoneNumber; i.Price = i.Price; i.SoldedCount = i.SoldedCount; i.ExpireDate = i.ExpireDate; i.SoldedTotal = i.SoldedTotal; i.UserId = i.UserId; i.CategoryId = i.CategoryId; i.Count = i.Count; _productRepository.Update(i); _productRepository.Save(); LogProduct logProduct = new LogProduct() { ProductId = i.Id, Description = "İstifadə tarxi bitib", Status = (int)Status.Expired, UserId = user.Id, Date = i.ExpireDate }; _logProductRepository.Insert(logProduct); _logProductRepository.Save(); } } }
private void btn_Update_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { _repository = new CategoryRepository(context); if (String.IsNullOrEmpty(txb_Name.Text)) { MessageBox .Show("KAtegoriya adi daxil edin"); } else { Category book = new Category() { Id = Convert.ToInt32(dgw_Table.CurrentRow.Cells[0].Value), Name = txb_Name.Text, }; _repository.Update(book); _repository.Save(); GetAll(); } } }
private void button1_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { productRepository = new ProductRepository(context); int userid = Convert.ToInt32(lbl_UserId.Text); var user = context.Users.Where(y => y.Id == userid).FirstOrDefault(); Product pr = new Product() { Name = tbx_productName.Text, CategoryId = Convert.ToInt32(cmb_Category.Text.Split('.')[0]), Price = Convert.ToInt32(txb_Price.Text), Count = Convert.ToInt32(txb_Count.Text), CreatedUserId = user.Id, PhoneNumber = user.Phone, Status = 0, SoldedTotal = 0, SoldedCount = 0 }; productRepository.Insert(pr); GetAllProduct(); } }
private void SetCategory() { using (ShopManagementContext context = new ShopManagementContext()) { _categoryrepository = new CategoryRepository(context); var catlist = _categoryrepository.GetAll(); cmb_Category.Items.Insert(0, "select"); cmb_Category.SelectedIndex = 0; foreach (Category category in catlist.Where(c => c.Status == 0)) { cmb_Category.Items.Add(category.Id + "." + category.Name); cmb_SearchCategory.Items.Add(category.Id + "." + category.Name); cmb_SearchDetail.Items.Add(category.Id + "." + category.Name); cmb_SearchByUserCategory.Items.Add(category.Id + "." + category.Name); } //cmb_SearchByUserCategory.Items.Insert(0, "select"); } }
public void SearchtextBox() { int userid = Convert.ToInt32(lbl_UserId.Text); using (ShopManagementContext context = new ShopManagementContext()) { var user = context.Users.Where(u => u.Id == userid).FirstOrDefault(); if (user.RoleId == (int)Enums.Role.Admin) { txb_SearchNameByUSer.Visible = false; cmb_SearchByUserCategory.Visible = false; txb_SearchName.Visible = true; cmb_SearchCategory.Visible = true; } else { txb_SearchNameByUSer.Visible = true; cmb_SearchByUserCategory.Visible = true; txb_SearchName.Visible = false; cmb_SearchCategory.Visible = false; } } }