Exemple #1
0
    private bool DeleteEntity()
    {
        using (var ctx = new Entities())
        {
            try
            {
                var id         = btnFormButtons.EntityID;
                var dataSource = ctx.REPORTs.FirstOrDefault(u => u.ID == id);
                dataSource.DELETED = 1;

                EntityExtensions.ExecuteProcedure(new EntityConnection(ctx.Connection.ConnectionString),
                                                  "Entities.ClearReportFields", new KeyValuePair <string, object>("REPORT_ID", dataSource.ID));

                EntityExtensions.ExecuteProcedure(new EntityConnection(ctx.Connection.ConnectionString),
                                                  "Entities.ClearReportSites", new KeyValuePair <string, object>("REPORT_ID", dataSource.ID));

                Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName,
                          string.Format("Report Marked as Deleted. ID: {0}", dataSource.ID), LoggedInUser.ID);
                ctx.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                ExceptionLog.WriteException("Delete Report", ex);
                ShowMessage(MessageType.Error, "There was an error deleting this record");
            }
        }
        return(false);
    }
Exemple #2
0
    private bool CopyFromForm()
    {
        using (var ctx = new Entities())
        {
            try
            {
                var dataSource = new FIELDGROUP();

                if (btnFormButtons.EntityID.HasValue)
                {
                    var id = btnFormButtons.EntityID;
                    dataSource = ctx.FIELDGROUPs.FirstOrDefault(u => u.ID == id);
                    PopulateEntity(ref dataSource);
                    Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName,
                              string.Format("Group Edited. ID: {0}", dataSource.ID), LoggedInUser.ID);
                }
                else
                {
                    dataSource = new FIELDGROUP {
                        CREATEDON = DateTime.Now
                    };
                    PopulateEntity(ref dataSource);
                    ctx.AddToFIELDGROUPs(dataSource);

                    Audit.Log(ctx, AuditType.Add, this.Page.GetType().FullName,
                              string.Format("Group Added: {0}", dataSource.NAME), LoggedInUser.ID);
                }

                ctx.SaveChanges();

                // delete fields
                EntityExtensions.ExecuteProcedure(new EntityConnection(ctx.Connection.ConnectionString),
                                                  "Entities.ClearGroupFields", new KeyValuePair <string, object>("GROUP_ID", dataSource.ID));

                // save fields
                foreach (var item in jsGroupFields.SelectedItems)
                {
                    var groupField = new FIELDGROUPFIELD {
                        FIELDGROUPID = dataSource.ID, FIELDID = (short)int.Parse(item.Value)
                    };
                    ctx.AddToFIELDGROUPFIELDs(groupField);
                }

                ctx.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                ExceptionLog.WriteException("Save Group", ex);
                ShowMessage(MessageType.Error, "There was an error saving this record");
            }
        }
        return(false);
    }
Exemple #3
0
    private bool CopyFromForm()
    {
        var isValid = true;

        if (DateTime.ParseExact(txtDateFrom.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture) >
            DateTime.ParseExact(txtDateTo.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture))
        {
            ShowMessage(MessageType.Warning, "Your Date From date should be before your Date To date");
            isValid = false;
        }

        var selectedFields = jsReportFields_value.Value.Split(',');

        if (selectedFields.Length == 0)
        {
            ShowMessage(MessageType.Warning, "You have not chosen any fields - please select at least 1 field.");
            isValid = false;
        }

        if (jsReportSites.SelectedItems.Count == 0)
        {
            ShowMessage(MessageType.Warning, "You have not chosen any sites - please select at least 1 site.");
            isValid = false;
        }

        if (selectedFields.Length > 256)
        {
            ShowMessage(MessageType.Warning, "You have chosen too many fields, please select less than 256.");
            isValid = false;
        }

        if (!isValid)
        {
            return(false);
        }

        using (var ctx = new Entities())
        {
            try
            {
                var dataSource = new REPORT();

                if (btnFormButtons.EntityID.HasValue)
                {
                    var id = btnFormButtons.EntityID;
                    dataSource = ctx.REPORTs.FirstOrDefault(u => u.ID == id);
                    PopulateEntity(ref dataSource);
                    Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName,
                              string.Format("Report Edited. ID: {0}", dataSource.ID), LoggedInUser.ID);

                    // remove any cached data
                    var datastore = new DataStore(ConfigurationSettings.AppSettings["datastore_path"]);
                    datastore.Remove(id.Value);
                }
                else
                {
                    dataSource = new REPORT
                    {
                        CREATEDON = DateTime.Now,
                        DELETED   = 0
                    };
                    PopulateEntity(ref dataSource);
                    ctx.AddToREPORTs(dataSource);

                    Audit.Log(ctx, AuditType.Add, this.Page.GetType().FullName,
                              string.Format("Report Added. Name: {0}", dataSource.NAME), LoggedInUser.ID);
                }

                ctx.SaveChanges();

                var fieldsChanged = (jsReportFields_changed.Value != string.Empty);

                if (fieldsChanged)
                {
                    EntityExtensions.ExecuteProcedure(new EntityConnection(ctx.Connection.ConnectionString),
                                                      "Entities.ClearReportFields",
                                                      new KeyValuePair <string, object>("REPORT_ID", dataSource.ID));

                    var order = 0;
                    foreach (var item in selectedFields)
                    {
                        var reportField = new REPORTFIELD
                        {
                            REPORTID   = dataSource.ID,
                            FIELDID    = (short)int.Parse(item),
                            FIELDORDER = (short)order
                        };
                        ctx.AddToREPORTFIELDs(reportField);
                        order++;
                    }
                }

                if (jsReportSites.ValueChanged)
                {
                    EntityExtensions.ExecuteProcedure(new EntityConnection(ctx.Connection.ConnectionString),
                                                      "Entities.ClearReportSites",
                                                      new KeyValuePair <string, object>("REPORT_ID", dataSource.ID));

                    foreach (var item in jsReportSites.SelectedItems)
                    {
                        var reportSite = new REPORTSITE {
                            REPORTID = dataSource.ID, SITEID = (short)int.Parse(item.Value)
                        };
                        ctx.AddToREPORTSITEs(reportSite);
                    }
                }

                if (fieldsChanged || jsReportSites.ValueChanged)
                {
                    ctx.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                ExceptionLog.WriteException("Save Report", ex);
                ShowMessage(MessageType.Error, "There was an error saving this record");
            }
        }
        return(false);
    }