protected void btnExport_Click(object sender, EventArgs e)
        {
            System.Data.DataTable dt = new System.Data.DataTable();

            dt.Columns.Add(new System.Data.DataColumn(FiltersStrings.GetText(@"FilterName"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(FiltersStrings.GetText(@"SubFilterName"), typeof(string)));

            List <FilterUI> filters = ProductController.GetAllFilter();

            foreach (FilterUI filter in filters)
            {
                int i = 0;
                System.Data.DataRow row = dt.NewRow();
                row[i++] = filter.FilterName;
                row[i++] = ProductController.ConvertSubFilterListToString(filter.LstSubFilter);
                dt.Rows.Add(row);
            }

            SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, true, true);

            Response.Clear();
            Response.AddHeader(@"content-disposition", @"attachment;filename=AppUsersExport_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension);
            Response.Charset         = @"UTF-8";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = ex.FileContentType;
            Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
            Response.Write(ex.ToString());
            Response.End();
        }
        protected void LoadItems(string sortField = "ProductId", dg.Sql.SortDirection sortDirection = dg.Sql.SortDirection.ASC)
        {
            if (!HasEditPermission)
            {
                dgFilters.Columns[dgFilters.Columns.Count - 1].Visible = false;
            }

            dgFilters.VirtualItemCount = ProductController.GetAllFilter().Count;
            if (dgFilters.VirtualItemCount == 0)
            {
                phHasItems.Visible   = false;
                phHasNoItems.Visible = true;
                lblNoItems.Text      = FiltersStrings.GetText(@"MessageNoFiltersFound");
            }
            else
            {
                phHasItems.Visible   = true;
                phHasNoItems.Visible = false;

                if (dgFilters.PageSize * dgFilters.CurrentPageIndex > dgFilters.VirtualItemCount)
                {
                    dgFilters.CurrentPageIndex         = 0;
                    hfCurrentPageIndex_dgFilters.Value = dgFilters.CurrentPageIndex.ToString();
                }
                List <FilterUI> filters = ProductController.GetAllFilter(dgFilters.PageSize, dgFilters.CurrentPageIndex);
                BindList(filters);
            }
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            HasEditPermission = Permissions.PermissionsForUser(SessionHelper.UserId()).Contains(Permissions.PermissionKeys.sys_perm);

            Master.AddButtonNew(FiltersStrings.GetText(@"NewFilterButton"), @"EditFilter.aspx?New=yes", new string[] { Permissions.PermissionKeys.sys_perm });
            dgFilters.PageIndexChanged += dgFilters_PageIndexChanged;
        }
        protected void gvSubFolder_RowUpdate(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                int         index            = e.RowIndex;
                GridViewRow row              = gvFilters.Rows[index];
                Int64       Id               = Int64.Parse(gvFilters.DataKeys[index].Value.ToString());
                TextBox     txtSubFilterName = (TextBox)row.Cells[0].FindControl("txtSubFilterName");
                if (txtSubFilterName.Text.Trim() == "")
                {
                    Master.MessageCenter.DisplayWarningMessage(GlobalStrings.GetText(@"ErrorSubFilterName"));
                    return;
                }
                Query q = new Query(SubFilter.TableSchema).Where(SubFilter.Columns.SubFilterName, txtSubFilterName.Text.Trim())
                          .AddWhere(SubFilter.Columns.FilterId, WhereComparision.EqualsTo, FilterId)
                          .AddWhere(SubFilter.Columns.SubFilterId, WhereComparision.NotEqualsTo, Id);
                if (q.GetCount() > 0)
                {
                    Master.MessageCenter.DisplayErrorMessage(FiltersStrings.GetText(@"MessageSubFiltersAlreadyExists"));
                    return;
                }

                SubFilter subFilter = SubFilter.FetchByID(Id);
                subFilter.SubFilterName = txtSubFilterName.Text.Trim();
                subFilter.Save();
                gvFilters.EditIndex = -1;

                LoadItems();
            }
            catch (Exception) { }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }
            // check if filter name already exists
            Query q = new Query(Filter.TableSchema).Where(Filter.Columns.FilterName, txtFilterName.Text.Trim())
                      .AddWhere(Filter.Columns.FilterId, WhereComparision.NotEqualsTo, FilterId);

            if (q.GetCount() > 0)
            {
                Master.MessageCenter.DisplayWarningMessage(FiltersStrings.GetText(@"AlreadyExists"));
                return;
            }

            Filter filter;

            if (IsNewMode)
            {
                filter = new Filter();
            }
            else
            {
                filter = Filter.FetchByID(FilterId);
                if (filter == null)
                {
                    Master.MessageCenter.DisplaySuccessMessage(FiltersStrings.GetText(@"MessageUnknownError"));
                    return;
                }
            }
            filter.FilterName = txtFilterName.Text;
            filter.Save();

            if (IsNewMode)
            {
                FilterId = filter.FilterId;
                string successMessage = FiltersStrings.GetText(@"MessageFilterCreated");
                string url            = @"EditFilter.aspx?FilterId=" + FilterId;
                url += @"&message-success=" + Server.UrlEncode(successMessage);
                Response.Redirect(url, true);
                return;
            }
            else
            {
                string successMessage = FiltersStrings.GetText(@"MessageFilterUpdate");
                string url            = @"EditFilter.aspx?FilterId=" + FilterId;
                url += @"&message-success=" + Server.UrlEncode(successMessage);
                Response.Redirect(url, true);
                return;
            }
        }
Exemple #6
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Query q = new Query(SubFilter.TableSchema).Where(SubFilter.Columns.FilterId, FilterId);
                q.Delete().Execute();

                Filter.Delete(FilterId);
                //string url = "Filters.aspx?message-success=" + FiltersStrings.GetText(@"MessageFilterDeleted");
                //Response.Redirect(url, true);
                Master.MessageCenter.DisplaySuccessMessage(FiltersStrings.GetText(@"MessageFilterDeleted"));
            }
        }
Exemple #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Int64.TryParse(Request.QueryString[@"FilterId"], out FilterId))
            {
                if (ProductController.IsFilterInUse(FilterId))
                {
                    Master.MessageCenter.DisplayErrorMessage(FiltersStrings.GetText(@"MessageDeleteFailedFilterInUse"));
                    pnlDelete.Visible = false;
                }
            }
            FilterName = new Query(Filter.TableSchema).Select(Filter.Columns.FilterName).Where(Filter.Columns.FilterId, FilterId).ExecuteScalar();

            if (FilterName == null)
            {
                Http.Respond404(true);
            }
        }
 protected void gvSubFolder_RowDelete(object sender, GridViewDeleteEventArgs e)
 {
     try
     {
         int   index = e.RowIndex;
         Int64 Id    = Int64.Parse(gvFilters.DataKeys[index].Value.ToString());
         Query q     = new Query(ProductFilter.TableSchema).Where(ProductFilter.Columns.SubFilterId, Id);
         if (q.GetCount() > 0)
         {
             Master.MessageCenter.DisplayErrorMessage(FiltersStrings.GetText(@"ErrorDeleteSubFilter"));
             return;
         }
         else
         {
             (new Query(SubFilter.TableSchema).Where(SubFilter.Columns.SubFilterId, Id).Delete()).Execute();
             LoadItems();
         }
     }
     catch (Exception) { }
 }
        protected void gvSubFolder_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (!e.CommandName.Equals("AddNew"))
                {
                    return;
                }

                GridViewRow row   = gvFilters.FooterRow;
                int         index = gvFilters.EditIndex;
                TextBox     txtSubFilterNameNew = (TextBox)row.Cells[0].FindControl("txtSubFilterNameNew");
                if (txtSubFilterNameNew.Text.Trim() == "")
                {
                    Master.MessageCenter.DisplayErrorMessage(GlobalStrings.GetText(@"ErrorSubFilterName"));
                    return;
                }
                Query q = new Query(SubFilter.TableSchema).Where(SubFilter.Columns.SubFilterName, txtSubFilterNameNew.Text.Trim())
                          .AddWhere(SubFilter.Columns.FilterId, WhereComparision.EqualsTo, FilterId);
                if (q.GetCount() > 0)
                {
                    Master.MessageCenter.DisplayErrorMessage(FiltersStrings.GetText(@"MessageSubFiltersAlreadyExists"));
                    return;
                }

                SubFilter subFilter = new SubFilter();
                subFilter.FilterId      = FilterId;
                subFilter.SubFilterName = txtSubFilterNameNew.Text.Trim();
                subFilter.Save();
                gvFilters.EditIndex = -1;

                // refresh the grid view data
                LoadItems();
            }
            catch (Exception) { }
        }
        private void ReadCSVFile(string filePath)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                using (CsvReader csv = new CsvReader(fs))
                {
                    string[] _values = null;

                    CsvDataTable = new DataTable();
                    CsvDataTable.Columns.Add(new DataColumn("Line", typeof(int)));
                    CsvDataTable.Columns.Add(new DataColumn("FilterName", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("SubFilterName", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("Comments", typeof(string)));

                    bool bErrors     = false;
                    int  line        = -1;
                    int  numToImport = 0;
                    _values = csv.ReadRow();
                    while (_values != null)
                    {
                        if (++line == 0)
                        {
                            _values = csv.ReadRow();
                            continue;
                        }

                        DataRow DR       = CsvDataTable.NewRow();
                        string  comments = "";

                        try
                        {
                            DR["Line"]          = line;
                            DR["FilterName"]    = _values[0] == "" ? "" : _values[1].Trim();
                            DR["SubFilterName"] = _values[1] == "" ? "" : _values[2].Trim();
                            if (DR["FilterName"] == null || DR["FilterName"].ToString() == "" || DR["SubFilterName"] == null || DR["SubFilterName"].ToString() == "")
                            {
                                if (comments != "")
                                {
                                    comments += "<br />";
                                }
                                comments += FiltersStrings.GetText(@"MessageFilterOrSubFilterNameEmpty");
                            }
                            else
                            {
                                Filter f = Filter.FetchByName(DR["FilterName"].ToString());

                                Query q = new Query(Filter.TableSchema);
                                q.Join(JoinType.InnerJoin, SubFilter.TableSchema, SubFilter.TableSchema.SchemaName, new JoinColumnPair(Filter.TableSchema, Filter.Columns.FilterId, SubFilter.Columns.FilterId));
                                q.Where(Filter.Columns.FilterName, DR["FilterName"].ToString()).AddWhere(SubFilter.Columns.SubFilterName, DR["SubFilterName"].ToString());
                                if (q.GetCount() > 0)
                                {
                                    if (comments != "")
                                    {
                                        comments += "<br />";
                                    }
                                    comments += FiltersStrings.GetText(@"AlreadyExistsComment");
                                }
                            }
                        }
                        catch (Exception e) { }

                        if (comments != "")
                        {
                            bErrors   = true;
                            comments += "<br />" + FiltersStrings.GetText(@"MessageWillNotImported");
                        }
                        else
                        {
                            numToImport++;
                        }

                        DR["Comments"] = comments;
                        CsvDataTable.Rows.Add(DR);

                        _values = csv.ReadRow();
                    }

                    if (bErrors)
                    {
                        lblErrors.Text = ProductsStrings.GetText(@"ImportErrorsLabel");
                    }
                    else
                    {
                        lblErrors.Text = ProductsStrings.GetText(@"ImportNoErrorsLabel");;
                    }

                    dgFilter.DataSource = CsvDataTable;
                    dgFilter.DataBind();
                    lblTotal.Text         = CsvDataTable.Rows.Count.ToString();
                    lblTotalToImport.Text = numToImport.ToString();
                    btnImport.Enabled     = numToImport == 0 ? false : true;
                }
            }
        }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     Master.PageTitleHtml = FiltersStrings.GetText(@"ImportFiltersPageTitle");
     Master.ActiveMenu    = "ImportFilter";
 }
        private void ReadCSVFile(string filePath)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                using (CsvReader csv = new CsvReader(fs))
                {
                    string[] _values = null;

                    CsvDataTable = new DataTable();
                    CsvDataTable.Columns.Add(new DataColumn("Line", typeof(int)));
                    CsvDataTable.Columns.Add(new DataColumn("AreaName", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("CityName", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("Comments", typeof(string)));

                    bool bErrors     = false;
                    int  line        = -1;
                    int  numToImport = 0;
                    _values = csv.ReadRow();
                    while (_values != null)
                    {
                        if (++line == 0)
                        {
                            _values = csv.ReadRow();
                            continue;
                        }

                        DataRow DR       = CsvDataTable.NewRow();
                        string  comments = "";

                        try
                        {
                            DR["Line"]     = line;
                            DR["AreaName"] = _values[2] == "" ? "" : _values[2].Trim();
                            DR["CityName"] = _values[1] == "" ? "" : _values[1].Trim();
                            if (DR["AreaName"] == null || DR["AreaName"].ToString() == "" || DR["CityName"] == null || DR["CityName"].ToString() == "")
                            {
                                if (comments != "")
                                {
                                    comments += "<br />";
                                }
                                comments += FiltersStrings.GetText(@"ReqCityAndAreaName");
                            }
                            else
                            {
                                Area f = Area.FetchByName(DR["AreaName"].ToString());
                                if (f != null)
                                {
                                    Query q = new Query(City.TableSchema);
                                    q.Where(City.Columns.CityName, DR["CityName"].ToString()).AddWhere(City.Columns.AreaId, f.AreaId);
                                    if (q.GetCount() > 0)
                                    {
                                        if (comments != "")
                                        {
                                            comments += "<br />";
                                        }
                                        comments += GlobalStrings.GetText(@"AlreadyExistsCity");
                                    }
                                }
                            }
                        }
                        catch (Exception e) { }

                        if (comments != "")
                        {
                            bErrors   = true;
                            comments += "<br />" + GlobalStrings.GetText(@"MessageWillNotImported");
                        }
                        else
                        {
                            numToImport++;
                        }

                        DR["Comments"] = comments;
                        CsvDataTable.Rows.Add(DR);

                        _values = csv.ReadRow();
                    }

                    if (bErrors)
                    {
                        lblErrors.Text = GlobalStrings.GetText(@"ImportErrorsLabel");
                    }
                    else
                    {
                        lblErrors.Text = GlobalStrings.GetText(@"ImportNoErrorsLabel");;
                    }

                    dgCity.DataSource = CsvDataTable;
                    dgCity.DataBind();
                    lblTotal.Text         = CsvDataTable.Rows.Count.ToString();
                    lblTotalToImport.Text = numToImport.ToString();
                    btnImport.Enabled     = numToImport == 0 ? false : true;
                }
            }
        }
Exemple #13
0
 protected void Page_PreRender(object sender, EventArgs e)
 {
     Master.PageTitleHtml = string.Format(FiltersStrings.GetText(@"DeleteFilterPageTitle"), FilterName);
     Master.ActiveMenu    = "Filters";
 }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     Master.PageTitle  = FiltersStrings.GetText(@"FiltersPageTitle");
     Master.ActiveMenu = "Filters";
     Master.AddClientScriptInclude(@"dgDateManager.js");
 }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     Master.PageTitle = FiltersStrings.GetText(IsNewMode ? @"NewFiltersPageTitle" : @"EditFiltersPageTitle");
     Master.AddButtonNew(FiltersStrings.GetText(@"NewFilterButton"), @"EditFilter.aspx?New=Yes", new string[] { Permissions.PermissionKeys.sys_perm });
     Master.ActiveMenu = "Filters";
 }