Example #1
0
    public static List <ModFLD> GetFldFromMod(int modid)
    {
        FldRepository fldRepo = new FldRepository();
        var           res     = fldRepo.SearchFor(o => o.ModAdminId == modid).ToList();

        foreach (var item in res)
        {
            item.tbl_ModAdmin = null;
        }
        return(res);
    }
Example #2
0
    public static string ExecuteScalar(int mid, string sp, string param, int fldcount)
    {
        var                 c       = new JsonSerializer();
        dynamic             obj     = c.Deserialize(new StringReader(param), typeof(object));
        var                 context = new vexedtEntities();
        FldRepository       fldRepo = new FldRepository();
        var                 fld     = fldRepo.SearchFor(o => o.ModAdminId == mid).ToList();
        List <string>       lst     = new List <string>();
        List <SqlParameter> para    = new List <SqlParameter>();

        foreach (var item in fld)
        {
            if (obj[item.FldName] != null)
            {
                sp += " @" + item.FldName;
                if (fld.IndexOf(item) < fldcount)
                {
                    sp += ",";
                }
                item.tbl_ModAdmin = null;
                lst.Add((string)item.FldName);
                SqlParameter parameter = new SqlParameter();
                switch (item.FldType)
                {
                case "PK":
                case "CCB":
                case "NUM":
                    parameter.SqlDbType = System.Data.SqlDbType.Int;
                    if (obj[item.FldName] == null)
                    {
                        parameter.Value = 0;
                    }
                    else
                    {
                        parameter.Value = (int)(obj[item.FldName]);
                    }
                    break;

                case "TIME":
                    parameter.SqlDbType = System.Data.SqlDbType.NVarChar;
                    if (obj[item.FldName] == null)
                    {
                        parameter.Value = DBNull.Value;
                    }
                    else
                    {
                        parameter.Value = (string)(obj[item.FldName]);
                    }
                    break;

                case "DATE":
                    parameter.SqlDbType = System.Data.SqlDbType.Date;
                    if (obj[item.FldName] == null)
                    {
                        parameter.Value = DBNull.Value;
                    }
                    else
                    {
                        parameter.Value = (DateTime)(obj[item.FldName]);
                    }
                    break;

                case "FLOAT":
                    parameter.SqlDbType = System.Data.SqlDbType.Float;
                    if (obj[item.FldName] == null)
                    {
                        parameter.Value = 0;
                    }
                    else
                    {
                        parameter.Value = (double)(obj[item.FldName]);
                    }
                    break;

                case "TXT":
                case "HTML":
                    parameter.SqlDbType = System.Data.SqlDbType.NVarChar;
                    if (obj[item.FldName] == null)
                    {
                        parameter.Value = DBNull.Value;
                    }
                    else
                    {
                        parameter.Value = (string)(obj[item.FldName]);
                    }
                    break;

                case "CKB":
                    parameter.SqlDbType = System.Data.SqlDbType.Bit;
                    if (obj[item.FldName] == null)
                    {
                        parameter.Value = false;
                    }
                    else
                    {
                        parameter.Value = (bool)(obj[item.FldName]);
                    }
                    break;

                default:
                    parameter.SqlDbType = System.Data.SqlDbType.NVarChar;
                    if (obj[item.FldName] == null)
                    {
                        parameter.Value = DBNull.Value;
                    }
                    else
                    {
                        parameter.Value = (string)(obj[item.FldName]);
                    }
                    break;
                }
                parameter.ParameterName = item.FldName;
                para.Add(parameter);
            }
        }

        int res;

        try
        {
            res = context.Database.ExecuteSqlCommand(sp, para.ToArray());
        }
        catch (Exception ex)
        {
            return(sp + "\n" + JsonConvert.SerializeObject(para) + "\n" + ex.ToString());
        }

        return(JsonConvert.SerializeObject(res));
    }