public List <PjPlainte> getPJPlainte(String idplainte) { List <PjPlainte> pjplaintes = new List <PjPlainte>(); if (cn.State == ConnectionState.Closed) { cn.Open(); } SqlCommand sqlCommand = new SqlCommand("SELECT * FROM PJ_plainte where id_plainte like @x", cn); sqlCommand.Parameters.Add("@x", "%" + idplainte + "%"); SqlDataReader reader = sqlCommand.ExecuteReader(); while (reader.Read()) { PjPlainte pj = new PjPlainte(); pj.Id_pj = (int)reader["id_pj"]; pj.Id_plainte = (String)reader["id_plainte"]; pj.Titre = (String)reader["titre"]; pj.Photo = (byte[])reader["photo"]; // pj.Date_enregistrement=(String) reader["date_enregistrement"]; pjplaintes.Add(pj); } cn.Close(); return(pjplaintes); }
/* * * PjPlainte * * **/ public void addPjPalainte(PjPlainte pp) { if (cn.State == ConnectionState.Closed) { cn.Open(); } SqlTransaction tx = cn.BeginTransaction(); try { SqlCommand cmd = new SqlCommand("insert into PJ_plainte values(@photo,@titre,@date,@idplainte)", cn); SqlParameter p1 = new SqlParameter("@photo", pp.Photo); SqlParameter p2 = new SqlParameter("@titre", pp.Titre); SqlParameter p3 = new SqlParameter("@date", pp.Date_enregistrement); SqlParameter p4 = new SqlParameter("@idplainte", pp.Id_plainte); cmd.Parameters.Add(p1); cmd.Parameters.Add(p2); cmd.Parameters.Add(p3); cmd.Parameters.Add(p4); cmd.Transaction = tx; cmd.ExecuteNonQuery(); tx.Commit(); cn.Close(); // MessageBox.Show("تمت الإضافة بنجاح"); } catch (Exception e) { tx.Rollback(); MessageBox.Show(e.Message); //Console.WriteLine(e.Message); } }
private void simpleButton2_Click(object sender, EventArgs e) { //save PJ setup if (u == 1 && comboBox1.Text != "") { foreach (string fileName in of.FileNames) { try { FileInfo fi = new FileInfo(fileName); PjPlainte pjplaint = new PjPlainte(); byte[] img = null; FileStream f = new FileStream(of.FileName, FileMode.Open); BinaryReader br = new BinaryReader(f); img = br.ReadBytes((int)f.Length); f.Close(); pjplaint.Id_plainte = comboBox1.Text; pjplaint.Photo = img; pjplaint.Titre = Path.GetFileName(of.FileName); pjplaint.Date_enregistrement = DateTime.Parse(DateTime.Now.ToShortDateString()); // pjOrder1.id_order = ord.id_order; op.addPjPalainte(pjplaint); MessageBox.Show("تمت إضافة الوثيقة بنجاح"); history.AddHistory("وثائق الشكاية", "الاضافة", comboBox1.Text); getDataTable(); } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } u = 0; } else { MessageBox.Show("يجب اختيار رقم الشكاية في خانة الشكايات لإضافة الوثيقة"); } }
private void btn_ajouter_Click(object sender, EventArgs e) { if (isvalidate()) { PlaintesOperations op = new PlaintesOperations(); Plainte p = new Plainte(); p.IdPlainte = txb_num_pl.Text; p.DateCreation = date_plai.Value; p.DateDepotPlainte = date_depot_plainte.Value; //p.Decision = txtdecision.Text; p.IdPlaignant = int.Parse(textBoxNumClient.Text); p.Ville = cb_ville.Text; p.SignePlainte = txb_symbole.Text; p.TypeTribunal = comboBox_tribunal.Text; p.TypePlaint = txb_genre_pl.Text; //Console.WriteLine("Test1: "+p.DateCreation+" "+p.TypeTribunal); // MessageBox.Show("Test1: " + p.DateCreation + " " + p.TypeTribunal); op.addPlainte(p); Decision d = new Decision(); d.Decision1 = "فتح الملف"; d.Id_plainte = p.IdPlainte; op.addDecisionPlainte(d); foreach (Par_plaignant item in listBox1.Items) { PlainteParPlaignant ppp = new PlainteParPlaignant(); ppp.IdParPlaignant = item.IdParPlaignant; ppp.IdPlainte = p.IdPlainte; op.addPlainteParPlaignant(ppp); } //save PJ setup if (u == 1) { foreach (string fileName in of.FileNames) { try { FileInfo fi = new FileInfo(fileName); PjPlainte pjplaint = new PjPlainte(); byte[] img = null; FileStream f = new FileStream(of.FileName, FileMode.Open); BinaryReader br = new BinaryReader(f); img = br.ReadBytes((int)f.Length); f.Close(); pjplaint.Id_plainte = p.IdPlainte; pjplaint.Photo = img; pjplaint.Titre = Path.GetFileName(of.FileName); pjplaint.Date_enregistrement = date_plai.Value; // pjOrder1.id_order = ord.id_order; op.addPjPalainte(pjplaint); history.AddHistory("شكاية", "اضافة", txb_num_pl.Text); } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } u = 0; } } else { MessageBox.Show("أحد الحقول فارغة أو المعلومات خاطئة"); } }