Create a json file , write Json data into it and Load the file into JsonDataAccess in bb 10 cascades - blackberry-10

I have this method call
QList<QByteArray> SocketBase::readAllSymb(QTcpSocket *socket) {
QList<QByteArray> listAll;
int bytesAvail = waitForInput(socket);
if (bytesAvail > 0) {
//int symbolCount = 0;
int cnt = 0;
bool endOfLine = false;
bool endOfStream = false;
while (cnt < bytesAvail && (!endOfLine) && (!endOfStream)) {
QByteArray ba="";
ba=socket->readAll();
listAll.append(ba);
if(ba.endsWith(']')){
endOfStream = true;
}
ba="";
}
}
return listAll;
}
now my Question is How to create a Dynamic file programatically and write data in to the file and load it like ....
JsonDataAccess jda;
QVariant list = jda.load(QDir::currentPath() +
"/app/native/assets/employees.json");

To save a QMap to a file:
QFile file("out.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Couldn't open file";
return;
}
JsonDataAccess jda;
jda.save(map, &file);

Related

Need to edit the code "user info" for sdk ZKTeco device fb100

I have this code working 100% but with one device zkt fb100,This code is for set user name ,card number , with id to the device to register it:
public int sta_SetUserInfo(ListBox lblOutputInfo, TextBox txtUserID, TextBox txtName, ComboBox cbPrivilege, TextBox txtCardnumber, TextBox txtPassword)
{
if (GetConnectState() == false)
{
lblOutputInfo.Items.Add("*Please connect first!");
return -1024;
}
if (txtUserID.Text.Trim() == "" || cbPrivilege.Text.Trim() == "")
{
lblOutputInfo.Items.Add("*Please input data first!");
return -1023;
}
int iPrivilege = cbPrivilege.SelectedIndex;
bool bFlag = false;
if (iPrivilege == 5)
{
lblOutputInfo.Items.Add("*User Defined Role is Error! Please Register again!");
return -1023;
}
/*
if(iPrivilege == 4)
{
axCZKEM1.IsUserDefRoleEnable(iMachineNumber, 4, out bFlag);
if (bFlag == false)
{
lblOutputInfo.Items.Add("*User Defined Role is unable!");
return -1023;
}
}
*/
//lblOutputInfo.Items.Add("[func IsUserDefRoleEnable]Temporarily unsupported");
int iPIN2Width = 0;
int iIsABCPinEnable = 0;
int iT9FunOn = 0;
string strTemp = "";
axCZKEM1.GetSysOption(GetMachineNumber(), "~PIN2Width", out strTemp);
iPIN2Width = Convert.ToInt32(strTemp);
axCZKEM1.GetSysOption(GetMachineNumber(), "~IsABCPinEnable", out strTemp);
iIsABCPinEnable = Convert.ToInt32(strTemp);
axCZKEM1.GetSysOption(GetMachineNumber(), "~T9FunOn", out strTemp);
iT9FunOn = Convert.ToInt32(strTemp);
/*
axCZKEM1.GetDeviceInfo(iMachineNumber, 76, ref iPIN2Width);
axCZKEM1.GetDeviceInfo(iMachineNumber, 77, ref iIsABCPinEnable);
axCZKEM1.GetDeviceInfo(iMachineNumber, 78, ref iT9FunOn);
*/
if (txtUserID.Text.Length > iPIN2Width)
{
lblOutputInfo.Items.Add("*User ID error! The max length is " + iPIN2Width.ToString());
return -1022;
}
if (iIsABCPinEnable == 0 || iT9FunOn == 0)
{
if (txtUserID.Text.Substring(0,1) == "0")
{
lblOutputInfo.Items.Add("*User ID error! The first letter can not be as 0");
return -1022;
}
foreach (char tempchar in txtUserID.Text.ToCharArray())
{
if (!(char.IsDigit(tempchar)))
{
lblOutputInfo.Items.Add("*User ID error! User ID only support digital");
return -1022;
}
}
}
int idwErrorCode = 0;
string sdwEnrollNumber = txtUserID.Text.Trim();
string sName = txtName.Text.Trim();
string sCardnumber = txtCardnumber.Text.Trim();
string sPassword = txtPassword.Text.Trim();
bool bEnabled = true;
/*if (iPrivilege == 4)
{
bEnabled = false;
iPrivilege = 0;
}
else
{
bEnabled = true;
}*/
axCZKEM1.EnableDevice(iMachineNumber, false);
axCZKEM1.SetStrCardNumber(sCardnumber);//Before you using function SetUserInfo,set the card number to make sure you can upload it to the device
if (axCZKEM1.SSR_SetUserInfo(iMachineNumber, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled))//upload the user's information(card number included)
{
lblOutputInfo.Items.Add("Set user information successfully");
}
else
{
axCZKEM1.GetLastError(ref idwErrorCode);
lblOutputInfo.Items.Add("*Operation failed,ErrorCode=" + idwErrorCode.ToString());
}
axCZKEM1.RefreshData(iMachineNumber);//the data in the device should be refreshed
axCZKEM1.EnableDevice(iMachineNumber, true);
return 1;
}
But if I have two device what should I change here ? .
I tried to change iMachineNumber to make first device is 1 and second device is 2 but not working too !
Finally I found the solution : in the button connect to device need to insert the above code in loop for one device and then next device and so on .

Need to update the Date format on my Google Mail Script

I'm creating a Gmail script that includes 5 variables, one of which is a due date. I just want it to populate as MM/DD/YYYY, however, it is currently populating as Thu Sep 13 2018 00:00:00 GMT-0400 (EDT).
Is there a way I can do that? I've pasted my code below for your reference. Any assistance is much appreciated.
function getRowsData(sheet, range, columnHeadersRowIndex) {
columnHeadersRowIndex = columnHeadersRowIndex || range.getRowIndex() - 1;
var numColumns = range.getEndColumn() - range.getColumn() + 1;
var headersRange = sheet.getRange(columnHeadersRowIndex, range.getColumn(), 1, numColumns);
var headers = headersRange.getValues()[0];
return getObjects(range.getValues(), normalizeHeaders(headers));
}
function getObjects(data, keys) {
var objects = [];
for (var i = 0; i < data.length; ++i) {
var object = {};
var hasData = false;
for (var j = 0; j < data[i].length; ++j) {
var cellData = data[i][j];
if (isCellEmpty(cellData)) {
continue;
}
object[keys[j]] = cellData;
hasData = true;
}
if (hasData) {
objects.push(object);
}
}
return objects;
}
function normalizeHeaders(headers) {
var keys = [];
for (var i = 0; i < headers.length; ++i) {
var key = normalizeHeader(headers[i]);
if (key.length > 0) {
keys.push(key);
}
}
return keys;
}
function normalizeHeader(header) {
var key = "";
var upperCase = false;
for (var i = 0; i < header.length; ++i) {
var letter = header[i];
if (letter == " " && key.length > 0) {
upperCase = true;
continue;
}
if (!isAlnum(letter)) {
continue;
}
if (key.length == 0 && isDigit(letter)) {
continue;
}
if (upperCase) {
upperCase = false;
key += letter.toUpperCase();
} else {
key += letter.toLowerCase();
}
}
return key;
}
function isCellEmpty(cellData) {
return typeof(cellData) == "string" && cellData == "";
}
function isAlnum(char) {
return char >= 'A' && char <= 'Z' ||
char >= 'a' && char <= 'z' ||
isDigit(char);
}
function isDigit(char) {
return char >= '0' && char <= '9';

inserting into SQL via sqlbulk

hallo i have this sniped code like this:
public static void Put_CSVtoSQL_Adhesion()
{
bool IsFirst = true;
DataTable dt = new DataTable();
string line = null;
int i = 0;
try
{
string fileName = Path.Combine(HttpContext.Current.Server.MapPath(UploadDirectory), TheFileName);
using (StreamReader sr = File.OpenText(fileName))
{
while ((line = sr.ReadLine()) != null)
{
string[] data = line.Split(';');
if (data.Length > 0)
{
if (i == 0)
{
foreach (var item in data)
{
dt.Columns.Add(new DataColumn());
}
i++;
}
DataRow row = dt.NewRow();
row.ItemArray = data;
// Pour enlever la tete
if (!IsFirst) dt.Rows.Add(row);
IsFirst = false;
}
}
}
using (var connectionWrapper = new Connexion())
{
var connectedConnection = connectionWrapper.GetConnected();
using (SqlBulkCopy copy = new SqlBulkCopy(connectionWrapper.conn))
{
int CountColl = dt.Columns.Count;
copy.ColumnMappings.Add(0, 1);
copy.ColumnMappings.Add(1, 2);
copy.ColumnMappings.Add(2, 3);
copy.ColumnMappings.Add(3, 4);
copy.ColumnMappings.Add(4, 5);
copy.DestinationTableName = "cotisation";
copy.WriteToServer(dt);
}
}
}
catch (Exception excThrown)
{
throw new Exception(excThrown.Message);
}
}
this code work well, but now i have more than 60 column, should i type manualy from 1 to 60 column or there are another methode ?
copy.ColumnMappings.Add(0, 1);
copy.ColumnMappings.Add(1, 2);
copy.ColumnMappings.Add(2, 3);
copy.ColumnMappings.Add(3, 4);
copy.ColumnMappings.Add(4, 5);
...until 60 column ?
the column is all the same i just shifted 1 column, because the first one is autoincremented column as an ID
Write a loop?
for (int i = 0; i < dt.Columns.Count - 1; i++)
{
copy.ColumnMappings.Add(i, i + 1);
}

E4X to JSON conversion fails for duplicate xml elements

Kindly see below code I am using to convert Mirth xml to JSON.
function E4XtoJSON(xml, ignored) {
var r, children = xml.*, attributes = xml.#*, length = children.length();
if(length == 0) {
r = xml.toString();
} else if(length == 1) {
var text = xml.text().toString();
if(text) {
r = text;
}
}
if(r == undefined) {
r = {};
for each (var child in children) {
var name = child.localName();
var json = E4XtoJSON(child, ignored);
var value = r[name];
if(value) {
if(value.length) {
value.push(json);
} else {
r[name] = [value, json]
}
} else {
r[name] = json;
}
}
}
if(attributes.length()) {
var a = {}, c = 0;
for each (var attribute in attributes) {
var name = attribute.localName();
if(ignored && ignored.indexOf(name) == -1) {
a["_" + name] = attribute.toString();
c ++;
}
}
if(c) {
if(r) a._ = r;
return a;
}
}
return r;
}
My concern is
<AdditionalMessageInformationCount AdditionalMessageInformationCount="02"><AdditionalMessageInformationQualifier>01</AdditionalMessageInformationQualifier><AdditionalMessageInformation>MEMBER MUST USE MAIL ORDER.</AdditionalMessageInformation><AdditionalMessageInformationQualifier>02</AdditionalMessageInformationQualifier><AdditionalMessageInformation>PLAN LIMITATIONS EXCEEDED</AdditionalMessageInformation></AdditionalMessageInformationCount>
Here AdditionalMessageInformation elemt is used two times so function fails to create JSON.
Kindly help if anyone have converted XML in json usingg javascript code not any API
We've had success with this version:
function E4XtoJSON(xml, ignored){
var r, children = xml.*,
attributes = xml.# * ,
length = children.length();
if (length == 0)
{
r = xml.toString();
}
else if (length == 1)
{
var text = xml.text().toString();
if (text)
{
r = text;
}
}
if (r == undefined)
{
r = {};
for each(var child in children)
{
var name = child.localName();
var json = E4XtoJSON(child, ignored);
var value = r[name];
if (value)
{
if (value instanceof Array)
{
value.push(json);
}
else
{
r[name] = [value, json]
}
}
else
{
r[name] = json;
}
}
}
if (attributes.length())
{
var a = {},
c = 0;
for each(var attribute in attributes)
{
var name = attribute.localName();
if (ignored && ignored.indexOf(name) == -1)
{
a["_" + name] = attribute.toString();
c++;
}
}
if (c)
{
if (r) a._ = r;
return a;
}
}
return r;
}
With the release of Mirth Connect version 3.3.0, you can use Mirth Connect to set your channel's interior data type to JSON. This will all be done for you.

How to read a word document in asp.net c#

i'm just workin on a project in asp.net c# 3.5 windows application which requires to read word document. i want to know how to read the *.doc file character by character.... how can i do it?
Microsoft.Office.Interop.Word.Application WApp;
Microsoft.Office.Interop.Word.Document Wdoc;
WApp = new Microsoft.Office.Interop.Word.Application();
//Opening Word file
Thread.Sleep(5312);
Wdoc = WApp.Documents.Open(#"C:\Users\Doc.doc");
object start = 0;
object end = Wdoc.Characters.Count;
Range rng = Wdoc.Range(ref start, ref end);
int wordCount = Wdoc.Words.Count;
// Display retrieved (incomplete) text
rng.TextRetrievalMode.IncludeHiddenText = false;
rng.TextRetrievalMode.IncludeFieldCodes = false;
// Find phrase in text string
string WTest;
string[] Title;
Title = new string[10];
Title[1] = "word1 ";
Title[2] = "word2 ";
Title[3] = "word3 ";
Title[4] = "word4 ";
Title[5] = "word5 ";
Title[6] = "word6 ";
Title[7] = "word7 ";
Title[8] = "word8 ";
Title[9] = "word9 ";
int icount = 1;
int n = 1;
int i=1;
while (icount <= wordCount)
{
WTest = Wdoc.Words[icount].Text.ToString();
foreach(string element in Title)
{
if (Title[i] == WTest)
{
Assert.IsTrue(true);
icount++;
i++;
break;
}
else if (i == wordCount)
{
Assert.Fail("Doc has no Data");
break;
}
else
{
icount++;
}
break;
}
continue;
}
Wdoc.Close(true);
WApp.Quit();
}