Beispiel #1
0
    public SugarEntry GetEntry(string module, string id, string[] fields)
    {
        module = ConvertToProper(module);
        get_entry_result result = _sugarsoap.get_entry(_session, module, id, fields);

        VerifySugarResult.Verify(result.error);
        var entry = new SugarEntry(module);

        name_value[] valueList = result.entry_list[0].name_value_list;
        foreach (name_value value in valueList)
        {
            entry.Add(value.name, value.value);
        }
        return(entry);
    }
Beispiel #2
0
        public get_entry_result get_entry(string session, string module_name, string id, string[] select_fields)
        {
            Guid gUSER_ID = GetSessionUserID(session);

            string sTABLE_NAME = VerifyModuleName(module_name);
            int nACLACCESS = Security.GetUserAccess(module_name, "list");
            if ( nACLACCESS < 0 )
            {
                L10N L10n = new L10N("en-US");
                throw(new Exception(L10n.Term("ACL.LBL_INSUFFICIENT_ACCESS")));
            }

            get_entry_result results = new get_entry_result();
            DbProviderFactory dbf = DbProviderFactories.GetFactory();
            using ( IDbConnection con = dbf.CreateConnection() )
            {
                con.Open();
                string sSQL;
                sSQL = "select *" + ControlChars.CrLf
                     + "  from " + sTABLE_NAME + ControlChars.CrLf
                     + " where ID = @ID" + ControlChars.CrLf;
                using ( IDbCommand cmd = con.CreateCommand() )
                {
                    cmd.CommandText = sSQL;
                    Sql.AddParameter(cmd, "@ID", id);
                    if ( nACLACCESS == ACL_ACCESS.OWNER )
                    {
                        // 09/01/2006 Paul.  Notes do not have an ASSIGNED_USER_ID.
                        if ( sTABLE_NAME != "NOTES" )
                            Sql.AppendParameter(cmd, gUSER_ID, "ASSIGNED_USER_ID");
                    }
                    try
                    {
                        using ( DbDataAdapter da = dbf.CreateDataAdapter() )
                        {
                            ((IDbDataAdapter)da).SelectCommand = cmd;
                            using ( DataTable dt = new DataTable() )
                            {
                                da.Fill(dt);
                                if ( dt.Rows.Count > 0 )
                                {
                                    // 02/20/2006 Paul.  First initialize the array.
                                    results.field_list = new field      [select_fields.Length];
                                    results.entry_list = new entry_value[select_fields.Length];
                                    DataRow row = dt.Rows[0];
                                    for ( int i=0; i < select_fields.Length; i++ )
                                    {
                                        string sColumnName = select_fields[i];
                                        DataColumn col = dt.Columns[sColumnName];
                                        // 02/20/2006 Paul.  Then initialize each element in the array.
                                        // varchar, bool, datetime, int, text, blob
                                        results.field_list[i] = new field(sColumnName.ToLower(), col.DataType.ToString(), sColumnName, 0);
                                        // 02/20/2006 Paul.  Then initialize each element in the array.
                                        results.entry_list[i] = new entry_value(id, module_name, sColumnName, Sql.ToString(row[sColumnName]));
                                    }
                                }
                            }
                        }
                    }
                    catch(Exception ex)
                    {
                        SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                        throw(new Exception("SOAP: Failed contact_by_email", ex));
                    }
                }
            }
            return results;
        }
Beispiel #3
0
        public get_entry_result get_entries(string session, string module_name, string[] ids, string[] select_fields)
        {
            Guid gUSER_ID = GetSessionUserID(session);
            Guid gTIMEZONE = Sql.ToGuid(HttpContext.Current.Cache.Get("soap.user.timezone." + gUSER_ID.ToString()));
            TimeZone T10n = TimeZone.CreateTimeZone(gTIMEZONE);

            string sTABLE_NAME = VerifyModuleName(module_name);
            int nACLACCESS = Security.GetUserAccess(module_name, "list");
            if ( nACLACCESS < 0 )
            {
                L10N L10n = new L10N("en-US");
                throw(new Exception(L10n.Term("ACL.LBL_INSUFFICIENT_ACCESS")));
            }

            get_entry_result results = new get_entry_result();
            // 02/19/2006 Paul.  Exit early if nothing to get.  We need to prevent fetching all recods.
            if ( ids.Length == 0 )
                return results;

            DbProviderFactory dbf = DbProviderFactories.GetFactory();
            using ( IDbConnection con = dbf.CreateConnection() )
            {
                con.Open();
                string sSQL;
                // 02/16/2006 Paul.  Convert the table name to a VIEW.  We can do this because we don't want deleted records.
                // 02/18/2006 Paul.  Use the Edit view as it will include description, content, etc.
                sSQL = "select *" + ControlChars.CrLf
                     + "  from vw" + sTABLE_NAME + "_Edit" + ControlChars.CrLf
                     + " where 1 = 1" + ControlChars.CrLf;
                using ( IDbCommand cmd = con.CreateCommand() )
                {
                    cmd.CommandText = sSQL;
                    // 02/19/2006 Paul.  Need to filter by the IDs povided.
                    Sql.AppendParameter(cmd, ids, "ID");
                    if ( nACLACCESS == ACL_ACCESS.OWNER )
                    {
                        // 09/01/2006 Paul.  Notes do not have an ASSIGNED_USER_ID.
                        if ( sTABLE_NAME != "NOTES" )
                            Sql.AppendParameter(cmd, gUSER_ID, "ASSIGNED_USER_ID");
                    }
                    try
                    {
                        CultureInfo ciEnglish = CultureInfo.CreateSpecificCulture("en-US");
                        using ( DbDataAdapter da = dbf.CreateDataAdapter() )
                        {
                            ((IDbDataAdapter)da).SelectCommand = cmd;
                            using ( DataTable dt = new DataTable() )
                            {
                                da.Fill(dt);
                                if ( dt.Rows.Count > 0 )
                                {
                                    // 02/20/2006 Paul.  First initialize the array.
                                    results.field_list = new field      [select_fields.Length];
                                    results.entry_list = new entry_value[dt.Rows.Count];
                                    for ( int i=0; i < select_fields.Length; i++ )
                                    {
                                        string sColumnName = select_fields[i];
                                        DataColumn col = dt.Columns[sColumnName];
                                        // 02/21/2006 Paul.  Column may not exist.  For example, we don't return a MEETINGS.TIME_START.
                                        if ( col != null )
                                        {
                                            // 02/20/2006 Paul.  Then initialize each element in the array.
                                            // 02/16/2006 Paul.  We don't have a mapping for the labels, so just return the column name.
                                            // varchar, bool, datetime, int, text, blob
                                            results.field_list[i] = new field(sColumnName.ToLower(), col.DataType.ToString(), sColumnName, 0);
                                        }
                                    }

                                    // 02/16/2006 Paul.  SugarCRM 3.5.1 returns all fields even though only a few were requested.  We will do the same.
                                    int nItem = 0;
                                    foreach ( DataRow row in dt.Rows )
                                    {
                                        // 02/20/2006 Paul.  Then initialize each element in the array.
                                        results.entry_list[nItem] = new entry_value();
                                        results.entry_list[nItem].id              = Sql.ToGuid(row["ID"]).ToString();
                                        results.entry_list[nItem].module_name     = module_name;
                                        // 02/20/2006 Paul.  First initialize the array.
                                        results.entry_list[nItem].name_value_list = new name_value[dt.Columns.Count];
                                        int nColumn = 0;
                                        foreach ( DataColumn col in dt.Columns )
                                        {
                                            // 02/20/2006 Paul.  Then initialize each element in the array.
                                            // 08/17/2006 Paul.  We need to convert all dates to UniversalTime.
                                            if ( Information.IsDate(row[col.ColumnName]) )
                                            {
                                                // 08/17/2006 Paul.  The time on the server and the time in the database are both considered ServerTime.
                                                DateTime dtServerTime = Sql.ToDateTime(row[col.ColumnName]);
                                                // 08/17/2006 Paul.  We need a special function to convert to UniversalTime because it might already be in UniversalTime, based on m_bGMTStorage flag.
                                                DateTime dtUniversalTime = T10n.ToUniversalTimeFromServerTime(dtServerTime);
                                                results.entry_list[nItem].name_value_list[nColumn] = new name_value(col.ColumnName.ToLower(), dtUniversalTime.ToString(CalendarControl.SqlDateTimeFormat, ciEnglish.DateTimeFormat));
                                            }
                                            else
                                            {
                                                results.entry_list[nItem].name_value_list[nColumn] = new name_value(col.ColumnName.ToLower(), Sql.ToString(row[col.ColumnName]));
                                            }
                                            nColumn++;
                                        }
                                        nItem++;
                                    }
                                }
                            }
                        }
                    }
                    catch(Exception ex)
                    {
                        SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                        throw(new Exception("SOAP: Failed get_entries", ex));
                    }
                }
            }
            return results;
        }