Esempio n. 1
0
    protected void btnProceed_Click(object sender, EventArgs e)
    {
        try
        {
            Page.Validate();

            if (Page.IsValid)
            {
                bool            isQtyEntered   = false;
                TextBox         txtProductQty  = null;
                TextBox         lblProductType = null;
                TextBox         lblProductId   = null;
                RadioButtonList rdbCompanies   = null;
                Label           lblProductCode = null;
                HiddenField     hdnIsDCC       = null;

                LinqToSqlDataContext db = new LinqToSqlDataContext();
                int OrderItemId         = 0;
                int qtyCounter          = 0;

                foreach (RepeaterItem item in dlProducts.Items)
                {
                    txtProductQty  = (TextBox)item.FindControl("txtProductQty");
                    lblProductType = (TextBox)item.FindControl("lblProductType");
                    lblProductId   = (TextBox)item.FindControl("lblProductId");
                    rdbCompanies   = (RadioButtonList)item.FindControl("rdbCompanies");
                    lblProductCode = (Label)item.FindControl("lblProductCode");
                    hdnIsDCC       = (HiddenField)item.FindControl("hdnIsDCC");

                    //only display radio for ISDCC is true
                    if (Convert.ToBoolean(hdnIsDCC.Value) == true)
                    {
                        // displayManufacturerRadioButtons(rdbCompanies);
                        displayManufacturerRadioButtons(rdbCompanies, lblProductCode.Text);
                        //displayManufacturerRadioButtons(rdbCompanies, Convert.ToInt32(lblProductId.Text));
                    }

                    if (!string.IsNullOrEmpty(txtProductQty.Text) && Convert.ToInt32(txtProductQty.Text) > 0)
                    {
                        if (rdbCompanies.Visible == true && (Convert.ToBoolean(hdnIsDCC.Value) == true))
                        {
                            if (rdbCompanies.SelectedItem.Text != rdbCompanies.Items[0].Text)//added by priya
                            {
                                string companyId = (from dcc in db.DCCCompanies
                                                    where dcc.company_name == rdbCompanies.SelectedItem.Text
                                                    select dcc.company_id).SingleOrDefault();
                                if (companyId != null)
                                {
                                    string productCode = lblProductCode.Text + companyId;


                                    int productid = (from p in db.Products
                                                     where p.ProductCode == productCode
                                                     select p.ProductId).SingleOrDefault();

                                    //validation to check if the productid exists needed
                                    if (productid != 0)
                                    {
                                        lblProductId.Text = productid.ToString();
                                    }
                                    else
                                    {
                                        string script = "alertify.alert('" + ltrNotaValidProduct + "');";
                                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                                        return;
                                    }
                                }
                            }
                            else
                            {
                                string script = "alertify.alert('" + ltrSelectManufacturer.Text + "');";
                                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                                return;
                            }
                        }

                        int CategoryID = Convert.ToInt32(Request.QueryString["CategoryId"]);

                        //update product code and product id
                        var orderitem = db.USP_SaveOrderItems(Convert.ToInt32(Session[enumSessions.OrderId.ToString()].ToString()), Convert.ToInt32(lblProductId.Text), Convert.ToInt32(txtProductQty.Text), new Guid(Session[enumSessions.User_Id.ToString()].ToString()), Session[enumSessions.User_Name.ToString()].ToString(), Convert.ToInt32(Request.QueryString["CategoryId"])).SingleOrDefault();
                        if (orderitem != null)
                        {
                            if (orderitem.OrderItemId.HasValue)
                            {
                                int.TryParse(orderitem.OrderItemId.Value.ToString(), out OrderItemId);
                            }
                        }



                        if (OrderItemId != 0)
                        {
                            /* by ajitender
                             * db.USP_DeleteOrderItemDetailsByOrderItemId(OrderItemId);*/

                            List <String> CategorieswithNoChipNo = (from app in db.ApplicationSettings
                                                                    where app.KeyName == "CategorieswithNoChipNo"
                                                                    select app.KeyValue).SingleOrDefault().Split(',').ToList();


                            string GPRSNo = string.Empty;
                            if (CategorieswithNoChipNo.Contains(CategoryID.ToString()))
                            {
                                GPRSNo = "0000";
                            }

                            for (qtyCounter = 0; qtyCounter < Convert.ToInt32(txtProductQty.Text); qtyCounter++)
                            {
                                db.USP_AddOrderItemDetailsToBasket(OrderItemId, GPRSNo, "", Session[enumSessions.User_Name.ToString()].ToString());
                            }
                        }


                        isQtyEntered = true;
                    }
                }


                db.Dispose();

                if (isQtyEntered)
                {
                    Response.Redirect("Basket.aspx");
                }
                else
                {
                    string script = "alertify.alert('" + ltrEnterQntty.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    return;
                }
            }
        }
        catch (System.Threading.ThreadAbortException ex)
        {
            //
        }
        catch (Exception objException)
        {
            CSLOrderingARCBAL.LinqToSqlDataContext db;
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "btnProceed_Click", Convert.ToString(objException.Message), Convert.ToString(objException.InnerException), Convert.ToString(objException.StackTrace), "", HttpContext.Current.Request.UserHostAddress, false, Convert.ToString(HttpContext.Current.Session[enumSessions.User_Id.ToString()]));
            db.Dispose();
        }
    }