Example #1
0
		public int saveData (QuizDB item) 
		{
			lock (locker) 
			{
				return Insert (item);
			}
		}
Example #2
0
		public static int updateDrawNoEventID (QuizDB quiz)
		{
			int stat = -1;

//			stat = me.db.updateData (quiz);
//			Console.Error.WriteLine ("stat"+stat);
//			if (stat == 1) {
//				Console.Error.WriteLine ("Success update IC No.: " + quiz.ic_No + " Draw No: "+quiz.luckyDraw_no+" event ID: "+quiz.event_id);
//			} else {
//				Console.Error.WriteLine ("Failed update IC No.: " + quiz.ic_No + " Draw No: "+quiz.luckyDraw_no+" event ID: "+quiz.event_id);
//			}

			return stat;
		}
Example #3
0
		public static int saveData (QuizDB quiz)
		{
			int stat = -1;

			stat = me.db.saveData (quiz);

			if (stat == 1) {
				Console.Error.WriteLine ("Success saved IC No.: " + quiz.ic_No);
			} else {
				Console.Error.WriteLine ("Failed saved IC No.: " + quiz.ic_No);
			}

			return stat;
		}
		private async void ClickFunction()
		{
			//get imei
			var telephonyManager = (TelephonyManager) GetSystemService(TelephonyService);
			string imei = telephonyManager.DeviceId;

			//if no imei use androidid
			if (String.IsNullOrEmpty (imei)) {
				imei = Settings.Secure.GetString (ContentResolver,Settings.Secure.AndroidId);
			}

			Console.Error.WriteLine ("imei:"+imei);

			//if imei not empty proceed
			if (!String.IsNullOrEmpty (imei)) {
				try {	
					var json_validateEventCode = await Task.Factory.StartNew (() => Webservice.ws_validateEventCode (et_eventCode.Text, imei, uid));
					Webservice.validateEventCode data = JsonConvert.DeserializeObject<Webservice.validateEventCode> (json_validateEventCode);

					//hide loading and show send button
					pb.Visibility = ViewStates.Invisible;
					btn_send.Visibility = ViewStates.Visible;

					if (data.success == 1) {

						//disable button to prevent double click
						RunOnUiThread (() => {
							btn_send.Enabled = false;
						});

						//database save quizdata
						QuizDB quizDB = new QuizDB ();
						quizDB.completion_Stat = 0;
						quizDB.event_Code = event_code;
						quizDB.user_id = uid;
						quizDB.event_Id = data.event_id;

						try {
							DB_access.saveData (quizDB);
						} catch {

						}

						//loop and store question and answer into list
						foreach (var temp in data.quizs) {
							if (temp.answer == 0) {
								QuestionAnswer.answerList.Add (false);
							} else {
								QuestionAnswer.answerList.Add (true);
							}
							QuestionAnswer.questionList.Add (temp.question);
						}

						//bundle to be sent for question fragment 
						Bundle msg = new Bundle ();
						msg.PutInt ("currentQuestion", 1);
						msg.PutBoolean ("anwser", QuestionAnswer.answerList [0]);
						msg.PutString ("user_id", uid);
						msg.PutInt ("event_id", data.event_id);
						msg.PutString ("imei", imei);

						FragmentTransaction transaction = FragmentManager.BeginTransaction ();
						dialog_Signup signUpDialog = new dialog_Signup ();
						signUpDialog.Arguments = msg;
						signUpDialog.Cancelable = false;
						signUpDialog.Show (transaction, "dialog fragment");
					
					} else if (data.success == 0) {

						Snackbar snackbar = Snackbar
						.Make (btn_send, "Kod penyertaan salah. Sila semak semula.", Snackbar.LengthLong)
						.SetAction ("OK", delegate {
						});

						View snackbarView = snackbar.View;
						TextView tv = (TextView)snackbarView.FindViewById (Resource.Id.snackbar_text);
						tv.SetTextColor (Color.White);

						snackbar.Show ();

					} else if (data.success == 3) {
						AlertDialog.Builder alert = new AlertDialog.Builder (this);

						alert.SetTitle ("Quiz telah ditutup!");
						alert.SetCancelable (false);
						alert.SetPositiveButton ("OK", (senderAlert, args) => {
							Finish ();
						});

						RunOnUiThread (() => {
							alert.Show ();
						});
					} else if (data.success == 2) {
						Snackbar snackbar = Snackbar
						.Make (btn_send, "Hanya satu penyertaan bagi setiap akaun/gajet", Snackbar.LengthLong)
						.SetAction ("OK", delegate {
						});

						View snackbarView = snackbar.View;
						TextView tv = (TextView)snackbarView.FindViewById (Resource.Id.snackbar_text);
						tv.SetTextColor (Color.White);

						snackbar.Show ();
					}
				} catch (Exception ex) {
					Console.Error.WriteLine ("ex" + ex);
					AlertDialog.Builder alert = new AlertDialog.Builder (this);

					alert.SetTitle ("Ralat! Sila cuba sebentar lagi. ");
					alert.SetCancelable (false);
					alert.SetPositiveButton ("OK", (senderAlert, args) => {
					});

					RunOnUiThread (() => {
						alert.Show ();
					});

					//hide loading and show send button
					pb.Visibility = ViewStates.Invisible;
					btn_send.Visibility = ViewStates.Visible;
				}
			} else {
				//if no imei/android,cannot proceed 
				Snackbar snackbar = Snackbar
					.Make (btn_send, "Ralat! Gajet anda tiada imei/androidid", Snackbar.LengthLong)
					.SetAction ("OK", delegate {
					});

				View snackbarView = snackbar.View;
				TextView tv = (TextView)snackbarView.FindViewById (Resource.Id.snackbar_text);
				tv.SetTextColor (Color.White);

				snackbar.Show ();
			}
		}