Ejemplo n.º 1
0
 protected void btnUploadDealer_Click(object sender, EventArgs e)
 {
     if (fDealerUpload.HasFile)
     {
         lblError.Text = "";
         string extension = System.IO.Path.GetExtension(fDealerUpload.PostedFile.FileName);
         if (extension.ToLower() == ".csv")
         {
             string fileName     = "csv_" + DateTime.Now.Ticks + "_" + fDealerUpload.FileName;
             string fileNamePath = Server.MapPath(LWGUtils.GetCSVPath()) + fileName;
             fDealerUpload.SaveAs(fileNamePath);
             List <lwg_Dealer> dealerList = ParseCSVFileToDealerList(fileNamePath);
             DealerBiz         dealerBiz  = new DealerBiz();
             dealerBiz.SaveDealerFromList(dealerList);
         }
         else
         {
             lblError.Text = "Invalid extension.";
         }
     }
     else
     {
         lblError.Text = "Please choose upload file";
     }
 }
Ejemplo n.º 2
0
        private void BindGrid()
        {
            string name    = txtSearchName.Text.Trim();
            string address = txtSearchAddress.Text.Trim();
            string id      = txtSearchID.Text.Trim();

            dealerBiz           = new DealerBiz();
            gvDealer.DataSource = dealerBiz.GetAllDealersBySearch(id, name, address);
            gvDealer.DataBind();
        }
Ejemplo n.º 3
0
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     if (dealerBiz == null)
     {
         dealerBiz = new DealerBiz();
     }
     if (dealerBiz.DeleteDealer(DealerID))
     {
         Response.Redirect("dealer.aspx");
     }
 }
Ejemplo n.º 4
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (dealerBiz == null)
                {
                    dealerBiz = new DealerBiz();
                }

                if (dealerBiz.IsDealerExist(txtCustomerID.Text.Trim()))
                {
                    lblAddNewError.Text = GetLocaleResourceString("Dealer.DealerIDExistMessage");
                    return;
                }

                lwg_Dealer newDealer = new lwg_Dealer();
                newDealer.DealerID     = txtCustomerID.Text.Trim();
                newDealer.AddressLine1 = txtAddress1.Text.Trim();
                newDealer.AddressLine2 = txtAddress2.Text.Trim();
                newDealer.City         = txtCity.Text.Trim();
                newDealer.Contact      = txtContact.Text.Trim();
                newDealer.Fax          = txtFax.Text.Trim();
                newDealer.Name         = txtName.Text.Trim();
                newDealer.NewIssue     = txtNewIssue.Text.Trim();
                newDealer.Phone        = txtPhone.Text.Trim();
                if (ddlUSState.SelectedValue == "00")
                {
                    newDealer.State = txtState.Text.Trim();
                }
                else
                {
                    newDealer.State = ddlUSState.SelectedValue;
                }
                newDealer.WebAddress    = txtWebAddress.Text.Trim();
                newDealer.Zip           = txtZip.Text.Trim();
                newDealer.AddressSearch = string.Format("{0} {1} {2} {3} {4}", txtAddress1.Text.Trim(), txtAddress2.Text.Trim(), txtCity.Text.Trim(), txtState.Text.Trim(), txtZip.Text.Trim());

                if (dealerBiz.AddDealer(newDealer))
                {
                    Response.Redirect("dealer.aspx");
                    //pnlAddNew.Visible = false;
                    //pnlAddNewMessage.Visible = true;
                }
                else
                {
                    pnlAddNew.Visible        = true;
                    pnlAddNewMessage.Visible = false;
                    lblAddNewError.Text      = GetLocaleResourceString("Dealer.AddFailMessage");
                }
            }
        }
Ejemplo n.º 5
0
        protected void ListDealerByState(string State)
        {
            try
            {
                DealerBiz dealerBiz = new DealerBiz();

                List <lwg_Dealer> dealers = dealerBiz.GetDealersByState(State);
                int total           = dealers.Count;
                int countEachColumn = int.Parse((Math.Ceiling((double)(total / 3.0)).ToString()));
                this.ltrDealers1.Text = this.CreateHtml(dealers.Take(countEachColumn).ToList(), State, true);
                this.ltrDealers2.Text = this.CreateHtml(dealers.Skip(countEachColumn).Take(countEachColumn).ToList(), State, false);
                this.ltrDealers3.Text = this.CreateHtml(dealers.Skip(countEachColumn * 2).Take(countEachColumn).ToList(), State, false);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
Ejemplo n.º 6
0
        protected void ListDealerByFirstLetter(string FirstLetter)
        {
            try
            {
                DealerBiz pb = new DealerBiz();

                List <lwg_Dealer> dealers = pb.GetDealersByFirstLetter(FirstLetter);
                int total           = dealers.Count;
                int countEachColumn = int.Parse((Math.Ceiling((double)(total / 2.5)).ToString()));
                this.ltrDealers1.Text = this.CreateHtml(dealers.Take(countEachColumn).ToList(), FirstLetter, true);
                this.ltrDealers2.Text = this.CreateHtml(dealers.Skip(countEachColumn).Take(countEachColumn).ToList(), FirstLetter, false);
                this.ltrDealers3.Text = this.CreateHtml(dealers.Skip(countEachColumn * 2).Take(countEachColumn).ToList(), FirstLetter, false);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
Ejemplo n.º 7
0
        private void LoadDetail()
        {
            lblError.Text   = string.Empty;
            lblSuccess.Text = string.Empty;
            if (Session["DealerUpdateSuccess"] != null)
            {
                lblSuccess.Text = Session["DealerUpdateSuccess"].ToString();
                Session.Remove("DealerUpdateSuccess");
            }
            dealerBiz = new DealerBiz();
            lwg_Dealer dealer = dealerBiz.GetDealerByDealerID(DealerID);

            if (dealer != null)
            {
                txtDealerID.Text = dealer.DealerID;
                txtAddress1.Text = dealer.AddressLine1;
                txtAddress2.Text = dealer.AddressLine2;
                txtCity.Text     = dealer.City;
                txtContact.Text  = dealer.Contact;
                txtFax.Text      = dealer.Fax;
                txtPhone.Text    = dealer.Phone;
                if (ddlUSState.Items.FindByValue(dealer.State) != null)
                {
                    ddlUSState.Items.FindByValue(dealer.State).Selected = true;
                    txtState.Text    = string.Empty;
                    txtState.Visible = false;
                }
                else
                {
                    ddlUSState.Items.FindByValue("00").Selected = true;
                    txtState.Text = dealer.State;
                }

                txtWebAddress.Text = dealer.WebAddress;
                txtZip.Text        = dealer.Zip;
                txtNewIssue.Text   = dealer.NewIssue;
                txtName.Text       = dealer.Name;
            }
            else
            {
                Response.Redirect("Dealer.aspx");
            }
        }
Ejemplo n.º 8
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                dealerBiz = new DealerBiz();
                foreach (GridViewRow row in gvDealer.Rows)
                {
                    var cbDealer   = row.FindControl("cbDealer") as CheckBox;
                    var hfDealerId = row.FindControl("hfDealerId") as HiddenField;

                    bool isChecked = cbDealer.Checked;
                    if (isChecked)
                    {
                        dealerBiz.DeleteDealer(hfDealerId.Value);
                    }
                }

                BindGrid();
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
Ejemplo n.º 9
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (dealerBiz == null)
                {
                    dealerBiz = new DealerBiz();
                }
                lwg_Dealer dealer = dealerBiz.GetDealerByDealerID(DealerID);
                lblError.Text   = string.Empty;
                lblSuccess.Text = string.Empty;
                bool updateNewID = false;

                if (txtDealerID.Text.Trim() != DealerID && dealerBiz.IsDealerExist(txtDealerID.Text.Trim()))
                {
                    lblError.Text = GetLocaleResourceString("Dealer.DealerIDExistMessage");
                    return;
                }
                else
                if (txtDealerID.Text.Trim() != DealerID && !dealerBiz.IsDealerExist(txtDealerID.Text.Trim()))  // new id
                {
                    updateNewID = true;
                }
                if (dealer != null)
                {
                    dealer.AddressLine1 = txtAddress1.Text.Trim();
                    dealer.AddressLine2 = txtAddress2.Text.Trim();
                    dealer.City         = txtCity.Text.Trim();
                    dealer.Contact      = txtContact.Text.Trim();
                    dealer.Fax          = txtFax.Text.Trim();
                    dealer.Name         = txtName.Text.Trim();
                    dealer.NewIssue     = txtNewIssue.Text.Trim();
                    dealer.Phone        = txtPhone.Text.Trim();
                    if (ddlUSState.SelectedValue == "00")
                    {
                        dealer.State = txtState.Text.Trim();
                    }
                    else
                    {
                        dealer.State = ddlUSState.SelectedValue;
                    }
                    dealer.WebAddress    = txtWebAddress.Text.Trim();
                    dealer.Zip           = txtZip.Text.Trim();
                    dealer.AddressSearch = string.Format("{0} {1} {2} {3} {4}", txtAddress1.Text.Trim(), txtAddress2.Text.Trim(), txtCity.Text.Trim(), txtState.Text.Trim(), txtZip.Text.Trim());

                    bool updateSuccess;
                    if (updateNewID)
                    {
                        updateSuccess = dealerBiz.UpdateDealer(dealer, txtDealerID.Text.Trim());
                    }
                    else
                    {
                        updateSuccess = dealerBiz.UpdateDealer(dealer, string.Empty);
                    }

                    if (updateSuccess)
                    {
                        if (updateNewID)
                        {
                            Session["DealerUpdateSuccess"] = GetLocaleResourceString("Dealer.UpdateSuccessMessage");
                            Response.Redirect(string.Format("dealerdetails.aspx?dealerid={0}", txtDealerID.Text.Trim()));
                        }
                        else
                        {
                            lblSuccess.Text = GetLocaleResourceString("Dealer.UpdateSuccessMessage");
                        }
                    }
                    else
                    {
                        lblError.Text = GetLocaleResourceString("Dealer.UpdateFailMessage");
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private void ListDealers(DealerSortType sortType)
        {
            try
            {
                String[] htmlStr = new String[3];

                DealerBiz dealerBiz = new DealerBiz();
                int       total     = 0;
                lblOutOfUS.Visible = false;
                // List composers by 3 columns
                int currentControlIndex = 0; // the current column index that appending composers.
                int countAppended       = 0; // the number of composers the current column had appended.
                if (sortType == DealerSortType.Name)
                {
                    #region sort by firtletter of name

                    List <lwg_Dealer> dealers = dealerBiz.GetAllDealers();
                    total = dealers.Count;

                    if (total == 0)
                    {
                        Response.Write("There is no dealer yet.");
                    }

                    int countEachColumn = 0;

                    countEachColumn = int.Parse((Math.Ceiling((double)(total / columnRatio)).ToString()));

                    int maxGroupCount = MaxFirstLetterGroup(dealers);  // The max group items count.
                    if (maxGroupCount > countEachColumn)
                    {
                        countEachColumn = maxGroupCount;
                    }


                    for (int i = 65; i < 91; i++)
                    {
                        string            firstLetter = Chr(i);
                        List <lwg_Dealer> subDealers  = FilterDealerByFirstLetter(dealers, firstLetter);
                        int subCount = subDealers.Count;
                        if (subCount > 0)
                        {
                            if (subCount >= countEachColumn)
                            {
                                if (currentControlIndex >= 1 && currentControlIndex <= 2)
                                {
                                    currentControlIndex += 1;
                                }
                                htmlStr[currentControlIndex] += CreateHtml(subDealers, firstLetter, true);
                                countAppended = countEachColumn;
                            }
                            else if (subCount + 1 > countEachColumn - countAppended)
                            {
                                if (currentControlIndex < 2)
                                {
                                    currentControlIndex += 1;
                                }

                                // Generate html
                                htmlStr[currentControlIndex] += CreateHtml(subDealers, firstLetter, true);

                                countAppended = subCount + 1;
                            }
                            else
                            {
                                htmlStr[currentControlIndex] += CreateHtml(subDealers, firstLetter, true);
                                countAppended += subCount + 1;
                            }
                        }
                    }
                    this.ltrDealers1.Text = htmlStr[0];
                    this.ltrDealers2.Text = htmlStr[1];
                    this.ltrDealers3.Text = htmlStr[2];
                    #endregion
                }
                else
                {
                    #region  sort by state
                    lblOutOfUS.Visible = true;
                    #region US Dealers
                    List <lwg_Dealer> dealers = dealerBiz.GetAllUSDealers();
                    total = dealers.Count;

                    if (total == 0)
                    {
                        Response.Write("There is no dealer yet.");
                    }

                    int countEachColumn = 0;

                    countEachColumn = int.Parse((Math.Ceiling((double)(total / columnRatio)).ToString()));

                    int maxGroupCount = MaxStateGroup(dealers);  // The max group items count.
                    if (maxGroupCount > countEachColumn)
                    {
                        countEachColumn = maxGroupCount;
                    }

                    List <string> stateList = dealerBiz.GetAllStateOfUS();
                    foreach (string state in stateList)
                    {
                        List <lwg_Dealer> subDealers = FilterDealerByState(dealers, state);
                        int subCount = subDealers.Count;
                        if (subCount > 0)
                        {
                            if (subCount >= countEachColumn)
                            {
                                if (currentControlIndex >= 1 && currentControlIndex <= 2)
                                {
                                    currentControlIndex += 1;
                                }
                                htmlStr[currentControlIndex] += CreateHtml(subDealers, state, true);
                                countAppended = countEachColumn;
                            }
                            else if (subCount + 1 > countEachColumn - countAppended + 5)
                            {
                                if (currentControlIndex < 2)
                                {
                                    currentControlIndex += 1;
                                }

                                // Generate html
                                htmlStr[currentControlIndex] += CreateHtml(subDealers, state, true);

                                countAppended = subCount + 1;
                            }
                            else
                            {
                                htmlStr[currentControlIndex] += CreateHtml(subDealers, state, true);
                                countAppended += subCount + 1;
                            }
                        }
                    }

                    this.ltrDealers1.Text = htmlStr[0];
                    this.ltrDealers2.Text = htmlStr[1];
                    this.ltrDealers3.Text = htmlStr[2];
                    #endregion
                    #region Out of US Dealers
                    dealers = dealerBiz.GetAllOutOfUSDealers();
                    total   = dealers.Count;

                    if (total == 0)
                    {
                        return;
                    }

                    htmlStr             = new String[3];
                    countEachColumn     = 0;
                    countAppended       = 0;
                    currentControlIndex = 0;
                    countEachColumn     = int.Parse((Math.Ceiling((double)(total / columnRatio)).ToString()));

                    stateList = dealerBiz.GetAllStateOutOfUS();
                    foreach (string state in stateList)
                    {
                        List <lwg_Dealer> subDealers = FilterDealerByState(dealers, state);
                        int subCount = subDealers.Count;
                        if (subCount > 0)
                        {
                            if (subCount >= countEachColumn)
                            {
                                if (currentControlIndex >= 1 && currentControlIndex <= 2)
                                {
                                    currentControlIndex += 1;
                                }
                                htmlStr[currentControlIndex] += CreateHtml(subDealers, state, true);
                                countAppended = countEachColumn;
                            }
                            else if (subCount + 1 > countEachColumn - countAppended + 5)
                            {
                                if (currentControlIndex < 2)
                                {
                                    currentControlIndex += 1;
                                }

                                // Generate html
                                htmlStr[currentControlIndex] += CreateHtml(subDealers, state, true);

                                countAppended = subCount + 1;
                            }
                            else
                            {
                                htmlStr[currentControlIndex] += CreateHtml(subDealers, state, true);
                                countAppended += subCount + 1;
                            }
                        }
                    }
                    this.ltrDealers4.Text = htmlStr[0];
                    this.ltrDealers5.Text = htmlStr[1];
                    this.ltrDealers6.Text = htmlStr[2];
                    #endregion
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
Ejemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadSortType();

                if (!string.IsNullOrEmpty(Request.QueryString["Filter"]))
                {
                    string alpha = "";
                    alpha          = Request.QueryString["Filter"];
                    hdfalpha.Value = alpha;
                    string FirstLetter      = Request.QueryString["Filter"].ToUpper();
                    int    FirstLetterASCII = Asc(FirstLetter);
                    if (FirstLetterASCII >= 65 && FirstLetterASCII <= 90)
                    {
                        ListDealerByFirstLetter(FirstLetter);
                        ddlSortType.ClearSelection();
                        ddlSortType.Items.FindByText("Name").Selected = true;
                        divAlphabet.Visible = true;
                        divState.Visible    = false;
                        return;
                    }
                }

                if (!string.IsNullOrEmpty(Request.QueryString["State"]))
                {
                    string state = string.Empty;
                    state = Request.QueryString["State"].ToUpper();
                    DealerBiz dealerBiz = new DealerBiz();
                    if (dealerBiz.IsExistState(state))
                    {
                        ListDealerByState(state);
                        ddlSortType.ClearSelection();
                        ddlSortType.Items.FindByText("State").Selected = true;

                        divState.Visible     = true;
                        divAlphabet.Visible  = false;
                        ltrStateMenu.Text    = CreateSelectionStateMenu(dealerBiz.GetAllStateOfUS(), state, false);
                        ltrOutofUsState.Text = CreateSelectionStateMenu(dealerBiz.GetAllStateOutOfUS(), state, true);
                        return;
                    }
                    else
                    if (state.ToLower() == allStatesOfUS)
                    {
                        ListDealers(DealerSortType.State);
                        ddlSortType.ClearSelection();
                        ddlSortType.Items.FindByText("State").Selected = true;
                        divState.Visible     = true;
                        divAlphabet.Visible  = false;
                        ltrStateMenu.Text    = CreateSelectionStateMenu(dealerBiz.GetAllStateOfUS(), state.ToLower(), false);
                        ltrOutofUsState.Text = CreateSelectionStateMenu(dealerBiz.GetAllStateOutOfUS(), state.ToLower(), true);
                        return;
                    }
                }


                // default load all dealer
                ListDealers(DealerSortType.Name);
                divAlphabet.Visible = true;
                divState.Visible    = false;
            }
        }