/// <summary> /// it updates the customer information. /// </summary> public void saveCustomer() { VeritabaniIslemleri database = VeritabaniIslemleri.bagOlustur("SatisVeritabani"); string query = "update MusteriBilgileriTablosu set customerName = '" + Name + "', customerSurname = '" + Surname + "', customerAdress='" + Adress + "', customerEmail='" + Email + "', userName = '******', userPassword = '******' where customerID=" + UserID; database.veriKaydet(query); }
/// <summary> /// yeni eleman ekleyen metot. Factory patern kullanarak eleman türüne göre ekleme yapıyor /// </summary> /// <param name="product"></param> /// <param name="path"></param> public void addNewItem(Product product, string path) { Type sendedObject = product.GetType(); getMaxId(); string productValues = maxId + ",'" + product.Name.Replace("'", " ") + "'," + product.Price.ToString().Replace(',', '.') + ",'" + path + "','" + (product.Description.Replace('\'', ' ')) + "'," + product.Sale + ","; if (sendedObject.Name == "Book") { dataBase.veriKaydet("productId,productName,productPrice,productImage,productDescription,productSale,productType", productValues + "1", "UrunlerTablosu"); AddNewBook((Book)product); } else if (sendedObject.Name == "MusicCD") { dataBase.veriKaydet("productId,productName,productPrice,productImage,productDescription,productSale,productType", productValues + "2", "UrunlerTablosu"); AddNewMusicCD((MusicCD)product); } else if (sendedObject.Name == "Magazine") { dataBase.veriKaydet("productId,productName,productPrice,productImage,productDescription,productSale,productType", productValues + "3", "UrunlerTablosu"); AddNewMagazine((Magazine)product); } else { System.Windows.Forms.MessageBox.Show("INVALID PRODUCT"); } }
/// <summary> /// when this button clicked, /// if user == null the login page appear /// else the pnlUserNameClicked appear or vice versa /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bttnUserName_Click(object sender, EventArgs e) { Program.NotifyObserver(this.Name, ((Button)sender).Name); if (user == null) { LoginForm login = new LoginForm(); DialogResult result = login.ShowDialog(); if (result == DialogResult.Yes) { bttnUserName.Text = user.Name; VeritabaniIslemleri database = VeritabaniIslemleri.bagOlustur("SatisVeritabani"); string query = "select * from SepetTablosu where customerId = " + user.UserID + " and siparisId = 'none'"; DataTable table = database.veriCek(query); foreach (DataRow item in table.Rows) { query = "select * from UrunlerTablosu where productId = '" + item[1].ToString() + "'"; DataTable tablee = database.veriCek(query); shoppingCard.addProduct(new ItemToPurchase(addNewProductFromDatabase.CreateNewItem(tablee.Rows[0]), Convert.ToInt32(item[3]))); } query = "delete from SepetTablosu where customerId = " + user.UserID + " and siparisId = 'none'"; database.veriKaydet(query); query = "delete from ShoppingCartTable where CustomerId = " + user.UserID + " and siparisId = 'none'"; database.veriKaydet(query); } } else { if (pnlUserNameClicked.Visible == false) { pnlUserNameClicked.Visible = true; } else { pnlUserNameClicked.Visible = false; } } this.MainForm_Activated(this, new EventArgs()); }
/// <summary> /// it records the log info /// </summary> /// <param name="formname"> form name to record </param> /// <param name="bttnname"> button name to record </param> public override void record(string formname, string bttnname) { VeritabaniIslemleri database = VeritabaniIslemleri.bagOlustur("SatisVeritabani"); string query = ""; if (MainForm.user != null) { query = "INSERT INTO logtablosu (formName,buttonName,UserID,Date) VALUES('" + formname + "','" + bttnname + "', " + MainForm.user.UserID + " ,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')"; } else { query = "INSERT INTO logtablosu (formName,buttonName,UserID,Date) VALUES('" + formname + "','" + bttnname + "', " + 0 + " ,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')"; } database.veriKaydet(query); }
/// <summary> /// when the user wants to log out /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bttnlogout_Click(object sender, EventArgs e) { Program.NotifyObserver(this.Name, ((Button)sender).Name); try { VeritabaniIslemleri database = VeritabaniIslemleri.bagOlustur("SatisVeritabani"); string query = ""; for (int i = 0; i < shoppingCard.items.Count; i++) { query = "insert into SepetTablosu (customerId,urunId,siparisId,urunAdedi ) values(" + user.UserID + "," + shoppingCard.items.ElementAt(i).Value.product.Id + " ,'none' ," + shoppingCard.items.ElementAt(i).Value.quantity + " )"; database.veriKaydet(query); } } catch { } user = null; pnlUserNameClicked.Visible = false; bttnUserName.Text = "Sign In"; shoppingCard.cancelOrder(); btnAdminPaneli.Visible = false; this.MainForm_Activated(this, new EventArgs()); }
/// <summary> /// it works when form closing. /// if user != null it records the items in the shoping card in database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { //try //{ // VeritabaniIslemleri database = VeritabaniIslemleri.bagOlustur("SatisVeritabani"); // for (int i = 0; i <= shoppingCard.items.Count; i++) // { // string query = "insert into ShoppingCartTable (CustomerId,siparisId) values(" + user.UserID + ",'none')"; // database.veriKaydet(query); // query = "insert into SepetTablosu (customerId,urunId,siparisId,urunAdedi ) values(" + user.UserID + "," + shoppingCard.items.ElementAt(i).Value.product.Id + " ,'none' ," + shoppingCard.items.ElementAt(i).Value.quantity + " )"; // database.veriKaydet(query); // } //} //catch //{ //} Program.NotifyObserver(this.Name, "formclosing"); try { VeritabaniIslemleri database = VeritabaniIslemleri.bagOlustur("SatisVeritabani"); string query = ""; for (int i = 0; i < shoppingCard.items.Count; i++) { query = "insert into SepetTablosu (customerId,urunId,siparisId,urunAdedi ) values(" + user.UserID + "," + shoppingCard.items.ElementAt(i).Value.product.Id + " ,'none' ," + shoppingCard.items.ElementAt(i).Value.quantity + " )"; database.veriKaydet(query); } } catch { } user = null; pnlUserNameClicked.Visible = false; bttnUserName.Text = "Sign In"; shoppingCard.cancelOrder(); btnAdminPaneli.Visible = false; }
/// <summary> /// yeni bir CD ekleyen metot /// </summary> /// <param name="cd"></param> /// <param name="maxId"></param> public void addNewCd(MusicCD cd, string maxId) { string cdValues = maxId + "," + Convert.ToInt32(cd.Mcdtype) + ",'" + cd.Singer + "'"; dataBase.veriKaydet("productId,productType,productSinger", cdValues, "CdBilgileriTablosu"); }
/// <summary> /// yeni bir dergi ekleyen metot /// </summary> /// <param name="magazine"></param> /// <param name="maxId"></param> public void addNewMagazine(Magazine magazine, string maxId) { string magazineValues = maxId + ",'" + magazine.Issue + "'," + Convert.ToInt16(magazine.Mtype); dataBase.veriKaydet("productId,productIssue,productType", magazineValues, "MagazineBilgileriTablosu"); }
/// <summary> /// it saves the user /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bttnSignUp_Click(object sender, EventArgs e) { if (txtbxName.Text == "") { lbName.ForeColor = Color.Maroon; } else if (txtbxAdress.Text == "") { lbAdress.ForeColor = Color.Maroon; } else if (txtbxMail.Text == "") { lbMail.ForeColor = Color.Maroon; } else if (txtbxcheck.Text == "") { lbcheck.ForeColor = Color.Maroon; } else if (txtbxPassWord.Text == "") { lbPassWord.ForeColor = Color.Maroon; } else if (txtbxSurname.Text == "") { lbSurname.ForeColor = Color.Maroon; } else if (txtbxUserName.Text == "") { lbUserName.ForeColor = Color.Maroon; } else if (txtbxcheck.Text == txtbxPassWord.Text) { if (IsValidEmail(txtbxMail.Text)) { try { VeritabaniIslemleri database = VeritabaniIslemleri.bagOlustur("SatisVeritabani"); string checkQuery = "select * from MusteriBilgileriTablosu where userName ='******'"; DataTable check = database.veriCek(checkQuery); if (check.Rows.Count == 0) { string query = "INSERT INTO MusteriBilgileriTablosu(customerName,customerSurname,customerAdress,customerEmail,userName,userPassword,userAuthorization) VALUES('" + txtbxName.Text + "','" + txtbxSurname.Text + "','" + txtbxAdress.Text + "','" + txtbxMail.Text + "','" + txtbxUserName.Text + "','" + txtbxPassWord.Text + "'," + 0 + ")"; database.veriKaydet(query); Task.Delay(5000).Wait(); query = "SELECT * FROM MusteriBilgileriTablosu WHERE userName='******'and userPassword='******'"; DataTable table = database.veriCek(query); DataRow row = table.Rows[0]; MainForm.user = new Customer(); MainForm.user.UserID = Convert.ToInt32(row[0]); MainForm.user.Name = row[1].ToString(); MainForm.user.Surname = row[2].ToString(); MainForm.user.Adress = row[3].ToString(); MainForm.user.Email = row[4].ToString(); MainForm.user.Username = row[5].ToString(); MainForm.user.Password = row[6].ToString(); this.Close(); } else { MessageBox.Show("This user name using by another user"); lbUserName.ForeColor = Color.Maroon; } } catch { } } else { MessageBox.Show("This mail was not found"); } } }
/// <summary> /// yeni bir kitap ekleyen metot /// </summary> /// <param name="book"></param> /// <param name="maxId"></param> public void addNewBook(Book book, string maxId) { string bookValues = maxId + ",'" + book.Author + "'," + book.Isbn + ",'" + book.Publisher + "'," + book.Page + ",'" + book.size + "'," + Convert.ToInt16(book.type) + "," + Convert.ToInt16(book.l_anguage); dataBase.veriKaydet("productId,productAuthor,isbn,publisher,page,size,type,language", bookValues, "kitapBilgileriTablosu"); }