Пример #1
0
        protected void btnimport_OnClick(object sender, EventArgs e)
        {
            StreamReader reader = null;
            string path = HttpContext.Current.Server.MapPath(WebConfigurationManager.AppSettings["attachmentPath"] +
                                                              "/tempCSV/");
            try
            {
                FileUpload customerCSV = new FileUpload();
                customerCSV = FileUpload1;

                if (customerCSV.HasFile)
                {
                    string chkExtension = Path.GetExtension(customerCSV.FileName);
                    // string ppImg = ImgID + Path.GetExtension(productImg.FileName);

                    if (chkExtension.ToLower() == ".csv")
                    {


                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        String userId = LumexSessionManager.Get("ActiveUserId").ToString();
                        path = path + @"\cr" + userId + ".csv";

                        customerCSV.PostedFile.SaveAs(path);


                        //need to implement here.
                        reader = new StreamReader(File.OpenRead(path));
                        int linecount = 0;
                        //int dupcount = 0;
                        while (!reader.EndOfStream)
                        {

                            var line = reader.ReadLine();
                            if (linecount != 0)
                            {
                                var pinfos = line.Split(',');
                                CustomerBLL customer = new CustomerBLL();


                                customer.CustomerName = pinfos[0];
                                customer.ContactNumber = pinfos[1];
                                customer.Email = pinfos[2];
                                customer.Country = "";

                                customer.District = "";
                                customer.PostalCode = "";

                                customer.NationalId = "";
                                customer.PassportNumber = "";
                                customer.JoiningSalesCenterId = pinfos[3];
                                customer.City = pinfos[4];



                                customer.Address = pinfos[5];
                                DataTable dt = customer.SaveCustomer();
                                //dupcount++;                            }


                            }
                            linecount++;

                            //reader.Close();

                        }
                        linecount--;
                        if (linecount > 0)
                        {


                            string message =
                                "Customer <span class='actionTopic'></span> Successfully import " + linecount +
                                " Customers.<span class='actionTopic'></span>.";
                            MyAlertBox(
                                "var callbackOk = function () { MyOverlayStop(); window.location = \"/UI/Customer/List.aspx\"; }; SuccessAlert(\"" +
                                "Process Succeed" + "\", \"" + message + "\", callbackOk);");


                        }

                    }
                    else
                    {
                        string message = "Only CSV File is allowed";
                        MyAlertBox("WarningAlert(\"" + "Validation" + "\", \"" + message + "\");");
                    }
                }
                else
                {
                    string message = " <span class='actionTopic'>" + "You are Not select any CSV file!</span>.";
                    MyAlertBox("WarningAlert(\"" + "Validation" + "\", \"" + message + "\");");

                }

            }
            catch (Exception ex)
            {

                string message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += " --> " + ex.InnerException.Message;
                }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
            }

            finally
            {
                if (reader != null)
                {
                    reader.Close();
                    File.Delete(path);
                }
            }
        }
Пример #2
0
        //protected void LoadSalesCenters()
        //{
        //    SalesCenterBLL salesCenter = new SalesCenterBLL();

        //    try
        //    {
        //        DataTable dt = salesCenter.GetActiveSalesCenterList();

        //        joiningSalesCenterDropDownList.DataSource = dt;
        //        joiningSalesCenterDropDownList.DataValueField = "SalesCenterId";
        //        joiningSalesCenterDropDownList.DataTextField = "SalesCenterName";
        //        joiningSalesCenterDropDownList.DataBind();
        //        joiningSalesCenterDropDownList.Items.Insert(0, "");
        //        joiningSalesCenterDropDownList.SelectedIndex = 0;

        //        if (dt.Rows.Count < 1)
        //        {
        //            msgbox.Visible = true; msgTitleLabel.Text = "Joining Sales Center Data Not Found!!!"; msgDetailLabel.Text = "";
        //            msgbox.Attributes.Add("class", "alert alert-warning");
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        string message = ex.Message;
        //        if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
        //        MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
        //    }
        //    finally
        //    {
        //        salesCenter = null;
        //    }
        //}

        protected void saveButton_Click(object sender, EventArgs e)
        {
            CustomerBLL customer = new CustomerBLL();

            try
            {
                if (customerNameTextBox.Text == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Customer Name field is required.";
                }
                else if (addressTextBox.Text == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Address field is required.";
                }
                //else if (joiningSalesCenterDropDownList.Text == "")
                //{
                //    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Joining Sales Center field is required.";
                //}
                else
                {
                    customer.CustomerName = customerNameTextBox.Text.Trim();
                    customer.ContactNumber = contactNumberTextBox.Text.Trim();
                    customer.Email = emailTextBox.Text.Trim();
                    customer.Country = "";
                    customer.City = cityTextBox.Text.Trim();
                    customer.District = "";
                    customer.PostalCode = "";
                    customer.Address = addressTextBox.Text.Trim();
                    customer.NationalId = ""; //nationalIdTextBox.Text.Trim();
                    customer.PassportNumber = "";//passportNumberTextBox.Text.Trim();
                    customer.JoiningSalesCenterId = WarehouesDropDownList.SelectedValue.Trim();
                    customer.Description = txtbxDescription.Text.Trim();

                    DataTable dt = customer.SaveCustomer();

                    if (dt.Rows.Count > 0)
                    {
                        string message = "Customer <span class='actionTopic'>Created</span> Successfully with Customer ID: <span class='actionTopic'>" + dt.Rows[0][0].ToString() + "</span>.";
                        MyAlertBox("var callbackOk = function () { MyOverlayStart(); window.location = \"/UI/Customer/crateRetail.aspx\"; }; SuccessAlert(\"" + "Process Succeed" + "\", \"" + message + "\", callbackOk);");
                        CleartField();
                    }
                    else
                    {
                        string message = "<span class='actionTopic'>Failed</span> to Create Customer.";
                        MyAlertBox("ErrorAlert(\"" + "Process Failed" + "\", \"" + message + "\");");
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
            }
            finally
            {
                customer = null;
            }
        }