public static Qustions EditSlider(Qustions Qustion) { try { using (SqlConnection Connection = new SqlConnection(DataBaseConnections.connectionString)) { Slider SliderForEdit = (Slider)Qustion; SqlCommand CommandForUpdateSlider = new SqlCommand(UpdateSlider, Connection); CommandForUpdateSlider.Parameters.AddWithValue(NewStartValue, SliderForEdit.StartValue); CommandForUpdateSlider.Parameters.AddWithValue(NewEndValue, SliderForEdit.EndValue); CommandForUpdateSlider.Parameters.AddWithValue(NewStartValueCaption, SliderForEdit.StartCaption); CommandForUpdateSlider.Parameters.AddWithValue(NewEndValueCaption, SliderForEdit.EndCaption); CommandForUpdateSlider.Parameters.AddWithValue(IdQuestion, SliderForEdit.Id); CommandForUpdateSlider.Connection.Open(); CommandForUpdateSlider.ExecuteNonQuery(); CommandForUpdateSlider.Parameters.Clear(); EditQuestion(SliderForEdit); return(SliderForEdit); } } catch (Exception ex) { StaticObjects.Erros.Log(ex); return(Qustion); } }
public static Qustions AddNewStar(Qustions Qustion) { Stars StarQuestion = (Stars)Qustion; int Id = AddQustionInDataBase(Qustion); if (Id != -1) { try { using (SqlConnection Connection = new SqlConnection(DataBaseConnections.connectionString)) { SqlCommand CommandForInsertStar = new SqlCommand(InsertInStar, Connection); CommandForInsertStar.Parameters.AddWithValue(NewNumberOfStars, StarQuestion.NumberOfStars); CommandForInsertStar.Parameters.AddWithValue(QustionIdDataBase, Id); CommandForInsertStar.Connection.Open(); CommandForInsertStar.ExecuteNonQuery(); CommandForInsertStar.Parameters.Clear(); StarQuestion.Id = Id; //StaticObjects.ListOfAllQuestion.Add(StarQuestion); StaticObjects.SuccOfFail = 1; return(StarQuestion); } } catch (Exception ex) { StaticObjects.Erros.Log(ex); StaticObjects.SuccOfFail = 0; return(StarQuestion); } } return(StarQuestion); }
public static Qustions AddNewSlider(Qustions Qustion) { Slider SliderQuestion = (Slider)Qustion; int Id = AddQustionInDataBase(SliderQuestion); if (Id != -1) { try { using (SqlConnection Connection = new SqlConnection(DataBaseConnections.connectionString)) { SqlCommand CommandForInsertSlider = new SqlCommand(InsertInSlider, Connection); CommandForInsertSlider.Parameters.AddWithValue(NewStartValue, SliderQuestion.StartValue); CommandForInsertSlider.Parameters.AddWithValue(NewEndValue, SliderQuestion.EndValue); CommandForInsertSlider.Parameters.AddWithValue(NewStartValueCaption, SliderQuestion.StartCaption); CommandForInsertSlider.Parameters.AddWithValue(NewEndValueCaption, SliderQuestion.EndCaption); CommandForInsertSlider.Parameters.AddWithValue(QustionIdDataBase, Id); SliderQuestion.Id = Id; CommandForInsertSlider.Connection.Open(); CommandForInsertSlider.ExecuteNonQuery(); StaticObjects.SuccOfFail = 1; return(SliderQuestion); } } catch (Exception ex) { StaticObjects.Erros.Log(ex); StaticObjects.SuccOfFail = 0; return(SliderQuestion); } } return(SliderQuestion); }
private void ListOfQuestion_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { QuestionWillDeleteOrEdit = GetObjectSelect(); if (QuestionWillDeleteOrEdit != null) { QuestionsInformation QuestionsInformationPage = new QuestionsInformation(QuestionWillDeleteOrEdit, Global.TypeOfChoice.Edit.ToString()); QuestionsInformationPage.ShowDialog(); if (StaticObjects.SuccOfFail == 1) { ListOfAllQuestion = Operation.GetQustion(); ShowData(); StaticObjects.SuccOfFail = 0; } } else { MessageBox.Show(Survey.Properties.Resource1.NoSelectItem, Global.Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { StaticObjects.Erros.Log(ex); MessageBox.Show(Survey.Properties.Resource1.MessageError); } }
/// <summary> /// This Listener for delete button when press add button /// </summary> private void Delete_Click(object sender, EventArgs e) { try { QuestionWillDeleteOrEdit = GetObjectSelect(); int Check = 0; if (QuestionWillDeleteOrEdit == null) { MessageBox.Show(Survey.Properties.Resource1.NoSelectItem, Global.Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); StaticObjects.SuccOfFail = 0; } else { DialogResult dialogResult = MessageBox.Show(Survey.Properties.Resource1.SureToDeleteMessage, Global.Constant.DELETE, MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (QuestionWillDeleteOrEdit.TypeOfQuestion == Global.TypeOfQuestion.Slider.ToString()) { Slider SliderWillDelete = (Slider)QuestionWillDeleteOrEdit; Check = Operation.DeleteQustion(SliderWillDelete); ListOfAllQuestion.Remove(SliderWillDelete); } else if (QuestionWillDeleteOrEdit.TypeOfQuestion == Global.TypeOfQuestion.Smily.ToString()) { Smiles SmileWillDelete = (Smiles)QuestionWillDeleteOrEdit; Check = Operation.DeleteQustion(SmileWillDelete); ListOfAllQuestion.Remove(SmileWillDelete); } else if (QuestionWillDeleteOrEdit.TypeOfQuestion == Global.TypeOfQuestion.Stars.ToString()) { Stars StarWillDelete = (Stars)QuestionWillDeleteOrEdit; Check = Operation.DeleteQustion(StarWillDelete); ListOfAllQuestion.Remove(StarWillDelete); } if (Check == 1) { MessageBox.Show(Survey.Properties.Resource1.TheQuestionDeleted); ShowData(); StaticObjects.SuccOfFail = 1; } else { MessageBox.Show(Survey.Properties.Resource1.TheQuestionNotDeleted); } } } } catch (Exception ex) { StaticObjects.Erros.Log(ex); StaticObjects.SuccOfFail = 0; MessageBox.Show(Survey.Properties.Resource1.MessageError); } }
/// <summary> /// This constructor for hide and if i choose edit will show the variable for types of question /// </summary> public QuestionsInformation(Qustions QuestionWillDeleteOrEdit, string AddOrEdit) { InitializeComponent(); InitHide(); this.QuestionWillDeleteOrEdit = QuestionWillDeleteOrEdit; NewText.Focus(); AddOrEdirChoice = AddOrEdit; try { if (TypeOfChoice.Edit.ToString() == AddOrEdit) { this.Text = Survey.Properties.Resource1.TitleOfQuestionEdit; GroupOfTypes.Visible = false; ShowDataForEdit(); if (QuestionWillDeleteOrEdit != null) { if (TypeOfQuestion.Slider.ToString() == QuestionWillDeleteOrEdit.TypeOfQuestion) { ShowForSlider(); } else if (TypeOfQuestion.Smily.ToString() == QuestionWillDeleteOrEdit.TypeOfQuestion) { ShowForSmiles(); } else if (TypeOfQuestion.Stars.ToString() == QuestionWillDeleteOrEdit.TypeOfQuestion) { ShowForStars(); } } } else if (TypeOfChoice.Add.ToString() == AddOrEdit) { this.Text = Survey.Properties.Resource1.TitleOfQuestionAdd; GroupOfTypes.Visible = true; InitHide(); } } catch (Exception ex) { StaticObjects.Erros.Log(ex); MessageBox.Show(Survey.Properties.Resource1.MessageError); } }
/// <summary> /// For Edit Question retrun object after edited /// </summary> private static void EditQuestion(Qustions Question) { try { using (SqlConnection Connection = new SqlConnection(DataBaseConnections.connectionString)) { SqlCommand CommandForUpdateQustion = new SqlCommand(UpdateQuestion, Connection); CommandForUpdateQustion.Parameters.AddWithValue(NewQuestionText, Question.NewText); CommandForUpdateQustion.Parameters.AddWithValue(NewQuestionOrder, Question.Order); CommandForUpdateQustion.Parameters.AddWithValue(IdQuestion, Question.Id); CommandForUpdateQustion.Connection.Open(); CommandForUpdateQustion.ExecuteNonQuery(); CommandForUpdateQustion.Parameters.Clear(); } } catch (Exception ex) { StaticObjects.Erros.Log(ex); } }
public static int DeleteStar(Qustions Question) { try { using (SqlConnection Connection = new SqlConnection(DataBaseConnections.connectionString)) { Stars QustionWillDeleteStar = (Stars)Question; SqlCommand CommandForDeleteQustion = null; CommandForDeleteQustion = new SqlCommand(DeleteStarString, Connection); CommandForDeleteQustion.Parameters.AddWithValue(IdQuestionWithAt, QustionWillDeleteStar.IdForType); CommandForDeleteQustion.Connection.Open(); CommandForDeleteQustion.ExecuteNonQuery(); CommandForDeleteQustion.Parameters.Clear(); DeleteQustion(Question.Id); return(1); } }catch (Exception ex) { StaticObjects.Erros.Log(ex); return(0); } }
public static Qustions EditStar(Qustions Qustion) { try { Stars StarForEdit = (Stars)Qustion; using (SqlConnection Connection = new SqlConnection(DataBaseConnections.connectionString)) { SqlCommand CommandForUpdateStar = new SqlCommand(UpdateStar, Connection); CommandForUpdateStar.Parameters.AddWithValue(NewNumberOfStars, StarForEdit.NumberOfStars); CommandForUpdateStar.Parameters.AddWithValue(IdQuestion, StarForEdit.Id); CommandForUpdateStar.Connection.Open(); CommandForUpdateStar.ExecuteNonQuery(); CommandForUpdateStar.Parameters.Clear(); EditQuestion(StarForEdit); return(StarForEdit); } } catch (Exception ex) { StaticObjects.Erros.Log(ex); return(Qustion); } }
public static int DeleteQustion(Qustions Question) { try { if (Question is Slider) { return(DataBaseConnections.DeleteSlider(Question)); } else if (Question is Smiles) { return(DataBaseConnections.DeleteSmile(Question)); } else { return(DataBaseConnections.DeleteStar(Question)); } } catch (Exception ex) { StaticObjects.Erros.Log(ex); StaticObjects.SuccOfFail = 0; return(0); } }
public static Qustions EditQustion(Qustions Question) { try { if (Question is Slider) { return(DataBaseConnections.EditSlider(Question)); } else if (Question is Smiles) { return(DataBaseConnections.EditSmile(Question)); } else { return(DataBaseConnections.EditStar(Question)); } } catch (Exception ex) { StaticObjects.Erros.Log(ex); StaticObjects.SuccOfFail = 0; return(null); } }
/// <summary> /// This functions for add or edit and delete and select from database, /// And connections in database /// </summary> /// <summary> /// For Add Qustion return new OBJECT OF QUESTION /// </summary> private static int AddQustionInDataBase(Qustions Question) { int Id = -1; try { using (SqlConnection Connection = new SqlConnection(DataBaseConnections.connectionString)) { SqlCommand ComandForInsertQustion = new SqlCommand(InsertIntoQustion, Connection); ComandForInsertQustion.CommandText = InsertIntoQustion; ComandForInsertQustion.Parameters.AddWithValue(NewQuestionText, Question.NewText); ComandForInsertQustion.Parameters.AddWithValue(NewQuestionType, Question.TypeOfQuestion); ComandForInsertQustion.Parameters.AddWithValue(NewQuestionOrder, Question.Order); ComandForInsertQustion.Connection.Open(); ComandForInsertQustion.ExecuteNonQuery(); } using (SqlConnection Connection = new SqlConnection(DataBaseConnections.connectionString)) { SqlCommand CommandForSelectMaxForQuestion = new SqlCommand(ProcdureQuestionSelectForMax, Connection); CommandForSelectMaxForQuestion.Connection.Open(); SqlDataReader Reader = CommandForSelectMaxForQuestion.ExecuteReader(); while (Reader.Read()) { Id = Convert.ToInt32(Reader[IdQuestion]); } Reader.Close(); } } catch (Exception ex) { StaticObjects.Erros.Log(ex); StaticObjects.SuccOfFail = 0; return(Id); } return(Id); }
/// <summary> /// when i press save button go to this function and from AddOrEdit var will know i edit or add the question /// </summary> private void Save_Click(object sender, EventArgs e) { try { if (AddOrEdirChoice == TypeOfChoice.Add.ToString()) { if (SliderRadio.Checked) { Slider NewQuestion = new Slider(); NewQuestion.NewText = NewText.Text; NewQuestion.Order = Convert.ToInt32(NewOrder.Value); NewQuestion.TypeOfQuestion = TypeOfQuestion.Slider.ToString(); NewQuestion.StartValue = Convert.ToInt32(NewStartValue.Text); NewQuestion.EndValue = Convert.ToInt32(NewEndValue.Text); NewQuestion.StartCaption = NewStartValueCaption.Text; NewQuestion.EndCaption = NewEndValueCaption.Text; if (CheckTheData(NewQuestion)) { ReturnNewQuestion = (Slider)Operation.AddQustion(NewQuestion); if (StaticObjects.SuccOfFail == 1) { DataEnter(); } } } else if (SmilyRadio.Checked) { Smiles NewQuestion = new Smiles(); NewQuestion.NewText = NewText.Text; NewQuestion.Order = Convert.ToInt32(NewOrder.Value); NewQuestion.TypeOfQuestion = TypeOfQuestion.Smily.ToString(); NewQuestion.NumberOfSmiles = Convert.ToInt32(NewNumberOfSmiles.Text); if (CheckTheData(NewQuestion)) { ReturnNewQuestion = (Smiles)Operation.AddQustion(NewQuestion); if (StaticObjects.SuccOfFail == 1) { DataEnter(); } } } else if (StarsRadio.Checked) { Stars NewQuestion = new Stars(); NewQuestion.NewText = NewText.Text; NewQuestion.Order = Convert.ToInt32(NewOrder.Value); NewQuestion.TypeOfQuestion = TypeOfQuestion.Stars.ToString(); NewQuestion.NumberOfStars = Convert.ToInt32(NewNumberOfStars.Text); if (CheckTheData(NewQuestion)) { ReturnNewQuestion = (Stars)Operation.AddQustion(NewQuestion); if (StaticObjects.SuccOfFail == 1) { DataEnter(); } } } else { MessageBox.Show(Survey.Properties.Resource1.NotChooseTheType, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }catch (Exception ex) { StaticObjects.Erros.Log(ex); MessageBox.Show(Survey.Properties.Resource1.MessageError); } try { if (AddOrEdirChoice == TypeOfChoice.Edit.ToString()) { if (SliderForEdit != null) { SliderForEdit.NewText = NewText.Text; SliderForEdit.Order = Convert.ToInt32(NewOrder.Value); SliderForEdit.StartValue = Convert.ToInt32(NewStartValue.Value); SliderForEdit.EndValue = Convert.ToInt32(NewEndValue.Value); SliderForEdit.StartCaption = NewStartValueCaption.Text; SliderForEdit.EndCaption = NewEndValueCaption.Text; if (CheckTheData(SliderForEdit)) { ReturnNewQuestion = (Slider)Operation.EditQustion(SliderForEdit); MessageBox.Show(Properties.Resource1.TheEditMessage); StaticObjects.SuccOfFail = 1; this.Close(); } } else if (SmileForEdit != null) { SmileForEdit.NewText = NewText.Text; SmileForEdit.Order = Convert.ToInt32(NewOrder.Value); SmileForEdit.NumberOfSmiles = Convert.ToInt32(NewNumberOfSmiles.Value); if (CheckTheData(SmileForEdit)) { ReturnNewQuestion = (Smiles)Operation.EditQustion(SmileForEdit); MessageBox.Show(Properties.Resource1.TheEditMessage); StaticObjects.SuccOfFail = 1; this.Close(); } } else if (StarForEdit != null) { StarForEdit.NewText = NewText.Text; StarForEdit.Order = Convert.ToInt32(NewOrder.Value); StarForEdit.NumberOfStars = Convert.ToInt32(NewNumberOfStars.Value); if (CheckTheData(StarForEdit)) { ReturnNewQuestion = (Stars)Operation.EditQustion(StarForEdit); MessageBox.Show(Properties.Resource1.TheEditMessage); StaticObjects.SuccOfFail = 1; this.Close(); } } } } catch (Exception ex) { StaticObjects.Erros.Log(ex); MessageBox.Show(Survey.Properties.Resource1.MessageError); } }
/// <summary> /// This Function to Check validation of data /// </summary> private bool CheckTheData(Qustions TypeQuestion) { try { if (TypeQuestion.NewText == Constant.Empty) { MessageBox.Show(Survey.Properties.Resource1.QuestionIsEmptyMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error);; return(false); } else if (IsNumber(TypeQuestion.NewText)) { MessageBox.Show(Survey.Properties.Resource1.QuestionIsJustANumberMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (TypeQuestion.Order <= 0) { MessageBox.Show(Survey.Properties.Resource1.NewOrderLessThanZeroMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (TypeQuestion is Slider) { Slider SliderCheck = (Slider)TypeQuestion; if (SliderCheck.StartValue <= 0) { MessageBox.Show(Survey.Properties.Resource1.StartValueLessThanZeroMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (SliderCheck.EndValue <= 0) { MessageBox.Show(Survey.Properties.Resource1.EndValueLessThanZeroMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (SliderCheck.StartValue > 100) { MessageBox.Show(Survey.Properties.Resource1.StartValueGreaterThanOneHundredMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (SliderCheck.EndValue > 100) { MessageBox.Show(Survey.Properties.Resource1.EndValueGreaterThanOneHundredMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (SliderCheck.StartValue >= SliderCheck.EndValue) { MessageBox.Show(Survey.Properties.Resource1.TheEndValueSholudGreaterThanStartValueMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (SliderCheck.StartCaption == Constant.Empty) { MessageBox.Show(Survey.Properties.Resource1.StartCaptionEmptyMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (IsNumber(SliderCheck.StartCaption)) { MessageBox.Show(Survey.Properties.Resource1.StartCaptionJustNumberMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (SliderCheck.EndCaption == Constant.Empty) { MessageBox.Show(Survey.Properties.Resource1.EndCaptionEmptyMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (IsNumber(SliderCheck.EndCaption)) { MessageBox.Show(Survey.Properties.Resource1.EndCaptionJustNumberMessage, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else if (TypeQuestion is Smiles) { Smiles SmilesCheck = (Smiles)TypeQuestion; if (SmilesCheck.NumberOfSmiles <= 1 || SmilesCheck.NumberOfSmiles > 5) { MessageBox.Show(Survey.Properties.Resource1.NumberOfSmileBetweenFiveAndTow, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else if (TypeQuestion is Stars) { Stars StarCheck = (Stars)TypeQuestion; if (StarCheck.NumberOfStars <= 0 || StarCheck.NumberOfStars > 10) { MessageBox.Show(Survey.Properties.Resource1.NumberOfStrasBetweenTenAndOne, Constant.ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } } catch (Exception ex) { StaticObjects.Erros.Log(ex); MessageBox.Show(Survey.Properties.Resource1.MessageError); return(false); } return(true); }