コード例 #1
0
 protected void SetData(DataSet ds)
 {
     if (ds.Tables.Count > 0)
     {
         try
         {
             JsonDataSet.SetDebugMode(DEBUG, Response);
             if (serverResponse.Data == null)
             {
                 if (DEBUG)
                 {
                     Response.Write(" SetData <br>");
                 }
                 serverResponse.Data = new JsonDataSet(ds);
             }
             else
             {
                 if (DEBUG)
                 {
                     Response.Write(" MergeDataSet <br>");
                 }
                 serverResponse.Data.MergeDataSet(new JsonDataSet(ds));
             }
         }
         catch (Exception err)
         {
             Response.Write("Error setting data<br>");
             OutputException(err);
         }
     }
 }
コード例 #2
0
 public void MergeDataSet(JsonDataSet jds)
 {
     if (string.IsNullOrEmpty(DataSetName))
     {
         DataSetName = jds.DataSetName;
     }
     if (Locale == 0)
     {
         Locale = jds.Locale;
     }
     if (Tables == null)
     {
         Tables = jds.Tables;
     }
     else
     {
         if (jds.Tables != null && jds.Tables.Length > 0)
         {
             for (int i = 0; i < jds.Tables.Length; i++)
             {
                 bool found = false;
                 for (int j = 0; j < Tables.Length; j++)
                 {
                     if (string.Compare(jds.Tables[i].TableName, Tables[j].TableName, StringComparison.OrdinalIgnoreCase) == 0)
                     {
                         found = true;
                         break;
                     }
                 }
                 if (!found)
                 {
                     int             n    = Tables.Length;
                     JsonDataTable[] newT = new JsonDataTable[n + 1];
                     if (n > 0)
                     {
                         Tables.CopyTo(newT, 0);
                     }
                     newT[n] = jds.Tables[i];
                     Tables  = newT;
                 }
             }
         }
     }
 }
コード例 #3
0
 public void FromJsonText(string jsonText)
 {
     Calls = new RequestCommand[] { };
     Data  = null;
     if (!string.IsNullOrEmpty(jsonText))
     {
         JavaScriptSerializer js = new JavaScriptSerializer();
         IJsonObject          jo = Json.StringToJson(jsonText);
         if (jo != null)
         {
             JsonDataPropertyBag prb = jo as JsonDataPropertyBag;
             if (prb != null)
             {
                 IJsonValue jv;
                 if (prb.TryGetValue("Calls", out jv))
                 {
                     JsonDataArray callsX = jv as JsonDataArray;
                     if (callsX != null)
                     {
                         if (callsX.Count > 0)
                         {
                             Calls = new RequestCommand[callsX.Count];
                             for (int i = 0; i < callsX.Count; i++)
                             {
                                 Calls[i] = new RequestCommand();
                                 JsonDataPropertyBag pb = callsX[i] as JsonDataPropertyBag;
                                 if (pb != null)
                                 {
                                     if (pb.TryGetValue("method", out jv))
                                     {
                                         JsonDataString sv = jv as JsonDataString;
                                         if (sv != null)
                                         {
                                             Calls[i].method = sv.ValueString;
                                         }
                                     }
                                     if (pb.TryGetValue("value", out jv))
                                     {
                                         JsonDataString sv = jv as JsonDataString;
                                         if (sv != null)
                                         {
                                             Calls[i].value = sv.ValueString;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 JsonDataArray clientData;
                 IJsonValue    jvalue;
                 if (prb.TryGetValue("values", out jvalue))
                 {
                     values = jvalue as JsonDataPropertyBag;
                 }
                 if (prb.TryGetValue("Data", out jvalue))
                 {
                     clientData = jvalue as JsonDataArray;
                     if (clientData != null)
                     {
                         Data        = new JsonDataSet();
                         Data.Tables = new JsonDataTable[clientData.Count];
                         for (int i = 0; i < clientData.Count; i++)
                         {
                             JsonDataTableUpdate tbl = new JsonDataTableUpdate();
                             Data.Tables[i] = tbl;
                             if (clientData[i] != null)
                             {
                                 JsonDataPropertyBag pb = clientData[i] as JsonDataPropertyBag;
                                 if (pb != null)
                                 {
                                     JsonDataArray rows;
                                     if (pb.TryGetValue("TableName", out jv))
                                     {
                                         JsonDataString name = jv as JsonDataString;
                                         Data.Tables[i].TableName = name.ValueString;
                                     }
                                     if (pb.TryGetValue("Columns", out jv))
                                     {
                                         JsonDataArray pbc = jv as JsonDataArray;
                                         if (pbc != null && pbc.Count > 0)
                                         {
                                             Data.Tables[i].Columns = new JsonDataColumn[pbc.Count];
                                             for (int c = 0; c < pbc.Count; c++)
                                             {
                                                 Data.Tables[i].Columns[c] = new JsonDataColumn();
                                                 JsonDataPropertyBag jsc = pbc[c] as JsonDataPropertyBag;
                                                 if (jsc != null)
                                                 {
                                                     if (jsc.TryGetValue("Name", out jv))
                                                     {
                                                         JsonDataString jds = jv as JsonDataString;
                                                         if (jds != null)
                                                         {
                                                             Data.Tables[i].Columns[c].Name = jds.ValueString;
                                                         }
                                                     }
                                                     if (jsc.TryGetValue("ReadOnly", out jv))
                                                     {
                                                         JsonDataBool jdb = jv as JsonDataBool;
                                                         if (jdb != null)
                                                         {
                                                             Data.Tables[i].Columns[c].ReadOnly = jdb.ValueBool;
                                                         }
                                                     }
                                                     if (jsc.TryGetValue("Type", out jv))
                                                     {
                                                         JsonDataString jds = jv as JsonDataString;
                                                         if (jds != null)
                                                         {
                                                             Data.Tables[i].Columns[c].Type = jds.ValueString;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                     if (pb.TryGetValue("PrimaryKey", out jv))
                                     {
                                         JsonDataArray pbc = jv as JsonDataArray;
                                         if (pbc != null && pbc.Count > 0)
                                         {
                                             Data.Tables[i].PrimaryKey = new string[pbc.Count];
                                             for (int c = 0; c < pbc.Count; c++)
                                             {
                                                 Data.Tables[i].PrimaryKey[c] = pbc[c].ToString();
                                             }
                                         }
                                     }
                                     if (pb.TryGetValue("rowIndex", out jv))
                                     {
                                         JsonDataNumber jn = jv as JsonDataNumber;
                                         if (jn != null)
                                         {
                                             tbl.RowIndex = jn.ValueNumber;
                                         }
                                     }
                                     if (pb.TryGetValue("Rows", out jv))
                                     {
                                         rows = jv as JsonDataArray;
                                         if (rows != null)
                                         {
                                             Data.Tables[i].Rows = new JsonDataRow[rows.Count];
                                             for (int m = 0; m < rows.Count; m++)
                                             {
                                                 JsonDataPropertyBag r = rows[m] as JsonDataPropertyBag;
                                                 if (r != null)
                                                 {
                                                     JsonDataRowUpdate jdr = new JsonDataRowUpdate();
                                                     Data.Tables[i].Rows[m] = jdr;
                                                     if (r.TryGetValue("KeyValues", out jv))
                                                     {
                                                         JsonDataArray keys = jv as JsonDataArray;
                                                         if (keys != null)
                                                         {
                                                             jdr.KeyValues = new object[keys.Count];
                                                             for (int k = 0; k < keys.Count; k++)
                                                             {
                                                                 if (keys[k] != null)
                                                                 {
                                                                     JsonDataValue jdv = keys[k] as JsonDataValue;
                                                                     if (jdv != null)
                                                                     {
                                                                         jdr.KeyValues[k] = jdv.Value;
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                     if (r.TryGetValue("added", out jv))
                                                     {
                                                         if (((JsonDataBool)jv).ValueBool)
                                                         {
                                                             jdr.Added = true;
                                                         }
                                                     }
                                                     if (r.TryGetValue("deleted", out jv))
                                                     {
                                                         if (((JsonDataBool)jv).ValueBool)
                                                         {
                                                             jdr.Deleted = true;
                                                         }
                                                     }
                                                     if (r.TryGetValue("ItemArray", out jv))
                                                     {
                                                         JsonDataArray rowsData = jv as JsonDataArray;
                                                         if (rowsData != null)
                                                         {
                                                             Data.Tables[i].Rows[m].ItemArray = new object[rowsData.Count];
                                                             if (rowsData.Count > 0)
                                                             {
                                                                 for (int c = 0; c < rowsData.Count; c++)
                                                                 {
                                                                     if (rowsData[c] != null)
                                                                     {
                                                                         JsonDataValue jv0 = rowsData[c] as JsonDataValue;
                                                                         if (jv0 != null)
                                                                         {
                                                                             Data.Tables[i].Rows[m].ItemArray[c] = jv0.Value;
                                                                         }
                                                                         else
                                                                         {
                                                                             JsonDataArray jva = rowsData[c] as JsonDataArray;
                                                                             if (jva != null)
                                                                             {
                                                                                 Data.Tables[i].Rows[m].ItemArray[c] = jva.ToByteArray();
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 OnParseJsonText(prb);
             }
         }
     }
 }