private void AnswerClick(object sender, EventArgs e) { if (this.SelectedQuations.Count > 0) { Button btn = sender as Button; string answer = btn.Text; if (this.SelectedQuations[Index].Answer == answer) { btn.BackColor = Color.LawnGreen; this.lblResponse.ForeColor = Color.Green; this.lblResponse.Text = "Cavab Doğrudur"; lblResponse.Left = (grp_answers.Width / 2) - (lblResponse.Width / 2); this.lblCorretCount.Text = (++this.CorrectCount).ToString(); if (cmbIncorrectQuations.SelectedIndex != -1) { string val = (cmbIncorrectQuations.SelectedItem as ComboboxItem).Value.ToString(); this.IncorrectQuations.Remove(this.IncorrectQuations.First(q => q.Value.ToString() == val)); } fillCmbIncorrect(); } else { btn.BackColor = Color.Red; lblResponse.ForeColor = Color.Red; lblResponse.Text = "Cavab Səhvdir"; lblResponse.Left = (grp_answers.Width / 2) - (lblResponse.Width / 2); Quation quat = this.SelectedQuations[Index]; string value = quat.Id.ToString(); List <Quation> _quations = this.Quations.Where(q => q.Category_id == quat.Category_id).ToList(); int number = (_quations.IndexOf(quat) + 1); ComboboxItem item = new ComboboxItem { Text = number.ToString(), Value = value }; if (!this.IncorrectQuations.Any(q => (string)q.Value == value)) { this.IncorrectQuations.Add(item); } fillCmbIncorrect(); } foreach (Button button in this.grpAnswers.Controls) { if (button.Text == this.SelectedQuations[Index].Answer) { button.BackColor = Color.LawnGreen; } button.Enabled = false; } } }
public void update(int ticketId) { this.TicketId = ticketId; this.btnSave.Visible = false; this.btnUpdate.Visible = true; using (SQLiteConnection con = new SQLiteConnection(Login.connection)) { con.Open(); string sql = "SELECT * FROM Tickets WHERE id = " + ticketId; SQLiteCommand com = new SQLiteCommand(sql, con); SQLiteDataAdapter da = new SQLiteDataAdapter(); DataTable dt = new DataTable(); da.SelectCommand = com; da.Fill(dt); this.txtTicketName.Text = dt.Rows[0]["name"].ToString(); } using (SQLiteConnection con = new SQLiteConnection(Login.connection)) { con.Open(); string sql = "SELECT * FROM P_TicketAndQuation WHERE ticket_id = " + ticketId; SQLiteCommand com = new SQLiteCommand(sql, con); SQLiteDataAdapter da = new SQLiteDataAdapter(); DataTable dt = new DataTable(); da.SelectCommand = com; da.Fill(dt); int c_index = 0; int p_index = 0; foreach (Control ctrl in this.grpMain.Controls) { if (ctrl is GroupBox) { foreach (Control cmb in ctrl.Controls) { if (cmb is ComboBox) { ComboBox combo = cmb as ComboBox; if (combo.Name.Contains("Category")) { combo.TextChanged -= Cmb_SelectedIndexChanged; int id = Convert.ToInt32(dt.Rows[c_index]["quation_id"]); int cat_id = this.quations.FirstOrDefault(q => q.Id == id).Category_id; foreach (ComboboxItem item in combo.Items) { if (cat_id == Convert.ToInt32(item.Value)) { combo.SelectedItem = item; } } c_index++; } } } foreach (Control panel in ctrl.Controls) { if (panel is ComboBox) { ComboBox cmb = panel as ComboBox; if (cmb.Name.Contains("quation")) { int id = Convert.ToInt32(dt.Rows[p_index]["quation_id"]); Quation selected = quations.FirstOrDefault(q => q.Id == id); cmb.Parent.Name = "selected-" + id; foreach (var item in cmb.Items) { ComboboxItem comboboxItem = item as ComboboxItem; if (comboboxItem.Value.ToString() == id.ToString()) { cmb.SelectedItem = item; } } p_index++; } } } } } } }
public void update(int ticketId) { this.TicketId = ticketId; this.btnSave.Visible = false; this.btnUpdate.Visible = true; using (SQLiteConnection con = new SQLiteConnection(Login.connection)) { con.Open(); string sql = "SELECT * FROM Tickets WHERE id = " + ticketId; SQLiteCommand com = new SQLiteCommand(sql, con); SQLiteDataAdapter da = new SQLiteDataAdapter(); DataTable dt = new DataTable(); da.SelectCommand = com; da.Fill(dt); this.txtTicketName.Text = dt.Rows[0]["name"].ToString(); } using (SQLiteConnection con = new SQLiteConnection(Login.connection)) { con.Open(); string sql = "SELECT * FROM P_TicketAndQuation WHERE ticket_id = " + ticketId; SQLiteCommand com = new SQLiteCommand(sql, con); SQLiteDataAdapter da = new SQLiteDataAdapter(); DataTable dt = new DataTable(); da.SelectCommand = com; da.Fill(dt); int c_index = 0; int p_index = 0; foreach (Control ctrl in this.grpMain.Controls) { if (ctrl is GroupBox) { foreach (Control cmb in ctrl.Controls) { if (cmb is ComboBox) { ComboBox combo = cmb as ComboBox; combo.TextChanged -= Cmb_SelectedIndexChanged; int id = Convert.ToInt32(dt.Rows[c_index]["quation_id"]); int cat_id = this.quations.FirstOrDefault(q => q.Id == id).Category_id; foreach (ComboboxItem item in combo.Items) { { if (cat_id == Convert.ToInt32(item.Value)) { combo.SelectedItem = item; } } } c_index++; } } foreach (Control panel in ctrl.Controls) { if (panel is Panel) { int id = Convert.ToInt32(dt.Rows[p_index]["quation_id"]); Quation selected = quations.FirstOrDefault(q => q.Id == id); Panel pnl = panel as Panel; pnl.Parent.Name = "selected-" + id; pnl.Controls.Clear(); Button btn = new Button(); btn.Width = pnl.Width - 18; btn.Height = pnl.Height; btn.FlatStyle = FlatStyle.Flat; btn.BackgroundImageLayout = ImageLayout.Stretch; using (FileStream s = new FileStream(Extentions.GetPath() + "\\Quations_Images\\" + selected.Image, FileMode.Open)) { btn.BackgroundImage = Image.FromStream(s); } pnl.Controls.Add(btn); btn.Click += Btn_Click; btn.Name = id.ToString(); p_index++; } } } } } }