Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List <int> LstYear = new List <int>();
            int        start   = DateTime.Now.AddYears(-20).Year;
            int        end     = DateTime.Now.Year;
            for (int i = start; i <= end; i++)
            {
                LstYear.Add(i);
            }
            ddlyear.DataSource = LstYear;
            ddlyear.DataBind();
            ddlyear.Items.Insert(0, new ListItem(ProductsStrings.GetText("Choose"), "0"));

            List <int> LstMonth = new List <int>();
            for (int i = 1; i <= 12; i++)
            {
                LstMonth.Add(i);
            }
            ddlMonth.DataSource = LstMonth;
            ddlMonth.DataBind();
            ddlMonth.Items.Insert(0, new ListItem(ProductsStrings.GetText("Choose"), "0"));
            ddlDayFrom.Items.Insert(0, new ListItem(ProductsStrings.GetText("Choose"), "0"));
            ddlDayTo.Items.Insert(0, new ListItem(ProductsStrings.GetText("Choose"), "0"));
        }
        LoadItem();
    }
Exemple #2
0
 protected void dgOrders_ItemDataBound(object sender, DataGridItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Footer)
     {
         e.Item.Cells[2].Text = ProductsStrings.GetText("OrderCount") + " $Count";
         e.Item.Cells[3].Text = SupplierProfileStrings.GetText("Shekel") + " $Sum " + ProductsStrings.GetText("OrderSum");
     }
 }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            Master.PageTitle  = ProductsStrings.GetText(IsNewMode ? @"NewProductPageTitle" : @"EditProductPageTitle");
            Master.ActiveMenu = IsNewMode ? "NewProduct" : "Products";

            //rfvProductName.Visible = rfvProductName.Enabled = IsNewMode;
            //rfvProductCode.Visible = rfvProductCode.Enabled = IsNewMode;
            //rfvProductAmount.Visible = rfvProductAmount.Enabled = IsNewMode;
            //rfvProductDescription.Visible = rfvProductDescription.Enabled = IsNewMode;
        }
Exemple #4
0
    protected void btnExport_Click(object sender, EventArgs e)
    {
        System.Data.DataTable dt = new System.Data.DataTable();

        dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductName"), typeof(string)));
        dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductCode"), typeof(string)));
        dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"Amount"), typeof(string)));
        dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"RecomendedPrice"), typeof(string)));
        dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"Description"), typeof(string)));
        dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"AnimalType"), typeof(string)));
        dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductPrice"), typeof(string)));
        //dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"Category"), typeof(string)));
        //  dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"SubCategory"), typeof(string)));
        // dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductRate"), typeof(string)));

        string searchCode = "%" + txtSearch.Text.Trim() + "%";

        List <ProductUI> products = ProductController.GetAllProductUI(searchCode, Int64.Parse(ddlCategory.SelectedValue), Int64.Parse(ddlSubCategory.SelectedValue));

        foreach (ProductUI product in products)
        {
            int i = 0;
            System.Data.DataRow row = dt.NewRow();
            row[i++] = product.ProductName;
            row[i++] = product.ProductCode;
            row[i++] = product.Amount;
            row[i++] = product.RecomendedPrice;
            row[i++] = product.Description;
            row[i++] = ProductController.ConvertListToString(product.AnimalLst);
            SupplierProduct sup_prd = SupplierProduct.FetchByID(SuppliersSessionHelper.SupplierId(), product.ProductId);
            if (sup_prd != null)
            {
                row[i++] = sup_prd.Price;
            }


            //row[i++] = product.CategoryName;
            // row[i++] = product.SubCategoryName;
            // row[i++] = product.ProductRate;
            dt.Rows.Add(row);
        }

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

        Response.Clear();
        Response.AddHeader(@"content-disposition", @"attachment;filename=ProductsExport_" + 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();
    }
Exemple #5
0
    protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        Int64 CategoryId = (ddlCategory.SelectedValue != null && Int64.TryParse(ddlCategory.SelectedValue, out CategoryId) && CategoryId > 0 ? CategoryId : 0);

        ddlSubCategory.DataSource = ProductController.GetAllSubCategory(CategoryId);
        ddlSubCategory.DataBind();
        ddlSubCategory.Enabled = ddlSubCategory.Items.Count > 0 ? true : false;
        ddlSubCategory.Items.Insert(0, new ListItem(ProductsStrings.GetText("Choose"), "0"));

        LoadItem();
    }
Exemple #6
0
    public string ListTostring(List <BidProductUI> LstProduct)
    {
        string products = "";

        foreach (var item in LstProduct)
        {
            products += ProductsStrings.GetText("ProductName") + ":" + item.ProductName + " " + ProductsStrings.GetText("ProductAmountExcel") + ":" + item.ProductAmount +
                        ProductsStrings.GetText("OrderAmount") + ":" + item.Amount + " " + ProductsStrings.GetText("ProductCode") + ":" + item.ProductCode + ", ";
        }
        return(products.Substring(0, products.Length));
    }
        protected void LoadItems()
        {
            if (!HasEditPermission)
            {
                dgProducts.Columns[dgProducts.Columns.Count - 1].Visible = false;
            }

            string searchCode = "%" + txtSearchCode.Text.Trim() + "%";

            if (Int64.Parse(ddlCategory.SelectedValue) != 0)
            {
                dgProducts.VirtualItemCount = ProductController.GetAllProductUI(searchCode, Int64.Parse(ddlCategory.SelectedValue), 0).Count;
                if (Int64.Parse(ddlSubCategory.SelectedValue) != 0)
                {
                    dgProducts.VirtualItemCount = ProductController.GetAllProductUI(searchCode, Int64.Parse(ddlCategory.SelectedValue), Int64.Parse(ddlSubCategory.SelectedValue)).Count;
                }
            }
            else
            {
                dgProducts.VirtualItemCount = ProductController.GetAllProductUI(searchCode).Count;
            }

            if (dgProducts.VirtualItemCount == 0)
            {
                phHasItems.Visible   = false;
                phHasNoItems.Visible = true;
                lblNoItems.Text      = ProductsStrings.GetText(@"MessageNoProductsFound");
            }
            else
            {
                phHasItems.Visible   = true;
                phHasNoItems.Visible = false;

                if (dgProducts.PageSize * dgProducts.CurrentPageIndex > dgProducts.VirtualItemCount)
                {
                    dgProducts.CurrentPageIndex         = 0;
                    hfCurrentPageIndex_dgProducts.Value = dgProducts.CurrentPageIndex.ToString();
                }
                List <ProductUI> products = ProductController.GetAllProductUI(searchCode, Int64.Parse(ddlCategory.SelectedValue), Int64.Parse(ddlSubCategory.SelectedValue), dgProducts.PageSize, dgProducts.CurrentPageIndex);
                BindList(products);
            }
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Product p = Product.FetchByID(ProductId);
                p.IsDeleted = true;
                p.Save();

                ProductFilterCollection coll = ProductController.GetProductFilterForProduct(ProductId);
                if (coll.Count > 0)
                {
                    foreach (ProductFilter item in coll)
                    {
                        ProductFilter.Delete(ProductId, item.FilterId, item.SubFilterId);
                    }
                }

                Master.MessageCenter.DisplaySuccessMessage(ProductsStrings.GetText(@"MessageProductDeleted"));
            }
        }
        protected void btnAcceptFile_Click(object sender, EventArgs e)
        {
            if (fuImportFile.HasFile)



            {
                string[] allowedFileTypes = { "text/csv", "text/xml", "application/vnd.ms-excel" };
                if (allowedFileTypes.Contains(fuImportFile.PostedFile.ContentType))
                {
                    string filename     = Path.GetRandomFileName() + "_" + Path.GetFileName(fuImportFile.FileName);
                    string filePath     = Path.Combine(Settings.GetSetting(Settings.Keys.TEMP_UPLOAD_FOLDER), filename);
                    string fullFilePath = filePath;
                    if (!fullFilePath.Contains(@":/") && !fullFilePath.Contains(@":\"))
                    {
                        fullFilePath = Server.MapPath(filePath);
                    }

                    //Save that file in temp folder
                    fuImportFile.SaveAs(fullFilePath);

                    ReadCSVFile(fullFilePath);

                    phErrors.Visible       = true;
                    phProductsList.Visible = true;
                    phImportResult.Visible = false;
                }
                else
                {
                    Master.MessageCenter.DisplayErrorMessage(ProductsStrings.GetText(@"ImportFileWrongFormat"));
                    return;
                }
            }
            else
            {
                lblErrors.Text         = ProductsStrings.GetText(@"MessageFileNotSelected");
                phErrors.Visible       = true;
                phProductsList.Visible = false;
                phImportResult.Visible = false;
            }
        }
        protected void btnImport_Click(object sender, EventArgs e)
        {
            if (CsvDataTable != null)
            {
                int count = 0;
                try
                {
                    foreach (DataRow row in CsvDataTable.Rows)
                    {
                        if (row["Comments"].ToString() == "")
                        {
                            Filter f = Filter.FetchByName(row["FilterName"].ToString());
                            if (f == null)
                            {
                                f            = new Filter();
                                f.FilterName = row["FilterName"].ToString();
                                f.Save();
                            }
                            SubFilter sub = new SubFilter();
                            sub.SubFilterName = row["SubFilterName"].ToString();
                            sub.FilterId      = f.FilterId;
                            sub.Save();
                            count++;
                        }
                    }

                    lblImportResult.Text = ProductsStrings.GetText(@"MessageImportSuccess");
                }
                catch
                {
                    lblImportResult.Text = ProductsStrings.GetText(@"MessageImportFailedUnknown");
                }
                phImportResult.Visible = true;
                lblTotalImported.Text  = count.ToString();
                btnImport.Enabled      = false;
                phErrors.Visible       = false;
                phProductsList.Visible = false;
            }
        }
        protected void btnExport_Click(object sender, EventArgs e)
        {
            System.Data.DataTable dt = new System.Data.DataTable();

            dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductName"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductCode"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"Amount"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductPrice"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"Gift"), typeof(string)));


            List <ProductUI> products = ProductController.GetSupplierProducts(SupplierId);

            foreach (ProductUI product in products)
            {
                int i = 0;
                System.Data.DataRow row = dt.NewRow();
                row[i++] = product.ProductName;
                row[i++] = product.ProductCode;
                row[i++] = product.Amount;
                row[i++] = product.ProductPrice;
                row[i++] = product.Gift;
                dt.Rows.Add(row);
            }

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

            Response.Clear();
            Response.AddHeader(@"content-disposition", @"attachment;filename=SupplierProductsExport_" + DateTime.Now.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();
        }
Exemple #12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadItem();
            ddlAnimalType.DataSource     = AnimalCollection.FetchAll();
            ddlAnimalType.DataValueField = "AnimalId";
            ddlAnimalType.DataTextField  = "AnimalName";
            ddlAnimalType.DataBind();
            ddlAnimalType.Items.Insert(0, new ListItem(ProductsStrings.GetText("Choose"), "0"));


            ddlCategory.DataSource     = CategoryCollection.FetchAll();
            ddlCategory.DataValueField = "CategoryId";
            ddlCategory.DataTextField  = "CategoryName";
            ddlCategory.DataBind();
            ddlCategory.Items.Insert(0, new ListItem(ProductsStrings.GetText("Choose"), "0"));

            ddlSubCategory.Items.Insert(0, new ListItem(ProductsStrings.GetText("Choose"), "0"));
        }
        ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);

        scriptManager.RegisterPostBackControl(this.btnExport);
    }
Exemple #13
0
    protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        List <int> LstDays = new List <int>();

        if (ddlyear.SelectedValue == "0" || ddlMonth.SelectedValue == "0")
        {
            Master.MessageCenter.DisplayErrorMessage(SupplierProfileStrings.GetText("ChooseYearOrMonth"));
            return;
        }
        DateTime Date = new DateTime(Convert.ToInt32(ddlyear.SelectedValue), Convert.ToInt32(ddlMonth.SelectedValue), 1);

        for (int i = 1; i <= DateTime.DaysInMonth(Convert.ToInt32(ddlyear.SelectedValue), Convert.ToInt32(ddlMonth.SelectedValue)); i++)
        {
            LstDays.Add(i);
        }
        ddlDayFrom.DataSource = LstDays;
        ddlDayFrom.DataBind();
        ddlDayFrom.Items.Insert(0, new ListItem(ProductsStrings.GetText("Choose"), "0"));
        ddlDayFrom.Enabled  = true;
        ddlDayTo.DataSource = LstDays;
        ddlDayTo.DataBind();
        ddlDayTo.Items.Insert(0, new ListItem(ProductsStrings.GetText("Choose"), "0"));
        ddlDayTo.Enabled = true;
    }
 protected void Page_Init(object sender, EventArgs e)
 {
     HasEditPermission = Permissions.PermissionsForUser(SessionHelper.UserId()).Contains(Permissions.PermissionKeys.sys_perm);
     Master.AddButtonNew(ProductsStrings.GetText(@"NewProductButton"), @"EditProduct.aspx?New=yes", new string[] { Permissions.PermissionKeys.sys_perm });
     dgProducts.PageIndexChanged += dgProducts_PageIndexChanged;
 }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     Master.PageTitleHtml = string.Format(ProductsStrings.GetText(@"SupplierProductsPageTitle"), AppSupplier.FetchByID(SupplierId).BusinessName);
     Master.ActiveMenu    = "Suppliers";
 }
Exemple #16
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }
        bool result = false;

        string[] arr = hfProductIds.Value.Split(',');

        foreach (DataGridItem item in dgProducts.Items)
        {
            object obj = dgProducts.DataKeys[item.ItemIndex];
            if (obj != null && !arr.Contains(obj.ToString()))
            {
                continue;
            }
            CheckBox cb        = item.FindControl("cbIsExist") as CheckBox;
            TextBox  txtGift   = item.FindControl("txtGift") as TextBox;
            TextBox  txtPrice  = item.FindControl("txtPrice") as TextBox;
            Int64    ProductId = obj != null?Convert.ToInt64(obj) : 0;

            SupplierProduct sp = SupplierProduct.FetchByID(SuppliersSessionHelper.SupplierId(), ProductId);
            if (sp != null && cb != null && cb.Checked)
            {
                if (txtGift != null)
                {
                    sp.Gift = txtGift.Text;
                }
                if (txtPrice != null && !String.IsNullOrEmpty(txtPrice.Text))
                {
                    sp.Price = Convert.ToDecimal(txtPrice.Text);
                }
                if (sp.Price > 0)
                {
                    sp.Save();
                    result = true;
                    check_price_deviation(sp);
                }
            }
            else if (sp == null && cb != null && cb.Checked)
            {
                sp = new SupplierProduct();
                if (txtGift != null)
                {
                    sp.Gift = txtGift.Text;
                }
                if (txtPrice != null && !String.IsNullOrEmpty(txtPrice.Text))
                {
                    sp.Price = Convert.ToDecimal(txtPrice.Text);
                }
                sp.SupplierId = SuppliersSessionHelper.SupplierId();
                sp.ProductId  = ProductId;
                sp.CreateDate = DateTime.UtcNow;
                sp.Save();
                result = true;
                check_price_deviation(sp);
            }
            else if (sp != null && cb != null && !cb.Checked)
            {
                SupplierProduct.Delete(SuppliersSessionHelper.SupplierId(), ProductId);
                result = true;
            }
        }
        if (result)
        {
            Master.MessageCenter.DisplaySuccessMessage(ProductsStrings.GetText("SaveSuccess"));
        }
        LoadItem();
    }
Exemple #17
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            if (CsvDataTable != null)
            {
                int count = 0;
                try
                {
                    foreach (DataRow productRow in CsvDataTable.Rows)
                    {
                        if (productRow["Comments"].ToString() == "")
                        {
                            Product product = null;
                            if (productRow["ProductCode"].ToString() != "")
                            {
                                product = Product.FetchByCode(productRow["ProductCode"].ToString());
                            }
                            if (product == null && productRow["ProductNum"].ToString() != "")
                            {
                                product = Product.FetchByProductNum(Convert.ToInt64(productRow["ProductNum"]));
                            }

                            if (product == null)
                            {
                                product = new Product();
                            }

                            product.ProductCode     = productRow["ProductCode"].ToString();
                            product.ProductNum      = productRow["ProductNum"].ToString() == "" ? (Int64?)null : Convert.ToInt64(productRow["ProductNum"]);
                            product.ProductImage    = "";
                            product.ProductName     = productRow["ProductName"].ToString();
                            product.Amount          = productRow["Amount"] != null ? productRow["Amount"].ToString() : "";
                            product.Description     = productRow["Description"] != null ? productRow["Description"].ToString() : "";
                            product.CategoryId      = Category.FetchByID(productRow["CategoryId"].ToString()).CategoryId;
                            product.SubCategoryId   = SubCategory.FetchByID(Int64.Parse(productRow["SubCategoryId"].ToString()), product.CategoryId).SubCategoryId;
                            product.IsDeleted       = false;
                            product.RecomendedPrice = productRow["RecomendedPrice"] == null ? 0 : Convert.ToDecimal(productRow["RecomendedPrice"].ToString());
                            product.Save();

                            string        animals = productRow["AnimalType"].ToString();
                            List <string> result  = animals.Split(',').ToList();
                            foreach (string animal in result)
                            {
                                ProductAnimal productAnimal = new ProductAnimal();
                                productAnimal.ProductId = product.ProductId;
                                productAnimal.AnimalId  = Animal.FetchByName(animal.Trim()).AnimalId;
                                productAnimal.Save();
                            }
                            count++;
                        }
                    }
                    lblImportResult.Text = ProductsStrings.GetText(@"MessageImportSuccess");
                }
                catch
                {
                    lblImportResult.Text = ProductsStrings.GetText(@"MessageImportFailedUnknown");
                }
                phImportResult.Visible = true;
                lblTotalImported.Text  = count.ToString();
                btnImport.Enabled      = false;
                phErrors.Visible       = false;
                phProductsList.Visible = false;
            }
        }
 protected void Page_Init(object sender, EventArgs e)
 {
     Master.AddButtonNew(ProductsStrings.GetText(@"NewProductButton"), @"EditProduct.aspx?New=yes", new string[] { Permissions.PermissionKeys.sys_perm });
 }
Exemple #19
0
        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("ProductName", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("ProductCode", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("ProductNum", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("Amount", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("RecomendedPrice", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("Description", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("AnimalType", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("CategoryId", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("SubCategoryId", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("Comments", typeof(string)));

                    bool bErrors             = false;
                    int  line                = -1;
                    int  numProductsToImport = 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["ProductName"]     = _values[0] == "" ? "" : _values[0].Trim();
                            DR["ProductCode"]     = _values[1] == "" ? "" : _values[1].Trim();
                            DR["ProductNum"]      = _values[2] == "" ? "" : _values[2].Trim();
                            DR["Amount"]          = _values[3] == "" ? "" : _values[3].Trim();
                            DR["RecomendedPrice"] = _values[4] == "" ? "" : _values[4].Trim();
                            DR["Description"]     = _values[5] == "" ? "" : _values[5].Trim();
                            DR["AnimalType"]      = _values[6] == "" ? "" : _values[6].Trim();
                            DR["CategoryId"]      = _values[7] == "" ? "" : _values[7].Trim();
                            DR["SubCategoryId"]   = _values[8] == "" ? "" : _values[8].Trim();



                            if (DR["ProductCode"] == null || DR["ProductCode"].ToString() == "")
                            {
                                if (comments != "")
                                {
                                    comments += "<br />";
                                }
                                comments += ProductsStrings.GetText(@"MessageProductCodeEmpty");
                            }
                            else
                            {
                                //Code must be unique
                                if (Product.FetchByCode(DR["ProductCode"].ToString()) != null)
                                {
                                    if (comments != "")
                                    {
                                        comments += "<br />";
                                    }
                                    comments += ProductsStrings.GetText(@"MessageCodeAlreadyExists");
                                }
                            }

                            if (DR["ProductNum"] != null && DR["ProductNum"].ToString() != "")
                            {
                                string regExPattern2 = @"^\d+$";
                                System.Text.RegularExpressions.Regex pattern2 = new System.Text.RegularExpressions.Regex(regExPattern2);
                                if (!pattern2.IsMatch(DR["ProductNum"].ToString()))
                                {
                                    if (comments != "")
                                    {
                                        comments += "<br />";
                                    }
                                    comments += ProductsStrings.GetText(@"ProductNumInvalid");
                                }
                                //product num must be unique
                                else if (Product.FetchByProductNum(Convert.ToInt64(DR["ProductNum"])) != null)
                                {
                                    if (comments != "")
                                    {
                                        comments += "<br />";
                                    }
                                    comments += ProductsStrings.GetText(@"ProductNumAlreadyExists");
                                }
                            }

                            if (DR["ProductName"] == null || DR["ProductName"].ToString() == "")
                            {
                                if (comments != "")
                                {
                                    comments += "<br />";
                                }
                                comments += ProductsStrings.GetText(@"MessageProductNameEmpty");
                            }

                            if (DR["AnimalType"] == null || DR["AnimalType"].ToString() == "")
                            {
                                if (comments != "")
                                {
                                    comments += "<br />";
                                }
                                comments += ProductsStrings.GetText(@"MessageAnimalTypeEmpty");
                            }
                            else
                            {
                                string        animals = DR["AnimalType"].ToString();
                                List <string> result  = animals.Split(',').ToList();
                                foreach (string animal in result)
                                {
                                    if (Animal.FetchByName(animal.Trim()) == null)
                                    {
                                        if (comments != "")
                                        {
                                            comments += "<br />";
                                        }
                                        comments += ProductsStrings.GetText(@"MessageAnimalTypeDoesntExist");
                                    }
                                }
                            }
                            Category    category    = null;
                            SubCategory subCategory = null;
                            if (DR["CategoryId"] == null || DR["CategoryId"].ToString() == "")
                            {
                                if (comments != "")
                                {
                                    comments += "<br />";
                                }
                                comments += ProductsStrings.GetText(@"MessageCategoryNameEmpty");
                            }
                            else
                            {
                                category = Category.FetchByID(DR["CategoryId"].ToString());
                                if (category == null)
                                {
                                    if (comments != "")
                                    {
                                        comments += "<br />";
                                    }
                                    comments += ProductsStrings.GetText(@"MessageCategoryDoesntExists");
                                }
                            }


                            if (DR["SubCategoryId"] == null || DR["SubCategoryId"].ToString() == "")
                            {
                                if (comments != "")
                                {
                                    comments += "<br />";
                                }
                                comments += ProductsStrings.GetText(@"MessageSubCategoryNameEmpty");
                            }
                            else
                            {
                                subCategory = SubCategory.FetchByID(Int64.Parse(DR["SubCategoryId"].ToString()), Int64.Parse(DR["CategoryId"].ToString()));
                                if (subCategory == null)
                                {
                                    if (comments != "")
                                    {
                                        comments += "<br />";
                                    }
                                    comments += ProductsStrings.GetText(@"MessageSubCategoryDoesntExists");
                                }
                            }
                        }
                        catch (System.FormatException e)
                        {
                            if (comments != "")
                            {
                                comments += "<br />";
                            }
                            comments += ProductsStrings.GetText(@"MessageCategoriesOrSubCAtegoriesNotNumeric") + ": " + e.Message;
                        }
                        catch (Exception e)
                        {
                            if (comments != "")
                            {
                                comments += "<br />";
                            }
                            comments += ProductsStrings.GetText(@"MessageLineParsingError") + ": " + e.Message;
                        }

                        if (comments != "")
                        {
                            bErrors   = true;
                            comments += "<br />" + ProductsStrings.GetText(@"MessageProductsWillNotImported");
                        }
                        else
                        {
                            numProductsToImport++;
                        }

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

                        _values = csv.ReadRow();
                    }

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

                    dgProducts.DataSource = CsvDataTable;
                    dgProducts.DataBind();
                    lblTotal.Text         = CsvDataTable.Rows.Count.ToString();
                    lblTotalToImport.Text = numProductsToImport.ToString();
                    btnImport.Enabled     = numProductsToImport == 0 ? false : true;
                }
            }
        }
        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("ProductName", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("ProductCode", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("Amount", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("RecomendedPrice", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("Description", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("AnimalType", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("Price", typeof(string)));
                    //CsvDataTable.Columns.Add(new DataColumn("CategoryId", typeof(string)));
                    //CsvDataTable.Columns.Add(new DataColumn("SubCategoryId", typeof(string)));
                    CsvDataTable.Columns.Add(new DataColumn("Comments", typeof(string)));

                    bool bErrors             = false;
                    int  line                = -1;
                    int  numProductsToImport = 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["ProductName"] = _values[0] == "" ? "" : _values[0].Trim();
                            DR["ProductCode"] = _values[1] == "" ? "" : _values[1].Trim();
                            //DR["ProductNum"] = _values[2] == "" ? "" : _values[2].Trim();
                            DR["Amount"]          = _values[2] == "" ? "" : _values[2].Trim();
                            DR["RecomendedPrice"] = _values[3] == "" ? "" : _values[3].Trim();
                            DR["Description"]     = _values[4] == "" ? "" : _values[4].Trim();
                            DR["AnimalType"]      = _values[5] == "" ? "" : _values[5].Trim();
                            DR["Price"]           = _values[6] == "" ? "" : _values[6].Trim();


                            if (DR["ProductCode"] == null || DR["ProductCode"].ToString() == "")
                            {
                                comments = ProductsStrings.GetText(@"MessageProductCodeEmpty");
                            }
                            else
                            {
                                //Code must be unique
                                if (Product.FetchByCode(DR["ProductCode"].ToString()) != null)
                                {
                                    Product prod = Product.FetchByCode(DR["ProductCode"].ToString());
                                    if (SupplierProduct.FetchByID(SuppliersSessionHelper.SupplierId(), prod.ProductId) != null)
                                    {
                                        //Update
                                        if (DR["Price"] == null || DR["Price"].ToString() == "")
                                        {
                                            //delete from SupplierProduct
                                            comments = ProductsStrings.GetText(@"MessageCodeRemoveProductFromSupplier");//MessageCodeRemoveProductFromSupplier
                                            numProductsToImport++;
                                        }
                                        else //Update price

                                        {
                                            comments = ProductsStrings.GetText(@"MessageCodeUppdatePriceInSupplier");
                                            numProductsToImport++;
                                        }
                                    }
                                    else
                                    {
                                        //insert
                                        if (DR["Price"] == null || DR["Price"].ToString() == "")
                                        {
                                            //if (comments != "") comments += "<br />";
                                            comments = ProductsStrings.GetText(@"MessageCodeNotInsertProductToSupplierMissingPrice");
                                        }
                                        else
                                        {
                                            comments = ProductsStrings.GetText(@"MessageCodeInsertProductToSupplier");
                                            numProductsToImport++;
                                        }
                                    }
                                }
                            }
                        }

                        catch (Exception e)
                        {
                            comments = ProductsStrings.GetText(@"MessageLineParsingError") + ": " + e.Message;
                        }

                        //if (comments != "")
                        //{
                        //    bErrors = true;
                        //    comments += "<br />" + ProductsStrings.GetText(@"MessageProductsWillNotImported");
                        //}
                        //else
                        //{
                        //    numProductsToImport++;
                        //}

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

                        _values = csv.ReadRow();
                    }

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

                    dgProducts.DataSource = CsvDataTable;
                    dgProducts.DataBind();
                    lblTotal.Text         = CsvDataTable.Rows.Count.ToString();
                    lblTotalToImport.Text = numProductsToImport.ToString();
                    btnImport.Enabled     = numProductsToImport == 0 ? false : true;
                }
            }
        }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     Master.PageTitle  = ProductsStrings.GetText(@"ProductsPageTitle");
     Master.ActiveMenu = "Products";
     Master.AddClientScriptInclude(@"dgDateManager.js");
 }
Exemple #22
0
 protected void Page_PreRender(object sender, EventArgs e)
 {
     Master.PageTitleHtml = ProductsStrings.GetText(@"ImportProductsPageTitle");
     Master.ActiveMenu    = "ImportProducts";
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            Product product = null;

            if (IsNewMode)
            {
                product = new Product();
                product.SendSupplier = cbxIsSendSupplier.Checked;
                product.IsDeleted    = false;
            }
            else
            {
                product = Product.FetchByID(ProductId);
            }
            Product p = Product.FetchByCode(txtProductCode.Text);

            if (p != null && p.ProductId != ProductId)
            {
                Master.MessageCenter.DisplayErrorMessage(ProductsStrings.GetText(@"ProductCodeAlreadyExists"));
                return;
            }
            if (txtProductNum.Text != "")
            {
                Product p1 = Product.FetchByProductNum(Convert.ToInt64(txtProductNum.Text));
                if (p1 != null && p1.ProductId != ProductId)
                {
                    Master.MessageCenter.DisplayErrorMessage(ProductsStrings.GetText(@"ProductNumAlreadyExists"));
                    return;
                }
                else
                {
                    product.ProductNum = Convert.ToInt64(txtProductNum.Text);
                }
            }
            else
            {
                product.ProductNum = null;
            }
            product.ProductName     = txtProductName.Text;
            product.ProductCode     = txtProductCode.Text;
            product.Amount          = txtProductAmount.Text;
            product.Description     = txtProductDescription.Text;
            product.CategoryId      = Convert.ToInt64(ddlCategory.SelectedValue);
            product.SubCategoryId   = Convert.ToInt64(ddlSubCategory.SelectedValue);
            product.RecomendedPrice = txtRecomendedPrice.Text.Trim() != "" ? Convert.ToDecimal(txtRecomendedPrice.Text.Trim()) : 0;
            if (fuImage.HasFile)
            {
                if (!IsNewMode)
                {
                    MediaUtility.DeleteImageFilePath("Product", product.ProductImage, 64, 64, 0);
                }
                string fn = MediaUtility.SaveFile(fuImage.PostedFile, "Product", 0);
                product.ProductImage = fn;
                imgImage.ImageUrl    = Snoopi.core.MediaUtility.GetImagePath("Product", product.ProductImage, 0, 64, 64);
                ImageFileHandler(fuImage, imgImage, btnDeleteImage, imgImage.ImageUrl);
            }
            else if (product.ProductImage != "" && fuImage.Visible)
            {
                MediaUtility.DeleteImageFilePath("Product", product.ProductImage, 64, 64, 0);
                product.ProductImage = "";
            }

            product.Save();
            ProductId = product.ProductId;
            int count = 0;

            foreach (ListItem item in ddlAnimalType.Items)
            {
                if (item.Selected)
                {
                    count++;
                    ProductAnimal productAnimal = ProductAnimal.FetchByID(ProductId, Convert.ToInt64(item.Value));
                    if (productAnimal == null)
                    {
                        productAnimal           = new ProductAnimal();
                        productAnimal.ProductId = ProductId;
                        productAnimal.AnimalId  = Convert.ToInt64(item.Value);
                        productAnimal.Save();
                    }
                }
                else
                {
                    ProductAnimal.Delete(ProductId, Convert.ToInt64(item.Value));
                }
            }
            int index = 0;

            //save filters
            foreach (GridViewRow row in gvFilters.Rows)
            {
                Int64        FilterId = Int64.Parse(gvFilters.DataKeys[index].Value.ToString());
                CheckBoxList lsbx     = (CheckBoxList)row.FindControl("ddlSubFilter");

                foreach (ListItem item in lsbx.Items)
                {
                    ProductFilter productFilter = ProductFilter.FetchByID(ProductId, FilterId, Convert.ToInt64(item.Value));
                    if (productFilter == null && item.Selected)
                    {
                        productFilter             = new ProductFilter();
                        productFilter.ProductId   = ProductId;
                        productFilter.FilterId    = FilterId;
                        productFilter.SubFilterId = Convert.ToInt64(item.Value);
                        productFilter.Save();
                    }
                    else if (productFilter != null && !item.Selected)
                    {
                        (new Query(ProductFilter.TableSchema).Where(ProductFilter.Columns.ProductId, productFilter.ProductId)
                         .AddWhere(ProductFilter.Columns.FilterId, productFilter.FilterId)
                         .AddWhere(ProductFilter.Columns.SubFilterId, productFilter.SubFilterId).Delete()).Execute();
                    }
                }
                index++;
            }

            if (IsNewMode)
            {
                if (cbxIsSendSupplier.Checked)
                {
                    EmailMessagingService.SendEmailNewProductToSupplier(product);
                }
                string successMessage = ProductsStrings.GetText(@"MessageProductCreated");
                string url            = @"EditProduct.aspx?ProductId=" + ProductId;
                url += @"&message-success=" + Server.UrlEncode(successMessage);
                Response.Redirect(url, true);
            }
            else
            {
                string successMessage = ProductsStrings.GetText(@"MessageProductSaved");
                Master.MessageCenter.DisplaySuccessMessage(successMessage);
            }
        }
        protected void btnImport_Click(object sender, EventArgs e)
        {
            if (CsvDataTable != null)
            {
                int count = 0;
                try
                {
                    foreach (DataRow productRow in CsvDataTable.Rows)
                    {
                        if (productRow["Comments"].ToString() != "")
                        {
                            SupplierProduct suplierprod = null;
                            Product         prod        = null;
                            if ((productRow["Comments"].ToString()).Equals(ProductsStrings.GetText(@"MessageCodeRemoveProductFromSupplier")))
                            {
                                //Delete product from Supplier
                                prod = Product.FetchByCode(productRow["ProductCode"].ToString());
                                if (prod != null)
                                {
                                    suplierprod = SupplierProduct.FetchByID(SuppliersSessionHelper.SupplierId(), prod.ProductId);
                                    if (suplierprod != null)
                                    //delete
                                    {
                                        SupplierProduct.Delete(SuppliersSessionHelper.SupplierId(), suplierprod.ProductId);
                                        count++;
                                    }
                                }
                            }

                            else if ((productRow["Comments"].ToString()).Equals(ProductsStrings.GetText(@"MessageCodeInsertProductToSupplier")))
                            {
                                //Insert product to supplier
                                prod = Product.FetchByCode(productRow["ProductCode"].ToString());
                                if (prod != null)
                                {
                                    if (!ProductController.IsSupplierProduct(prod.ProductId, SuppliersSessionHelper.SupplierId()))
                                    {
                                        SupplierProduct sp = new SupplierProduct();
                                        sp.SupplierId = SuppliersSessionHelper.SupplierId();
                                        sp.ProductId  = prod.ProductId;
                                        sp.CreateDate = DateTime.UtcNow;
                                        sp.Price      = Convert.ToDecimal(productRow["Price"]);
                                        sp.Gift       = "";
                                        sp.Save();
                                        check_price_deviation(sp);
                                        count++;
                                    }
                                }
                            }
                            else if ((productRow["Comments"].ToString()).Equals(ProductsStrings.GetText(@"MessageCodeUppdatePriceInSupplier")))
                            {
                                //Update price
                                prod = Product.FetchByCode(productRow["ProductCode"].ToString());
                                if (prod != null)
                                {
                                    if (ProductController.IsSupplierProduct(prod.ProductId, SuppliersSessionHelper.SupplierId()))
                                    {
                                        SupplierProduct sp = new SupplierProduct();
                                        sp.SupplierId = SuppliersSessionHelper.SupplierId();
                                        sp.Price      = Convert.ToDecimal(productRow["Price"]);
                                        sp.ProductId  = prod.ProductId;
                                        sp.CreateDate = DateTime.UtcNow;
                                        sp.Gift       = "";
                                        sp.Update();
                                        check_price_deviation(sp);
                                        count++;
                                    }
                                }
                            }
                        }
                    }

                    lblImportResult.Text = ProductsStrings.GetText(@"MessageImportSuccess");
                }
                catch (Exception ex)
                {
                    lblImportResult.Text = ProductsStrings.GetText(@"MessageImportFailedUnknown");
                }

                phImportResult.Visible = true;
                lblTotalImported.Text  = count.ToString();
                btnImport.Enabled      = false;
                //   btnAcceptFile.Visible = false;
                phErrors.Visible       = false;
                phProductsList.Visible = false;
            }
        }
        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 = string.Format(ProductsStrings.GetText(@"DeleteProductPageTitle"), ProductName);
     Master.ActiveMenu    = "Products";
 }