Ejemplo n.º 1
0
		/// <summary>
		/// Show Dialog to add new contact and return it.
		/// </summary>
		public Contact Show()
		{
			int respType = -1;
			string txtDesc = "", txtNumber = "";
			
			while (1==1)
			{
				SetupDialog();
				respType = ncDialogWidget.Exec();
				txtDesc = ncDialogWidget.Desc;
				txtNumber = ncDialogWidget.Number;
				ncDialogWidget.Close();
				ncDialogWidget.Dispose();
				
				if (respType != 1)
				{
					// Cancel button pressed
					return null;
				}

				// check data entry
				if (txtDesc == "" || txtNumber == "")
				{
					// send warning message
					MainClass.ShowMessage(mainWin, "ERROR", 
						                  GlobalObjUI.LMan.GetString("fieldsreq"), 
						                  MainClass.MessageType.Warning);
				}
				else if ((txtNumber.Length == 21) && 
					     (txtNumber.Substring(0,1) != "+"))
				{
					// number max len is 20 digits
					MainClass.ShowMessage(mainWin, "ERROR", 
						                  GlobalObjUI.LMan.GetString("maxnumlen"), 
						                  MainClass.MessageType.Warning);


				}
				else
				{
					// Data are correct
					Contact cnt = new Contact(txtDesc, txtNumber);
					return cnt;
				}
			}
				
				
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Prepare record to store contact on sim
		/// </summary>
		private static string PrepareRecord(Contact cnt, out string record)
		{
			string outNumber = "";
			int lenNumber = 0;
			string inNumber = cnt.PhoneNumber;			
			string digit = "";
			string tonNpi = "81";
			record = HexFromAscii(cnt.Description);
			record = record.PadRight(SimADNMaxAlphaChars*2, 'F');
			
			int tmpInt;
			
			if (inNumber.Substring(0,1) == "+")
			{
				// international number
				tonNpi = "91";
				inNumber = inNumber.Substring(1);
			}
			
			// check for phone number digits
			for(int p=0; p<inNumber.Length; p++)
			{
				digit = inNumber.Substring(p, 1);
				if (!int.TryParse(digit, out tmpInt) && digit != "*" && digit != "#")
				{
					log.Debug("GlobalObjUI::PrepareRecord: WRONG NUMBER " + cnt.PhoneNumber);
					return "WRONG NUMBER " + cnt.PhoneNumber;
				}
			}
			
			// Prepare Phone number
			if (inNumber.Length%2 != 0)
			{
				// add digit 
				inNumber += "F";
			}
			
			// len of numner + tonnpi byte
			lenNumber = (inNumber.Length/2) + 1;
			
			// loop for each byte
			for (int k=0; k<inNumber.Length; k +=2)
			{
				// swap digits in byte
				outNumber += inNumber.Substring(k+1,1) + inNumber.Substring(k,1);
			}
			
			outNumber = outNumber.Replace("*", "A");
			outNumber = outNumber.Replace("#", "B");
			outNumber = outNumber.PadRight(20, 'F');
			
			record += lenNumber.ToString("X2");
			record += tonNpi;
			record += outNumber;
			record += "FFFF";
			
			return "";
		}