logging editor

logging editor

eyal_hbeyal_hb Posts: 32Questions: 10Answers: 0

I wanted to add something to my logging so that could quickly see at a glance what the actual changes to the data were.
so now i need to get the previous values from editor before i check what has changed and save in my log table
here is my code

editor.PreEdit += (sender, e) => prev_Values = Common.Classes.Functions.getPrevValues(db, editor.Table()[0], "MealService_id", e.Id);

and this is the prev_values function:

public static Dictionary<string, object> getPrevValues(DataTables.Database db, string table,string tablePk ,object id)
        {
            IEnumerable<string> st = new List<string>() { "*" };
            Dictionary<string, dynamic> check = new Dictionary<string, dynamic>();
            check.Add(tablePk, id);
            prev_Values = db.Select(table, st, check, null).Fetch();
            return prev_Values;
        }

now until here its ok. but i get only the data from specific table, and not all the data from join tables,
how i can get this data?

Answers

  • allanallan Posts: 50,505Questions: 1Answers: 7,508 Site admin

    Hi,

    You'd need to perform the join against your other tables in addition to your select if you are pulling in and changing information in other tables. Or are you just changing the reference value to them in the host table?

    Allan

  • eyal_hbeyal_hb Posts: 32Questions: 10Answers: 0

    so i need to write this function to every table, it cannot be generic?
    for now i changing the reference value in my tables,

  • eyal_hbeyal_hb Posts: 32Questions: 10Answers: 0

    hey allan one more question about other subject, about export to excel all working great but there are columns thats show me object object when multiple value in column, how can i show all values and not object object?

  • allanallan Posts: 50,505Questions: 1Answers: 7,508 Site admin

    How generic it can be will depend on how you are storing the data. If you have a look at this example we serialise the changed values and just store that in the db. If you wanted to break it down so you have a per column value, then yes, it would need to be per table.

    about export to excel all working great but there are columns thats show me object object when multiple value in column

    That suggests that the data property for the cell points to an object (or array). Buttons' export should use the display value by default (although perhaps you are using an object for that?). You can use an orthogonal data renderer to control what is exported. To be able to help much more than that, I'd need a link to a test case showing the issue.

    Allan

  • eyal_hbeyal_hb Posts: 32Questions: 10Answers: 0

    thank Allan, i have one more question if you can help!
    i have tables called hotel, contactMan and ContactMan_Hotel, each hotel can have many Contact Man.
    i want to add option in form in create mode of hotel to able to add rows automatic(contact man row)when click on custom button +,
    the rows will be need to be with identity number so when i will insert them into database i could run over with for i and insert all..

    this is simple without editor, but i get stuck with editor

  • allanallan Posts: 50,505Questions: 1Answers: 7,508 Site admin

    i want to add option in form in create mode of hotel to able to add rows automatic(contact man row)when click on custom button +,

    Do you mean you want a list of managers and the ability to add new ones in the form? I'm afraid that is not something that Editor currently does.

    I'm not certain that is what you are actually asking though. If you just want to link managers to hotels, then the Mjoin example shows how that can be done.

    Regards,
    Allan

  • eyal_hbeyal_hb Posts: 32Questions: 10Answers: 0

    if i have hotel and mjoin to contact man table
    can i add manager to this table from the hotel form?
    because it simply insert first the hotel details and then go to contact man table and create the contact man?

    i just want to have the ability to add bulk of row every time i press button + on form, then in server-side i will take the information with for i loop and will handle this myself?

  • allanallan Posts: 50,505Questions: 1Answers: 7,508 Site admin

    I'm really sorry, I'm just not understanding what you are looking for. Are you able to illustrate it with data or with wireframe pictures?

    Thanks
    Allan

  • eyal_hbeyal_hb Posts: 32Questions: 10Answers: 0

    i do something else, but i get stuck.
    this is my way:

    [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
            public ActionResult GetDataContactMan(int id,Common.Classes.Enums.Values type)
            {
                var settings = Properties.Settings.Default;
                var formData = HttpContext.Request.Form;
    
                using (var db = new Database(settings.DbType, settings.DbConnection))
                {
                    var editor = new DataTables.Editor(db, "ProfessionalContactMan", "ContactMan_id");
                    if (type== Common.Classes.Enums.Values.Hotel)
                    {
                        editor.Where(q =>
                        q.Where("ProfessionalContactMan.ContactMan_id", "(SELECT ProfessionalContactMan_Id FROM ProfessionalContactMan_Hotel WHERE Hotel_Id= " + id + ")", "IN", false)
                        );
                    }
                    editor.Model<Model.ProfessionalContactManVM>("ProfessionalContactMan")
                    .Field(new Field("ProfessionalContactMan.ContactMan_Degree")
                     .Options(() => new List<Dictionary<string, object>>{
                      new Dictionary<string, object>{ {"value", "Mr" }, {"label", "Mr" } },
                      new Dictionary<string, object>{ {"value", "Mrs" }, {"label", "Mrs " } },
                      new Dictionary<string, object>{ {"value", "Dr" }, {"label", "Dr" } },
                      new Dictionary<string, object>{ {"value", "Prof" }, {"label", "Prof" } },
                      new Dictionary<string, object>{ {"value", "Ms" }, {"label", "Ms" } },
                      new Dictionary<string, object>{ {"value", "Child" }, {"label", "Child" } }
                    }))
                    .Field(new Field("ProfessionalContactMan.First_Name"))
                    .Field(new Field("ProfessionalContactMan.Last_Name"))
                    .Field(new Field("ProfessionalContactMan.Working_Phone"))
                    .Field(new Field("ProfessionalContactMan.Phone"))
                    .Field(new Field("ProfessionalContactMan.Role"));
    
                    editor.PostCreate += (sender, e) => {
                        AddContactMan((string)e.Id, id, type);
                    };
    
                    editor.Process(formData);
                    DtResponse data = editor.Data();
                    return Json(data, JsonRequestBehavior.AllowGet);
                }
    
            }
    
            public bool AddContactMan(string contactManId,int id,Common.Classes.Enums.Values type)
            {
                try
                {
                    using (var db = new Pegasus_OperationEntities())
                    {
                        int contactId = 0;
                        Int32.TryParse(contactManId,out contactId);
                        var newContactMan = db.pr.AsNoTracking().Where(x => x.ContactMan_id == contactId).SingleOrDefault();
                        if (type == Common.Classes.Enums.Values.Hotel)
                        {
                            Hotel hotel = db.Hotels.Where(x => x.Hotel_id == id).SingleOrDefault();
                            hotel.ProfessionalContactMen.Add(newContactMan);
    
                        }
                        db.SaveChanges();
                    }
    
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
    

    but now i cant get the contact_man details i get timeout exception, maybe beacuse the editor database is still using this table?

  • allanallan Posts: 50,505Questions: 1Answers: 7,508 Site admin

    I'd expect the server to give an error stating that there was already a lock on the database if that was the case. Its locking up somewhere in that code, but its not clear to me where. If you remove your PostCreate event handler, does it run through?

    Thanks,
    Allan

Sign In or Register to comment.