public Tuple <bool, string> AddInstallID(List <EM_InstallIDRegister> entities)
        {
            Tuple <bool, string> data = new Tuple <bool, string>(false, "");

            try
            {
                using (LinqToSqlDataContext dbContext = new LinqToSqlDataContext())
                {
                    foreach (EM_InstallIDRegister entity in entities)
                    {
                        entity.CreatedOn = DateTime.Now;
                        dbContext.EM_InstallIDRegisters.InsertOnSubmit(entity);
                    }
                    ;
                    dbContext.SubmitChanges();
                    data = new Tuple <bool, string>(true, "records added to database");
                }
            }
            catch (Exception exp)
            {
                data = new Tuple <bool, string>(false, exp.Message);
            }
            return(data);
        }
Exemple #2
0
    /// <summary>
    /// Bind All Installer's with dropdown on page load
    ///
    /// </summary>
    private void BindInstallerDropdown()
    {
        db = new LinqToSqlDataContext();
        var Installerdata = (from inst in db.Installers
                             orderby inst.CompanyName ascending
                             where inst.IsActive == true
                             select new { inst.InstallerCompanyID, InstallerDisp = inst.CompanyName + " - [" + inst.UniqueCode + "] " });

        ddlInstaller.DataValueField = "InstallerCompanyID";
        ddlInstaller.DataTextField  = "InstallerDisp";
        ddlInstaller.DataSource     = Installerdata;
        ddlInstaller.DataBind();
        ddlInstaller.Items.Insert(0, new ListItem("-----------------------------------Select-----------------------------------", "0"));

        var priceBand = (from pbn in db.BandNameMasters
                         orderby pbn.BandName ascending
                         select pbn);

        ddlPriceBandMaster.DataValueField = "ID";
        ddlPriceBandMaster.DataTextField  = "BandName";
        ddlPriceBandMaster.DataSource     = priceBand;
        ddlPriceBandMaster.DataBind();
        ddlPriceBandMaster.Items.Insert(0, new ListItem("Select", "0"));
    }
Exemple #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[enumSessions.User_Id.ToString()] == null)
        {
            Response.Redirect("Login.aspx");
        }

        InstallersPC.Visible = false;
        Installers.Visible   = false;
        int ARCId = Convert.ToInt32(Session[enumSessions.ARC_Id.ToString()]);
        LinqToSqlDataContext db  = new LinqToSqlDataContext();
        var enablePostCodeSearch = (from arc in db.ARCs
                                    where arc.ARCId == ARCId
                                    select arc.EnablePostCodeSearch).Single();

        if (enablePostCodeSearch == true)
        {
            InstallersPC.Visible = true;
        }
        else
        {
            Installers.Visible = true;
        }
    }
        /// <summary>
        /// The purpose of this to save new installer address.
        /// </summary>
        /// <param name="InstallerId"></param>
        /// <param name="ContactName"></param>
        /// <param name="contactno"></param>
        /// <param name="CountryId"></param>
        /// <param name="AddressOne"></param>
        /// <param name="AddressTwo"></param>
        /// <param name="Town"></param>
        /// <param name="County"></param>
        /// <param name="PostCode"></param>
        /// <param name="Country"></param>
        /// <param name="CreatedBy"></param>
        /// <returns></returns>
        public static int SaveInstallerAddress(string InstallerId, string ContactName, string contactno, int CountryId, string AddressOne, string AddressTwo, string Town, string County, string PostCode, string Country, string CreatedBy)
        {
            int AddressId = 0;

            try
            {
                using (LinqToSqlDataContext db = new LinqToSqlDataContext())
                {
                    var address = db.USP_SaveInstallerAddress(InstallerId, ContactName, contactno, CountryId, AddressOne, AddressTwo, Town, County, PostCode, Country, CreatedBy).SingleOrDefault();
                    if (address != null)
                    {
                        if (address.AddressId.HasValue)
                        {
                            int.TryParse(address.AddressId.Value.ToString(), out AddressId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(AddressId);
        }
        /// <summary>
        /// The purpose of this method to get the installer adddress for email by installer id.
        /// </summary>
        /// <param name="InstallerId"></param>
        /// <returns></returns>
        public static string GetAddressHTML2LineForEmail(Guid InstallerId)
        {
            string strAddress = string.Empty;

            try
            {
                using (LinqToSqlDataContext db = new LinqToSqlDataContext())
                {
                    /* This change is made to get the company name */
                    USP_GetInstallerAddressByInstallerIdResult address = db.USP_GetInstallerAddressByInstallerId(InstallerId.ToString()).SingleOrDefault();
                    if (address == null)
                    {
                        return(" ");
                    }
                    string NOTSPECIFIED = " ";
                    strAddress += string.IsNullOrEmpty(address.CompanyName) ? NOTSPECIFIED.Trim() : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + address.CompanyName + ", " + " <br /> ";
                    strAddress += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + address.AddressOne + ", " + " <br /> ";
                    strAddress += string.IsNullOrEmpty(address.AddressTwo) ? NOTSPECIFIED.Trim() : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + address.AddressTwo + ", " + " <br /> ";
                    strAddress += string.IsNullOrEmpty(address.Town) ? NOTSPECIFIED.Trim() : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + address.Town + ", ";
                    strAddress += string.IsNullOrEmpty(address.County) ? NOTSPECIFIED.Trim() : address.County + ", ";
                    strAddress += string.IsNullOrEmpty(address.PostCode) ? NOTSPECIFIED.Trim() : "<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + address.PostCode + ", <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    strAddress += string.IsNullOrEmpty(address.Fax) ? NOTSPECIFIED.Trim() : " Fax: " + address.Fax;
                    strAddress += string.IsNullOrEmpty(address.Mobile) ? NOTSPECIFIED.Trim() : ", Mob: " + address.Mobile;
                    strAddress += string.IsNullOrEmpty(address.Telephone) ? NOTSPECIFIED.Trim() : " Tel: " + address.Telephone;
                    if (strAddress.LastIndexOf(",") > 0)
                    {
                        strAddress = strAddress.Remove(strAddress.LastIndexOf(","));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(strAddress);
        }
Exemple #6
0
        // Get product Grade list
        public static List <ProductGradeDTO> GetProductGrade()
        {
            LinqToSqlDataContext db = new LinqToSqlDataContext();


            List <ProductGradeDTO> lstProductGrade = new List <ProductGradeDTO>();


            var productGrade = (from pg in db.ProductCode_Grade_Maps

                                where pg.IsDeleted == false
                                orderby pg.ProductCode ascending
                                select new
            {
                productCode = pg.ProductCode,
                ProductGradeID = pg.ProductGradeID,
                Grade = pg.Grade
            }
                                );


            foreach (var grade in productGrade)
            {
                ProductGradeDTO gra = new ProductGradeDTO();
                gra.ProductGradeID = grade.ProductGradeID;
                gra.ProductCode    = grade.productCode;
                gra.Grade          = grade.Grade;
                lstProductGrade.Add(gra);
            }

            db.Dispose();



            return(lstProductGrade);
        }
Exemple #7
0
        public static string ValidateUsername(string username)
        {
            string trimmedString = username.Trim();

            if (trimmedString.Contains(" ") || string.IsNullOrEmpty(trimmedString))
            {
                throw new InvalidUsernameException();
            }

            // Username musí být unikátní
            LinqToSqlDataContext db           = DatabaseSetup.Database;
            IEnumerable <string> allUsernames = from u in db.Users
                                                select u.username;

            foreach (string singleUsername in allUsernames)
            {
                if (singleUsername.Trim() == trimmedString)
                {
                    throw new UsernameAlreadyExistsException();
                }
            }

            return(trimmedString);
        }
 private void BindGrid()
 {
     try
     {
         db = new LinqToSqlDataContext();
         var data = (from dt in db.ARC_AccessCodes
                     join arc in db.ARCs on dt.ARCID equals arc.ARCId
                     join ins in db.Installers on dt.InstallerUniqueCode equals ins.UniqueCode into insleftouter
                     from ins in insleftouter.DefaultIfEmpty()
                     select new { ARCDisp = arc.CompanyName + " [" + arc.ARC_Code + "]", ins.UniqueCode, ins.CompanyName, dt.Accesscode, arc.ARCId, dt.ID }).OrderBy(x => x.ARCDisp);
         if (data != null)
         {
             gvARCIns.DataSource = data;
             gvARCIns.DataBind();
         }
     }
     catch (Exception objException)
     {
         string script = "alertify.alert('" + objException.Message + "');";
         ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
         db = new CSLOrderingARCBAL.LinqToSqlDataContext();
         db.USP_SaveErrorDetails(Request.Url.ToString(), "BindGrid", 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()]));
     }
 }
        public static int AddtoEmizonRequestQueue(string EMNo, string QueueType)
        {
            int retvalue = -1;

            try
            {
                using (LinqToSqlDataContext dbContext = new LinqToSqlDataContext())
                {
                    EmizonQueueRequest _EmizonQueueRequest = new EmizonQueueRequest();
                    _EmizonQueueRequest.EMNo       = EMNo;
                    _EmizonQueueRequest.QueueType  = QueueType;
                    _EmizonQueueRequest.Createdon  = System.DateTime.Now;
                    _EmizonQueueRequest.Modifiedon = System.DateTime.Now;
                    dbContext.EmizonQueueRequests.InsertOnSubmit(_EmizonQueueRequest);
                    dbContext.SubmitChanges();
                    retvalue = _EmizonQueueRequest.ID;
                }
            }
            catch (Exception exp)
            {
                retvalue = -1;
            }
            return(retvalue);
        }
Exemple #10
0
        public static void DeleteAllProducts()
        {
            // Tabulka ProductImages má: ON DELETE CASCADE, ale
            // obrázky v tabulce ImagesTable zůstanou --> je třeba je smazat

            LinqToSqlDataContext db = DatabaseSetup.Database;

            // Mazání všech přiřazených obrázků
            List <ImagesTable>        imagesToDelete = new List <ImagesTable>();
            IEnumerable <ImagesTable> allImages      = from i in db.ImagesTables
                                                       join pi in db.ProductImages
                                                       on i.id equals pi.idImage
                                                       select i;

            db.ImagesTables.DeleteAllOnSubmit(allImages);
            db.SubmitChanges();

            // Mazání produktů
            IEnumerable <Product> allProducts = from p in db.Products
                                                select p;

            db.Products.DeleteAllOnSubmit(allProducts);
            db.SubmitChanges();
        }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        try
        {
            db = new LinqToSqlDataContext();
            var opt = (from op in db.Options
                       where op.OptionName.Contains(txtoptsrch.Text.Trim())
                       select op);
            gvOpt.DataSource = opt;
            gvOpt.DataBind();

            Session[enumSessions.Option_Id.ToString()] = null;

            if (opt.Count() == 0)
            {
                LoadData();
            }
        }
        catch (Exception objException)
        {
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "btnSearch_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()]));
        }
    }
Exemple #12
0
 protected void gvEMParams_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         using (LinqToSqlDataContext db = new LinqToSqlDataContext())
         {
             int paramID = 0;
             int.TryParse(gvEMParams.SelectedValue.ToString(), out paramID);
             var productParameters = db.EM_ProductParams.Where(x => x.EM_ProductParamID == paramID).FirstOrDefault();
             if (productParameters != null)
             {
                 chkAsNew.Checked            = false;
                 txtBillingDesc.Text         = productParameters.EM_ProductBillingDesc;
                 txtBillingCommit.Text       = productParameters.EM_ProductBillingCommitment.ToString();
                 txtCoreService.Text         = productParameters.EM_CoreService.ToString();
                 txtCoreType.Text            = productParameters.EM_CoreType.ToString();
                 txtInstTypeEquiv.Text       = productParameters.EM_InstType_Equivalent.ToString();
                 txtPriCluster.Text          = productParameters.EM_CorePrimaryCluster.ToString();
                 txtPriSubcluster.Text       = productParameters.EM_CorePrimarySubCluster.ToString();
                 txtSecondarycluster.Text    = productParameters.EM_CoreSecondaryCluster.ToString();
                 txtSecondarySubCluster.Text = productParameters.EM_CoreSecondarySubCluster.ToString();
                 txtTypeID.Text        = productParameters.EM_InstType_Type.ToString();
                 chkDeleteFlag.Checked = productParameters.Is_Deleted_Flag;
                 divForm.Visible       = true;
             }
             else
             {
                 lblErrorMsg.Text = "Unable to get data from database.";
             }
         }
     }
     catch (Exception exp)
     {
         lblErrorMsg.Text = exp.Message;
     }
 }
    protected void ProductsRepeater_ItemBound(object sender, RepeaterItemEventArgs args)
    {
        try
        {
            if (args.Item.ItemType == ListItemType.Item || args.Item.ItemType == ListItemType.AlternatingItem)
            {
                LinqToSqlDataContext db = new LinqToSqlDataContext();
                if (String.IsNullOrEmpty(hidProductCode.Value))
                {
                    hidProductCode.Value = (args.Item.FindControl("lblProductCode") as Label).Text;
                }

                else if (hidProductCode.Value.ToString() != (args.Item.FindControl("lblProductCode") as Label).Text)
                {
                    hidProductCode.Value = (args.Item.FindControl("lblProductCode") as Label).Text;
                    count = 1;
                }

                HtmlControl tdManufacturer = args.Item.FindControl("tdManufacturer") as HtmlControl;
                tdManufacturer.Visible = true;
                //
                string name = (from dcc in db.DCCCompanies
                               where dcc.Productcode.Contains(hidProductCode.Value)
                               select dcc.company_name).SingleOrDefault();
                if (name != null)
                {
                    Label lblManufacturer = args.Item.FindControl("lblManufacturer") as Label;
                    lblManufacturer.Visible = true;
                    lblManufacturer.Text    = name;
                }


                if (Session[enumSessions.User_Role.ToString()] != null && Session[enumSessions.User_Role.ToString()].ToString() == enumRoles.ARC_Admin.ToString())
                {
                    Label lblProductPrice = (Label)args.Item.FindControl("lblProductPrice");
                    lblProductPrice.Text = String.Empty; //0.00

                    Label lblProductPriceTotal = (Label)args.Item.FindControl("lblProductPriceTotal");
                    lblProductPriceTotal.Text = String.Empty; //0.00
                }

                Label lblProductCode = (Label)args.Item.FindControl("lblProductCode");

                int rowCount = db.USP_GetBasketProductsOnCheckOut(Convert.ToInt32(Session[enumSessions.OrderId.ToString()].ToString())).Where(i => i.ProductCode == lblProductCode.Text.Trim()).Count();


                if (rowCount == count)
                {
                    USP_GetBasketProductsOnCheckOutResult product = (USP_GetBasketProductsOnCheckOutResult)args.Item.DataItem;
                    Repeater rep = (Repeater)args.Item.FindControl("rptrDependentProducts");


                    rep.DataSource = db.USP_GetBasketDependentProductsByProductId(Convert.ToInt32(Session[enumSessions.OrderId.ToString()].ToString()), product.ProductId, product.CategoryId);
                    rep.DataBind();

                    if (rep.Items.Count == 0)
                    {
                        rep.Visible = false;
                    }

                    db.Dispose();
                }

                count++;
            }
            if (args.Item.ItemType == ListItemType.Footer)
            {
                Label lblTotalPrice = (Label)args.Item.FindControl("lblTotalPrice");
                Label lblTotalQty   = (Label)args.Item.FindControl("lblTotalQty");

                LinqToSqlDataContext db = new LinqToSqlDataContext();
                var OrderInfo           = db.USP_CreateOrderForUser(Convert.ToInt32(Session[enumSessions.ARC_Id.ToString()].ToString()), Session[enumSessions.User_Name.ToString()].ToString(), Session[enumSessions.User_Name.ToString()].ToString(), Session[enumSessions.User_Email.ToString()].ToString(), Session[enumSessions.User_Id.ToString()].ToString()).SingleOrDefault();
                if (OrderInfo != null)
                {
                    lblTotalPrice.Text     = "£" + OrderInfo.Amount.ToString();
                    lblTotalQty.Text       = OrderInfo.Quantity.ToString();
                    lblDtlsOrderTotal.Text = OrderInfo.Amount.ToString();
                    lblDtlsTotalToPay.Text = OrderInfo.Amount.ToString();
                }

                if (Session[enumSessions.User_Role.ToString()] != null && Session[enumSessions.User_Role.ToString()].ToString() == enumRoles.ARC_Admin.ToString())
                {
                    lblTotalPrice.Text     = String.Empty; //£0.00
                    lblDtlsOrderTotal.Text = String.Empty; //0.00
                    lblDtlsTotalToPay.Text = String.Empty; //0.00
                }
                db.Dispose();
            }
        }
        catch (Exception objException)
        {
            CSLOrderingARCBAL.LinqToSqlDataContext db;
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "ProductsRepeater_ItemBound", 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()]));
        }
    }
    protected void LoadDeliveryTypes()
    {
        ddlDeliveryTypes.Items.Clear();

        //Calculating order total and other offers to populate delivery options
        OrdersBAL deliveryOptions = new OrdersBAL();

        deliveryOptions.orderId = Convert.ToInt32(Session[enumSessions.OrderId.ToString()].ToString());

        //Set the lowest priced as selected.
        int     i = 0; int selectedIndex = 0;
        decimal leastPriceItem = decimal.MaxValue;


        try
        {
            //List<DeliveryType> shippingOptions = deliveryOptions.GetShippingOptions();
            LinqToSqlDataContext db = new LinqToSqlDataContext();
            List <USP_GetShippingOptionsResult> shippingOptions = new List <USP_GetShippingOptionsResult>();

            shippingOptions = db.USP_GetShippingOptions(Convert.ToInt32(Session[enumSessions.ARC_Id.ToString()].ToString()), new Guid(Session[enumSessions.InstallerCompanyID.ToString()].ToString()), Convert.ToInt32(Session[enumSessions.OrderId.ToString()])).ToList();

            foreach (USP_GetShippingOptionsResult delivery in shippingOptions)
            {
                System.Web.UI.WebControls.ListItem item = new System.Web.UI.WebControls.ListItem();
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB", false);
                item.Text  = delivery.DeliveryShortDesc + " - " + delivery.DeliveryPrice.Value.ToString("c");
                item.Value = delivery.DeliveryTypeId.ToString();

                if (leastPriceItem != decimal.Zero && delivery.DeliveryPrice < leastPriceItem)
                {
                    leastPriceItem = delivery.DeliveryPrice.Value;
                    ddlDeliveryTypes.ClearSelection();
                    ddlDeliveryTypes.SelectedIndex = i;
                    selectedIndex = i;
                }
                ddlDeliveryTypes.Items.Add(item);
                i++;
            }
            ddlDeliveryTypes.DataBind();
            ddlDeliveryTypes.SelectedIndex = selectedIndex;

            bool?isAncillary = false;
            db.USP_IsAncillaryOnlyOrders(Convert.ToInt32(Session[enumSessions.OrderId.ToString()]), ref isAncillary);
            if (isAncillary.Value == true)
            {
                lblIsAncillary.Visible = true;
            }
            else
            {
                lblIsAncillary.Visible = false;
            }
        }
        catch (Exception objException)
        {
            CSLOrderingARCBAL.LinqToSqlDataContext db;
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "LoadDeliveryTypes", 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();
        }
    }
Exemple #15
0
        public ApplicationDTO GetAppValues()
        {
            ApplicationDTO app = new ApplicationDTO();

            using (LinqToSqlDataContext db = new LinqToSqlDataContext())
            {
                var settingsKeyValuePairs = db.ApplicationSettings; // only one query to database to get all settings is better than quering multiples times for each key

                foreach (ApplicationSetting key in settingsKeyValuePairs)
                {
                    switch (key.KeyName)
                    {
                    case "VATRate":
                        app.VATRate = string.IsNullOrEmpty(key.KeyValue) ? 0 : Convert.ToDecimal(key.KeyValue);
                        break;

                    case "smtphost":
                        app.smtphost = key.KeyValue;
                        break;

                    case "OrdersEmailFrom":
                        app.mailFrom = key.KeyValue;
                        break;

                    case "EmailCC":
                        app.mailCC = key.KeyValue;
                        break;

                    case "LogisticsEmail":
                        app.mailTO = key.KeyValue;
                        break;

                    case "BillingEmail":
                        app.billingemail = key.KeyValue;
                        break;

                    case "FedexURL":
                        app.FedexURL = key.KeyValue;
                        break;

                    case "ConnectionOnlyCodes":
                        app.ConnectionOnlyCodes = key.KeyValue;
                        break;

                    default:
                        break;
                    }
                }//end foreach
            }


            //insert all the values in cache - Best to remove below and also the reference if the below cache keys are not used
            HttpRuntime.Cache.Insert("VATRate", app.VATRate);
            HttpRuntime.Cache.Insert("smtphost", app.smtphost);
            HttpRuntime.Cache.Insert("OrdersEmailFrom", app.mailFrom);
            HttpRuntime.Cache.Insert("EmailCC", app.mailCC);
            HttpRuntime.Cache.Insert("LogisticsEmail", app.mailTO);
            HttpRuntime.Cache.Insert("BillingEmail", app.billingemail);
            //HttpRuntime.Cache.Insert("ARCCC", app.ARC_CC);
            return(app);
        }
Exemple #16
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Page.Validate();
        if (Page.IsValid)
        {
            try
            {
                //creating user

                if (ddlARC.SelectedValue == "-1")
                {
                    string script = "alertify.alert('" + ltrSelectARC.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    MaintainScrollPositionOnPostBack = false;
                    return;
                }
                var checkedroles = (from ListItem item in Chkboxroles.Items where item.Selected select item.Value).ToList();
                if (!checkedroles.Any())
                {
                    string script = "alertify.alert('" + ltrSelectRole.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    MaintainScrollPositionOnPostBack = false;
                    return;
                }
                string username = "";
                if (Session[enumSessions.UserIdToUpdate.ToString()] == null)
                {
                    txtuname.Enabled = true;
                    if (!string.IsNullOrEmpty(txtpwd.Text.ToString().Trim()) && !string.IsNullOrEmpty(Txtuemail.Text.ToString().Trim()) && !string.IsNullOrEmpty(txtuname.Text.ToString().Trim()))
                    {
                        username = txtuname.Text.ToString().Trim();
                        string password = txtpwd.Text.ToString().Trim();
                        string Emailid  = Txtuemail.Text.ToString().Trim();
                        string question = ddlSecurityQuestion.SelectedValue;
                        string answer   = txtAnswer.Text.ToString().Trim();
                        MembershipCreateStatus res;
                        MembershipUser         usr = Membership.CreateUser(username, password, Emailid, question, answer, ChkBoxIsapproved.Checked, out res);
                        if (usr == null)
                        {
                            string script = "alertify.alert('" + res.ToString() + "');";
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                            return;
                        }
                        else
                        {
                            Session[enumSessions.UserIdToUpdate.ToString()] = new Guid(usr.ProviderUserKey.ToString());
                            string script = "alertify.alert('User " + txtuname.Text + " created successfully.');";
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                            MaintainScrollPositionOnPostBack = false;
                        }
                    }
                }
                //updating user
                else
                {
                    if (!string.IsNullOrEmpty(Txtuemail.Text.ToString().Trim()) && !string.IsNullOrEmpty(txtuname.Text.ToString().Trim()))
                    {
                        txtuname.Enabled = false;
                        username         = txtuname.Text.ToString().Trim();
                        string         password = txtpwd.Text.ToString().Trim();
                        string         Emailid  = Txtuemail.Text.ToString().Trim();
                        string         question = ddlSecurityQuestion.SelectedValue;
                        string         answer   = txtAnswer.Text.ToString().Trim();
                        MembershipUser user;
                        user = Membership.GetUser(new Guid(Session[enumSessions.UserIdToUpdate.ToString()].ToString()));
                        db   = new LinqToSqlDataContext();
                        if (ChkBoxIsBlocked.Checked == false)
                        {
                            user.UnlockUser();
                        }
                        var usrDtls = db.USP_GetUserDetailsByUserId(Session[enumSessions.UserIdToUpdate.ToString()].ToString()).FirstOrDefault();
                        // string cur_pwd = user.GetPassword(usrDtls.PasswordAnswer);
                        // user.ChangePasswordQuestionAndAnswer(cur_pwd, question, answer);
                        if (!string.IsNullOrEmpty(txtpwd.Text.ToString()))
                        {
                            user.ChangePassword(Membership.Provider.ResetPassword(username, usrDtls.PasswordAnswer), txtpwd.Text);
                            // user.ChangePassword(cur_pwd, txtpwd.Text.ToString().Trim());
                        }

                        user.Email = Emailid.Trim();

                        Boolean approved = true;
                        if (ChkBoxIsapproved.Checked)
                        {
                            approved = true;
                        }
                        else
                        {
                            approved = false;
                        }


                        user.IsApproved = approved;
                        Membership.UpdateUser(user);

                        //deleting old existing roles of this user
                        string[] adminroles = (from a in db.ApplicationSettings
                                               where a.KeyName == enumApplicationSetting.WebsiteAdminRoles.ToString()
                                               select a.KeyValue).SingleOrDefault().Split(',');
                        var Rls = Roles.GetAllRoles().Except(adminroles).ToList();

                        foreach (string Urole in Rls)
                        {
                            if (Roles.IsUserInRole(txtuname.Text.ToString(), Urole))
                            {
                                Roles.RemoveUserFromRole(txtuname.Text.ToString(), Urole);
                            }
                        }

                        //deleting old existing arcs of this user

                        db = new LinqToSqlDataContext();
                        var delarc = db.ARC_User_Maps.Where(item => item.UserId == new Guid(Session[enumSessions.UserIdToUpdate.ToString()].ToString()));
                        db.ARC_User_Maps.DeleteAllOnSubmit(delarc);
                        db.SubmitChanges();

                        string script = "alertify.alert('User " + txtuname.Text + " updated successfully.');";
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                        MaintainScrollPositionOnPostBack = false;
                    }
                }

                string roleslist = string.Empty;
                //inserting checked roles
                for (int i = 0; i <= Chkboxroles.Items.Count - 1; i++)
                {
                    if (Chkboxroles.Items[i].Selected == true)
                    {
                        Roles.AddUserToRole(txtuname.Text.ToString(), Chkboxroles.Items[i].Value.ToString());
                        roleslist += Chkboxroles.Items[i].Value.ToString() + ",";
                    }
                }


                //inserting checked arcs of this user

                ARC_User_Map acm;
                if (ddlARC.SelectedValue != "-1" && ddlARC.SelectedValue != null)
                {
                    db         = new LinqToSqlDataContext();
                    acm        = new ARC_User_Map();
                    acm.UserId = new Guid(Session[enumSessions.UserIdToUpdate.ToString()].ToString());
                    acm.ARCId  = Convert.ToInt32(ddlARC.SelectedValue);
                    db.ARC_User_Maps.InsertOnSubmit(acm);
                    db.SubmitChanges();
                    int orderId = (from o in db.Orders
                                   where o.UserId == acm.UserId && o.ARCId != acm.ARCId && o.OrderStatusId == 1
                                   select o.OrderId).SingleOrDefault();
                    if (orderId > 0)
                    {
                        db.USP_DeleteOrderwithDetails(orderId);
                    }
                }


                pnluserdetails.Visible = false;
                pnluserlist.Visible    = true;

                Audit audit = new Audit();
                audit.UserName  = Session[enumSessions.User_Name.ToString()].ToString();
                audit.ChangeID  = Convert.ToInt32(enumAudit.Manage_User);
                audit.CreatedOn = DateTime.Now;
                audit.Notes     = "UserName: "******", Email: " + Txtuemail.Text + ", ARC: " + ddlARC.SelectedItem + ", IsApproved: " + ChkBoxIsapproved.Checked +
                                  ", IsBlocked:" + ChkBoxIsBlocked.Checked + ", Roles:" + roleslist;

                if (Request.ServerVariables["LOGON_USER"] != null)
                {
                    audit.WindowsUser = Request.ServerVariables["LOGON_USER"];
                }
                audit.IPAddress = Request.UserHostAddress;
                db.Audits.InsertOnSubmit(audit);
                db.SubmitChanges();

                LoadData();
                MaintainScrollPositionOnPostBack = false;
            }


            catch (Exception objException)
            {
                if (objException.Message.Trim() == "The E-mail supplied is invalid.")
                {
                    string script = "alertify.alert('" + ltrEmailExists.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                }
                db = new CSLOrderingARCBAL.LinqToSqlDataContext();
                db.USP_SaveErrorDetails(Request.Url.ToString(), "btnSave_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()]));
            }
        }
        else
        {
            string script = "alertify.alert('" + ltrFill.Text + "');";
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
            MaintainScrollPositionOnPostBack = false;
        }
    }
Exemple #17
0
    protected void LinkButtonupdate_click(object sender, System.EventArgs e)
    {
        try
        {
            pnluserdetails.Visible   = true;
            pnluserlist.Visible      = false;
            litAction.Text           = "You choose to <b>EDIT USER</b>";
            ChkBoxIsapproved.Checked = false;
            LinkButton lbuser = sender as LinkButton;
            if (lbuser != null)
            {
                GridViewRow gvr  = (GridViewRow)lbuser.NamingContainer;
                Label       lbl1 = gvr.FindControl("UserKey") as Label;
                Session[enumSessions.UserIdToUpdate.ToString()] = lbl1.Text;
            }
            else
            {
                //Reset
                if (Session[enumSessions.UserIdToUpdate.ToString()] != null)
                {
                }
                else
                {
                    //Do a cancel as no value in session
                    btnCancel_Click(sender, e);
                }
            }

            db = new LinqToSqlDataContext();
            var usrDtls = db.USP_GetUserDetailsByUserId(Session[enumSessions.UserIdToUpdate.ToString()].ToString()).FirstOrDefault();
            if (usrDtls.IsLockedOut)
            {
                ChkBoxIsBlocked.Enabled = true;
            }
            //new code for isapproved and locked out by sonam
            if (usrDtls.IsApproved == true)
            {
                ChkBoxIsapproved.Checked = true;
            }
            if (usrDtls.IsLockedOut == true)
            {
                ChkBoxIsBlocked.Checked = true;
            }
            txtuname.Text    = usrDtls.UserName;
            txtuname.Enabled = false;
            txtpwd.Text      = usrDtls.Password;
            ddlSecurityQuestion.SelectedValue = usrDtls.PasswordQuestion;
            txtAnswer.Text = usrDtls.PasswordAnswer;
            Txtuemail.Text = usrDtls.Email;

            foreach (ListItem itemchk in Chkboxroles.Items)
            {
                itemchk.Selected = false;
            }

            //bind user roles to checkboxroles
            string[] adminroles = (from a in db.ApplicationSettings
                                   where a.KeyName == enumApplicationSetting.WebsiteAdminRoles.ToString()
                                   select a.KeyValue).SingleOrDefault().Split(',');
            var Rls = Roles.GetAllRoles().Except(adminroles).ToList();

            foreach (string Urole in Rls)
            {
                if (Roles.IsUserInRole(txtuname.Text.ToString(), Urole))
                {
                    foreach (ListItem itemchk in Chkboxroles.Items)
                    {
                        if (itemchk.Value == Urole)
                        {
                            itemchk.Selected = true;
                        }
                    }
                }
            }


            //binding user  to radioarc
            CheckArc();
        }
        catch (Exception objException)
        {
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "LinkButtonupdate_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()]));
        }
    }
Exemple #18
0
    public void LoadData()
    {
        try
        {
            Session[enumSessions.UserIdToUpdate.ToString()] = null;
            MaintainScrollPositionOnPostBack = true;
            txtuname.Text            = "";
            Txtuemail.Text           = "";
            txtpwd.Text              = "";
            txtConfirmPwd.Text       = "";
            txtuname.Enabled         = true;
            ChkBoxIsapproved.Checked = false;
            ChkBoxIsBlocked.Checked  = false;
            ChkBoxIsBlocked.Enabled  = false;

            //binding griduser
            db = new LinqToSqlDataContext();
            var UserDetails = (from usrDtls in db.VW_GetActiveUsersDetails
                               orderby usrDtls.UserName ascending
                               where usrDtls.CompanyName.Contains(Txtuarcsrch.Text.Trim()) &&
                               usrDtls.Email.Contains(Txtuemailsrch.Text.Trim()) &&
                               usrDtls.ARC_Code.Contains(txtArcCodeSrch.Text.Trim()) &&
                               usrDtls.UserName.Contains(Txtunamesrch.Text.Trim())
                               select usrDtls);


            gvUsers.DataSource = UserDetails;
            gvUsers.DataBind();

            //binding Role DropDown.
            string[] adminroles = (from a in db.ApplicationSettings
                                   where a.KeyName == enumApplicationSetting.WebsiteAdminRoles.ToString()
                                   select a.KeyValue).SingleOrDefault().Split(',');
            var rol2 = Roles.GetAllRoles().Except(adminroles).ToList();

            ddrolesrch.DataSource = rol2;
            ddrolesrch.DataBind();
            ListItem li = new ListItem();
            li.Text  = "All";
            li.Value = "-1";
            ddrolesrch.Items.Insert(0, li);
            ddrolesrch.SelectedIndex = 0;

            //binding roles
            var rol = Roles.GetAllRoles().Except(adminroles).ToList();
            Chkboxroles.DataSource = rol;
            Chkboxroles.DataBind();
            for (int i = 0; i <= Chkboxroles.Items.Count - 1; i++)
            {
                Chkboxroles.Items[i].Selected = false;
            }

            //binding arcs
            db = new LinqToSqlDataContext();
            var ARCdata = (from arc in db.ARCs
                           where arc.IsDeleted == false
                           orderby arc.CompanyName
                           select new { arc.ARCId, ARCDisp = arc.CompanyName + " - [" + arc.ARC_Code + "]" }
                           );

            ddlARC.DataValueField = "ARCId";
            ddlARC.DataTextField  = "ARCDisp";
            ddlARC.DataSource     = ARCdata;
            ddlARC.DataBind();
            ddlARC.Items.Insert(0, new ListItem("No ARC", "-1"));
        }
        catch (Exception objException)
        {
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "LoadData", 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()]));
        }
    }
Exemple #19
0
    protected void LinkButtonupdate_click(object sender, System.EventArgs e)
    {
        try
        {
            btnSave.Visible       = true;
            divcreateuser.Visible = true;
            LinkButton  lbctg = sender as LinkButton;
            GridViewRow gvr   = (GridViewRow)lbctg.NamingContainer;
            Label       lbl1  = gvr.Cells[5].FindControl("UserKey") as Label;
            Session[enumSessions.UserIdToUpdate.ToString()] = lbl1.Text;
            db = new LinqToSqlDataContext();
            var usrDtls = db.USP_GetUserDetailsByUserId(lbl1.Text).FirstOrDefault();
            if (usrDtls.IsLockedOut)
            {
                ChkBoxIsBlocked.Enabled = true;
            }

            //new code for isapproved and locked out by sonam

            if (usrDtls.IsApproved == true)
            {
                ChkBoxIsapproved.Checked = true;
            }
            if (usrDtls.IsLockedOut == true)
            {
                ChkBoxIsBlocked.Checked = true;
            }
            txtuname.Text    = usrDtls.UserName;
            txtuname.Enabled = false;
            txtpwd.Text      = usrDtls.Password;
            ddlSecurityQuestion.SelectedValue = usrDtls.PasswordQuestion;
            txtAnswer.Text = usrDtls.PasswordAnswer;
            Txtuemail.Text = usrDtls.Email;

            foreach (ListItem itemchk in Chkboxroles.Items)
            {
                itemchk.Selected = false;
            }

            //bind user roles to checkboxroles
            string[] Rls = { "ARC_Admin", "ARC_Manager" };

            foreach (string Urole in Rls)
            {
                if (Roles.IsUserInRole(txtuname.Text.ToString(), Urole))
                {
                    foreach (ListItem itemchk in Chkboxroles.Items)
                    {
                        if (itemchk.Text == Urole)
                        {
                            itemchk.Selected = true;
                        }
                    }
                }
            }


            //binding user  to radioarc
        }
        catch (Exception objException)
        {
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "LinkButtonupdate_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()]));
        }
    }
Exemple #20
0
        private void CreateXmlBillFromDatabaseSource(string orderId)
        {
            // Načtení dat z DB
            LinqToSqlDataContext db = DatabaseSetup.Database;
            int orderIdInt          = Convert.ToInt32(orderId);
            // Získat vybraný Order
            Order selectedOrder = (from o in db.Orders
                                   where o.id == orderIdInt
                                   select o).Single();
            // Získat výrobky
            IEnumerable <OrderItem> shoppingCartItemsFromDb =
                (from shopItm in db.OrderItems
                 where shopItm.orderId == orderIdInt
                 select shopItm);

            // Dovýpočet některých hodnot

            /*  decimal? totalPriceOfTransaction = 0;
             * foreach(OrderItem item in shoppingCartItemsFromDb)
             * {
             *    if (item.priceForUnit) totalPriceOfTransaction += item.price * item.quantity;
             *    if (!item.priceForUnit) totalPriceOfTransaction += item.price * item.unitQuantity;
             * }
             *
             * decimal? change = selectedOrder.paid - totalPriceOfTransaction;
             */

            // VAT pro produkty
            IEnumerable <OrderItemsVat> listOfVat = from vat in db.OrderItemsVats
                                                    where vat.orderId == orderIdInt
                                                    select vat;



            #region hardcoded účtenka
            if (!Directory.Exists(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill")))
            {
                Directory.CreateDirectory(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill"));
            }
            using (XmlWriter xmlWriter = XmlWriter.Create(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill", orderIdInt.ToString() + ".xml")))
            {
                xmlWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"../CashRegister/Bill.xslt\"?>");
                xmlWriter.WriteStartElement("bill");


                foreach (OrderItem item in shoppingCartItemsFromDb)
                {
                    xmlWriter.WriteStartElement("product");
                    xmlWriter.WriteElementString("name", item.name.Trim());
                    xmlWriter.WriteElementString("quantity", item.quantity.ToString());
                    xmlWriter.WriteElementString("unit", item.unit.Trim());

                    if (!item.priceForUnit)
                    {
                        xmlWriter.WriteElementString("unitQuantity", item.unitQuantity.ToString());
                    }

                    xmlWriter.WriteElementString("expirationDate", ((DateTime)item.expirationDate).ToString("dd.MM.yyyy"));
                    xmlWriter.WriteElementString("code", item.code.ToString());
                    xmlWriter.WriteElementString("totalPrice", item.totalPrice.ToString());
                    xmlWriter.WriteElementString("priceForUnit", item.priceForUnit.ToString());
                    xmlWriter.WriteElementString("priceForSingleUnit", item.price.ToString());
                    xmlWriter.WriteElementString("vatType", item.vatId.ToString());
                    xmlWriter.WriteEndElement();
                }

                xmlWriter.WriteElementString("totalShoppingCartPrice", selectedOrder.totalShoppingCartPrice.ToString());
                xmlWriter.WriteElementString("paid", selectedOrder.paid.ToString());
                xmlWriter.WriteElementString("change", (selectedOrder.change).ToString());
                xmlWriter.WriteElementString("staff", selectedOrder.staff.Trim());
                xmlWriter.WriteElementString("time", ((DateTime)selectedOrder.timeOfTransaction).ToShortDateString() + " " + ((DateTime)selectedOrder.timeOfTransaction).ToShortTimeString());


                //DPH se počítá dohromady pro všechny výrobky dané kategorie (A,B,C,D)

                /* List<VAT> listOfVat = GetVat();
                 * decimal? vatSum = GetVatSum(listOfVat);
                 * decimal? vatSumSingle = GetVatSumSingle(listOfVat);*/
                xmlWriter.WriteElementString("vatSum", string.Format("{0:0.00}", selectedOrder.vatSum));
                xmlWriter.WriteElementString("vatSumSingle", string.Format("{0:0.00}", selectedOrder.vatSumSingle));
                foreach (OrderItemsVat singleVat in listOfVat)
                {
                    xmlWriter.WriteStartElement(singleVat.vatId.ToString());
                    xmlWriter.WriteAttributeString("percentage", singleVat.percentageLabel.Trim());
                    xmlWriter.WriteAttributeString("totalPrice", string.Format("{0:0.00}", singleVat.vatValueProducts));
                    xmlWriter.WriteString(string.Format("{0:0.00}", singleVat.vatValue));
                    xmlWriter.WriteEndElement();
                }

                //Informace do hlavičky

                xmlWriter.WriteElementString("companyName", selectedOrder.companyName.Trim()); // Name je vždy vyplněné

                //Další nepovinné údaje, pokud chybí, tak se to do XML nebude přidávat
                if (!string.IsNullOrEmpty(selectedOrder.companyAdress))
                {
                    xmlWriter.WriteElementString("companyAdress", selectedOrder.companyAdress.Trim());
                }

                if (!string.IsNullOrEmpty(selectedOrder.companyCity))
                {
                    xmlWriter.WriteElementString("companyCity", selectedOrder.companyCity.Trim());
                }

                if (selectedOrder.companyPostalCode != null)
                {
                    xmlWriter.WriteElementString("companyPostalCode", selectedOrder.companyPostalCode.ToString().Trim());
                }

                if (!string.IsNullOrEmpty(selectedOrder.companyPhone))
                {
                    xmlWriter.WriteElementString("companyPhone", selectedOrder.companyPhone.Trim());
                }

                if (!string.IsNullOrEmpty(selectedOrder.companyWeb))
                {
                    xmlWriter.WriteElementString("companyWeb", selectedOrder.companyWeb.Trim());
                }

                Bill billInfo = BillInfo.GetBillInfo();
                if (!string.IsNullOrEmpty(billInfo.billText))
                {
                    xmlWriter.WriteElementString("billText", billInfo.billText.Trim());
                }

                xmlWriter.WriteEndElement();
            }
            #endregion
        }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            try
            {
                Audit  audit = new Audit();
                string notes = null;
                if (ddlArc.SelectedIndex > 0)
                {
                    if (gvProducts.Rows.Count > 0)
                    {
                        int retrun = -1;
                        foreach (GridViewRow row in gvProducts.Rows)
                        {
                            Decimal  objtxtPrice      = -1;
                            DateTime?objtxtExpiryDate = null;
                            Int32    objlblProuctId   = Convert.ToInt32((row.FindControl("ProductId") as Label).Text); // get product id
                            if ((row.FindControl("txtPrice") as TextBox).Text.Trim() != "")
                            {
                                objtxtPrice = Convert.ToDecimal((row.FindControl("txtPrice") as TextBox).Text); // get entered Price
                            }
                            if ((row.FindControl("txtExpiryDate") as TextBox).Text.Trim() != "")
                            {
                                objtxtExpiryDate = DateTime.Parse((row.FindControl("txtExpiryDate") as TextBox).Text); // get selected expiry date
                            }
                            if (objtxtPrice > -1 && objtxtExpiryDate != null)
                            {
                                db     = new LinqToSqlDataContext();
                                retrun = db.USP_SaveARCProductPrice(Convert.ToInt32(ddlArc.SelectedValue), objlblProuctId, objtxtPrice, objtxtExpiryDate, Convert.ToString(Session[enumSessions.User_Id.ToString()])); // pass all values to save
                            }
                            notes += "Product: " + objlblProuctId + ", Price: " + objtxtPrice + ", Date: " + objtxtExpiryDate + ", ";
                        }

                        if (retrun == 0)
                        {
                            string script = "alertify.alert('" + ltrProdPriceUpdate.Text + "');";
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                        }
                        else
                        {
                            string script = "alertify.alert('" + ltrEntered.Text + "');";
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                        }

                        BindProducts(Convert.ToInt32(ddlArc.SelectedValue.ToString())); // Bind updated price/date with Gridview
                    }
                    else
                    {
                        string script = "alertify.alert('" + ltrNoProdMap.Text + "');";
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    }
                }

                else
                {
                    string script = "alertify.alert('" + ltrSelectARC.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                }
                audit.Notes     = "ARC: " + ddlArc.SelectedItem.ToString() + ", " + notes;
                audit.UserName  = Session[enumSessions.User_Name.ToString()].ToString();
                audit.ChangeID  = Convert.ToInt32(enumAudit.Manage_ARC_Product_Price);
                audit.CreatedOn = DateTime.Now;
                if (Request.ServerVariables["LOGON_USER"] != null)
                {
                    audit.WindowsUser = Request.ServerVariables["LOGON_USER"];
                }
                audit.IPAddress = Request.UserHostAddress;
                db.Audits.InsertOnSubmit(audit);
                db.SubmitChanges();
            }
            catch (Exception objException)
            {
                db = new CSLOrderingARCBAL.LinqToSqlDataContext();
                db.USP_SaveErrorDetails(Request.Url.ToString(), "btnSave_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()]));
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
    }
    protected void btnConfirmOrder_Click(object sender, EventArgs e)
    {
        try
        {
            ltrMessage.Visible = false;

            if (Session[enumSessions.OrderId.ToString()] == null) /* If someone clicks on back button - when the confirmation message is shown.*/
            {
                Response.Redirect("Login.aspx");
            }
            else if (dlProducts.Items.Count == 0)
            {
                ltrMessage.Visible = true;
                ltrMessage.Text    = "No item is added to confirm the order. Please add an item first to confirm the order.";
            }
            else
            {
                LinqToSqlDataContext db = new LinqToSqlDataContext();
                var orderStatus         = (from o in db.Orders
                                           where o.OrderId == Convert.ToInt32(Session[enumSessions.OrderId.ToString()])
                                           select o.OrderStatusId).SingleOrDefault();
                if (orderStatus != 1)
                {
                    Response.Redirect("Categories.aspx");
                }
                this.MaintainScrollPositionOnPostBack = true;

                if (divNewAddress.Visible)
                {
                    Page.Validate("grpDeliveryAddress");
                }

                if (divInstallationAddress.Visible)
                {
                    Page.Validate("grpInstallationAddress");
                }

                if (String.IsNullOrEmpty(txtOrderRefNo.Text.Trim()) == true)
                {
                    ltrMessage.Text         = "Please enter the ARC Order Reference number.";
                    txtOrderRefNo.BackColor = System.Drawing.Color.Yellow;
                    txtOrderRefNo.Focus();

                    return;
                }
                else
                {
                    Session[enumSessions.OrderRef.ToString()] = txtOrderRefNo.Text;
                }

                if (IsValid)
                {
                    btnConfirmOrder.Enabled = false;
                    int    addressId             = 0;
                    int    installationAddressId = 0;
                    string contactno             = txtDeliContactNo.Text.ToString().Trim();
                    string OrderNo = String.Empty;
                    if (rdoInstallerAddress.Checked)
                    {
                        addressId = InstallerBAL.SaveInstallerAddress(Session[enumSessions.InstallerCompanyID.ToString()].ToString(), txtInstContactName1.Text, contactno, 0, "", "", "", "", "", "", Session[enumSessions.User_Name.ToString()].ToString());
                    }
                    else if (ddlarcdeliveryaddresses.SelectedValue != "0" && (chkEditAddress.Checked == false) && !string.IsNullOrEmpty(ddlarcdeliveryaddresses.SelectedValue))
                    {
                        addressId = Convert.ToInt32(ddlarcdeliveryaddresses.SelectedValue);
                    }
                    else
                    {
                        int countryId = 0;
                        int.TryParse(ddlCountry.SelectedValue, out countryId);
                        addressId = InstallerBAL.SaveInstallerAddress("", txtDeliContactName.Text, contactno, countryId, txtDeliAddressOne.Text, txtDeliAddressTwo.Text, txtDeliTown.Text, txtDeliCounty.Text, txtDeliPostcode.Text, ddlCountry.SelectedItem.Text, Session[enumSessions.User_Name.ToString()].ToString());
                    }

                    if (chkInstallationAddress.Checked)
                    {
                        instadd_differs = true;
                        int countryId = 0;
                        int.TryParse(ddlInstCountry.SelectedValue, out countryId);
                        installationAddressId = InstallerBAL.SaveInstallerAddress("", txtInstContactName.Text, txtInstContactNumber.Text, countryId,
                                                                                  txtInstAddressOne.Text, txtInstAddressTwo.Text, txtInstTown.Text,
                                                                                  txtInstCounty.Text, txtInstPostCode.Text, ddlInstCountry.SelectedItem.Text, Session[enumSessions.User_Name.ToString()].ToString());
                    }
                    //Added below code by Atiq on 11-08-2016 for ESI changes
                    string alarmDelArcCode = string.Empty;
                    if (ddlArcBranches.SelectedIndex > 0)
                    {
                        var arcData = (from a in db.AlarmDeliveryARCMappings
                                       where a.ID == Convert.ToInt32(ddlArcBranches.SelectedValue)
                                       select a.Branch_ARC_Code).SingleOrDefault();
                        alarmDelArcCode = arcData;
                    }
                    int orderid = Convert.ToInt32(Session[enumSessions.OrderId.ToString()].ToString());
                    var ordrNo  = db.USP_ConfirmOrderDetails(orderid, txtOrderRefNo.Text, Convert.ToDecimal(lblDeliveryTotal.Text), addressId,
                                                             ddlDeliveryTypes.SelectedValue == String.Empty ? 0 : Convert.ToInt32(ddlDeliveryTypes.SelectedValue), txtInstructions.Text,
                                                             VATRate, Session[enumSessions.User_Name.ToString()].ToString(), installationAddressId, txtInstContactName1.Text,
                                                             alarmDelArcCode).SingleOrDefault();
                    if (ordrNo != null)
                    {
                        OrderNo = ordrNo.OrderNo;
                    }
                    db.SubmitChanges();

                    int orderHasEmizonProducts = (from O in db.Orders
                                                  join
                                                  oi in db.OrderItems on O.OrderId equals oi.OrderId
                                                  join
                                                  p in db.Products on oi.ProductId equals p.ProductId
                                                  where
                                                  O.OrderId == orderid
                                                  &&
                                                  p.IsEmizonProduct == true
                                                  &&
                                                  p.ProductType == "Product"
                                                  select p.EM_ProductCode).Count();

                    // ** Send to logistcs
                    SendEmailDTO sendEmaildto = new SendEmailDTO();
                    sendEmaildto.ARCOrderRefNo       = txtOrderRefNo.Text;
                    sendEmaildto.orderDate           = lblOrderDate.Text;
                    sendEmaildto.userID              = Session[enumSessions.User_Id.ToString()].ToString();
                    sendEmaildto.userName            = Session[enumSessions.User_Name.ToString()].ToString();
                    sendEmaildto.userEmail           = Session[enumSessions.User_Email.ToString()].ToString();
                    sendEmaildto.orderID             = Session[enumSessions.OrderId.ToString()].ToString();
                    sendEmaildto.DdeliveryType       = ddlDeliveryTypes.SelectedItem.Text;
                    sendEmaildto.deliveryCost        = lblDeliveryTotal.Text;
                    sendEmaildto.installerID         = Session[enumSessions.InstallerCompanyID.ToString()].ToString();
                    sendEmaildto.specialInstructions = txtInstructions.Text;

                    //Send to CSL Orders INBOX // do not send to emizon queue as its internal email and EM is not mandatory
                    SendEmail.SendEmailWithPrice(OrderNo, mailTO, sendEmaildto, mailFrom, mailCC, false, false, 0);

                    // ** Send to customers
                    if (Session[enumSessions.User_Role.ToString()] != null && Session[enumSessions.User_Role.ToString()].ToString() == enumRoles.ARC_Admin.ToString())
                    {
                        SendEmail.SendEmailWithoutPrice(OrderNo, Session[enumSessions.User_Email.ToString()].ToString(), sendEmaildto,
                                                        mailFrom, mailCC + "," + LoadARCEmailCC(), false, (orderHasEmizonProducts > 0) ? true : false, orderid);
                    }
                    else
                    {
                        SendEmail.SendEmailWithPrice(OrderNo, Session[enumSessions.User_Email.ToString()].ToString(), sendEmaildto,
                                                     mailFrom, mailCC + "," + LoadARCEmailCC(), false, (orderHasEmizonProducts > 0) ? true : false, orderid);
                    }

                    db.Dispose();
                    Session[enumSessions.OrderId.ToString()]     = null;
                    Session[enumSessions.OrderNumber.ToString()] = OrderNo;

                    //Add Emizon page redirection here
                    if (orderHasEmizonProducts > 0)
                    {
                        Response.Redirect("OrderConfirmationEM.aspx?id=" + orderid.ToString());
                    }
                    else
                    {
                        Response.Redirect("OrderConfirmation.aspx");
                    }
                }
                else
                {
                    btnConfirmOrder.Enabled = true;
                    txtDeliContactName.Focus();
                    this.MaintainScrollPositionOnPostBack = false;
                }
            }
        }
        catch (System.Threading.ThreadAbortException ex)
        {
            //
        }
        catch (Exception objException)
        {
            CSLOrderingARCBAL.LinqToSqlDataContext db;
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "btnConfirmOrder_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()]));
        }
    }
    protected void btnDeleted_Click(object sender, EventArgs e)
    {
        try
        {
            Audit  audit = new Audit();
            string notes = null;
            db = new LinqToSqlDataContext();
            foreach (GridViewRow row in gvProducts.Rows)
            {
                if (!String.IsNullOrEmpty((row.FindControl("ProductId") as Label).Text))
                {
                    Int32   productId = Convert.ToInt32((row.FindControl("ProductId") as Label).Text);
                    Boolean isDeleted = (row.FindControl("chkDelete") as CheckBox).Checked;


                    Decimal  objtxtPrice      = -1;
                    DateTime?objtxtExpiryDate = null;
                    Int32    objlblProuctId   = Convert.ToInt32((row.FindControl("ProductId") as Label).Text); // get product id
                    if ((row.FindControl("txtPrice") as TextBox).Text.Trim() != "")
                    {
                        objtxtPrice = Convert.ToDecimal((row.FindControl("txtPrice") as TextBox).Text); // get entered Price
                    }
                    if ((row.FindControl("txtExpiryDate") as TextBox).Text.Trim() != "")
                    {
                        objtxtExpiryDate = DateTime.Parse((row.FindControl("txtExpiryDate") as TextBox).Text); // get selected expiry date
                    }
                    if (isDeleted == true && objtxtPrice > -1 && objtxtExpiryDate != null)
                    {
                        var productPrice = (from p in db.ARC_Product_Price_Maps where p.ProductId == productId && p.ARCId == Convert.ToInt32(ddlArc.SelectedValue.ToString()) && p.IsDeleted == false select p).Single();
                        productPrice.IsDeleted  = true;
                        productPrice.ModifiedOn = DateTime.Now;
                        productPrice.ModifiedBy = Session[enumSessions.User_Id.ToString()].ToString();
                        db.SubmitChanges();

                        string script = "alertify.alert('" + ltrProdPriceDeleted.Text + "');";
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    }

                    notes += "Product: " + objlblProuctId + ", Price: " + objtxtPrice + ", Date: " + objtxtExpiryDate + ", ";
                }
            }

            BindProducts(Convert.ToInt32(ddlArc.SelectedValue.ToString())); // bind grid after delete ARC price

            audit.Notes     = "Deleted - ARC: " + ddlArc.SelectedItem.ToString() + ", " + notes;
            audit.UserName  = Session[enumSessions.User_Name.ToString()].ToString();
            audit.ChangeID  = Convert.ToInt32(enumAudit.Manage_ARC_Product_Price);
            audit.CreatedOn = DateTime.Now;
            if (Request.ServerVariables["LOGON_USER"] != null)
            {
                audit.WindowsUser = Request.ServerVariables["LOGON_USER"];
            }
            audit.IPAddress = Request.UserHostAddress;
            db.Audits.InsertOnSubmit(audit);
            db.SubmitChanges();
        }
        catch (Exception objException)
        {
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "btnDeleted_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()]));
        }
        finally
        {
            if (db != null)
            {
                db.Dispose();
            }
        }
    }
Exemple #24
0
    public void ProceedwithRequest(bool isEmizonDevice = false)
    {
        db = new LinqToSqlDataContext();
        DropDownList ddlinstaller = (DropDownList)Installers.FindControl("ddlInstallers");

        if (rpList.Items.Count > 0)
        {
            foreach (RepeaterItem ri in rpList.Items)
            {
                HtmlTableCell tdsim = (HtmlTableCell)ri.FindControl("tdSim");
                string        sim   = tdsim.InnerText.Trim();
                if (esn_sim.Text == sim)
                {
                    //lblAddItem.Visible=true;
                    return;
                }
            }
        }

        string dr = "";

        if (Request.QueryString["dr"].ToString() == "d")
        {
            dr = "Disconnect";
        }
        else
        {
            dr = "Reconnect";
        }



        DR drdata = new DR();

        drdata.ArcId  = Session[enumSessions.ARC_Id.ToString()].ToString();
        drdata.Chipno = chip.Text.ToString();
        drdata.Datano = nua_data.Text.ToString();
        drdata.date   = DateTime.Now.ToString();
        if (enablePostCodeSearch == true)
        {
            drdata.Installer = Session[enumSessions.InstallerCompanyID.ToString()].ToString().ToLower();
        }
        else
        {
            drdata.Installer = ddlinstaller.SelectedValue.ToString().ToLower();
        }
        if (Request["dr"].ToString() == "r")
        {
            drdata.Reason = "";
        }
        else
        {
            drdata.Reason = ddlReason.SelectedValue.ToString();
        }
        drdata.Req_Type         = dr;
        drdata.Simno            = esn_sim.Text.ToString();
        drdata.Emailed          = false;
        drdata.UserId           = Session[enumSessions.User_Id.ToString()].ToString();
        drdata.EMNo             = SelectedEMNo.Text.Trim();
        drdata.ISEmizonUnit     = isEmizonDevice;
        drdata.UserName         = Session[enumSessions.User_Name.ToString()].ToString();
        drdata.UserEmail        = Session[enumSessions.User_Email.ToString()].ToString();
        drdata.TobeUpdatedOnBOS = false;
        drdata.UpdatedOnBOS     = false;
        drdata.NoofAttempts     = 0;
        drdata.FreeTextEntry    = (esn_sim.Enabled) ?  true : false;

        if (isEmizonDevice)
        {
            drdata.EM_Platform = ArcBAL.GetEmizonPlatformbyARCID(Session[enumSessions.ARC_Id.ToString()].ToString());
        }

        db.DRs.InsertOnSubmit(drdata);
        db.SubmitChanges();
        ClearSelection();
        PopulateList();
    }
Exemple #25
0
        public void initialize()
        {
            LinqToSqlDataContext sqlContext = new LinqToSqlDataContext(new DataClasses1DataContext());

            _iDataContext = new MyProductsDataContext(sqlContext.Repository <Product>().ToList(), sqlContext.Repository <ProductReview>().ToList());
        }
Exemple #26
0
    /// <summary>
    /// Fetch the Device details
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GetDevice_Click(object sender, EventArgs e)
    {
        ClearSelection();
        if (Session[enumSessions.ARC_Id.ToString()] == null)
        {
            string script = "alertify.alert('" + ltrARCDetails.Text + "');";
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
            esn_sim.Text = ""; nua_data.Text = ""; chip.Text = "";
            return;
        }

        if ((String.IsNullOrEmpty(txtChipNo.Text.Trim())) && (String.IsNullOrEmpty(txtDatano.Text.Trim())) && (String.IsNullOrEmpty(txtEMNo.Text.Trim())) && (String.IsNullOrEmpty(txtInstallID.Text.Trim())))
        {
            string script = "alertify.alert('" + ltrEnterNo.Text + "');";
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
            esn_sim.Text = ""; nua_data.Text = ""; chip.Text = "";
            return;
        }

        try
        {
            if (!String.IsNullOrEmpty(txtChipNo.Text.Trim()))
            {
                if (txtChipNo.Text.Trim().Length < 4 || txtChipNo.Text.Trim().Length > 6)
                {
                    string script = "alertify.alert('" + ltrValidChpNo.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    esn_sim.Text = ""; nua_data.Text = ""; chip.Text = "";
                    return;
                }
            }
            using (LinqToSqlDataContext db = new LinqToSqlDataContext())
            {
                int    id       = Convert.ToInt32(Session[enumSessions.ARC_Id.ToString()]);
                string chipNo   = txtChipNo.Text.Trim();
                string dataNo   = txtDatano.Text.Trim();
                string ARC_Code = (from arc in db.ARCs
                                   where arc.ARCId == Convert.ToInt32(id)
                                   select arc.ARC_Code).SingleOrDefault();
                string EMNo      = txtEMNo.Text.Trim();
                string InstallID = txtInstallID.Text.Trim();

                List <BOSDeviceDTO> devicelist = CSLOrderingARCBAL.BAL.ArcBAL.GetDevice(chipNo, ARC_Code, dataNo, EMNo, InstallID);
                gvDevicelist.DataSource = devicelist;
                gvDevicelist.DataBind();
                if (devicelist != null && devicelist.Count > 0)
                {
                    if (devicelist.Count == 1)
                    {
                        gvDevicelist.SelectedIndex = 0;
                        gvDevicelist_SelectedIndexChanged(sender, e);
                    }
                }
                else
                {
                    string script = "alertify.alert('" + ltrAccount.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    gvDevicelist.SelectedIndex = 0;
                    gvDevicelist_SelectedIndexChanged(sender, e);
                }
            }
        }
        catch (Exception objException)
        {
            string script = "alertify.alert('" + ltrDetails.Text + "');";
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
            esn_sim.Text = ""; nua_data.Text = ""; chip.Text = ""; SelectedEMNo.Text = "";
            using (LinqToSqlDataContext db = new CSLOrderingARCBAL.LinqToSqlDataContext())
            {
                db.USP_SaveErrorDetails(Request.Url.ToString(), "GetDevice_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_Name.ToString()]));
            }
        }
    }
Exemple #27
0
    public void LoadUserInfo()
    {
        if (Session[enumSessions.User_Id.ToString()] != null)
        {
            ARC arc = ArcBAL.GetArcInfoByUserId(new Guid(Session[enumSessions.User_Id.ToString()].ToString()));

            if (arc == null)
            {
                ltrErrorMsg.Text = "User does not belong to any ARC.";
                return;
            }

            if (arc.IsBulkUploadAllowed)
            {
                hyprLnkBulkUpload.Visible = true;
            }

            Session[enumSessions.ARC_Id.ToString()]             = arc.ARCId;
            Session[enumSessions.IsARC_AllowReturns.ToString()] = arc.AllowReturns;

            lblUsername.Text = Session[enumSessions.User_Name.ToString()].ToString();

            if (arc.CompanyName.Length > 30)
            {
                lblARCCompany.Text = arc.CompanyName.Substring(0, 30) + "...";
            }
            else
            {
                lblARCCompany.Text = arc.CompanyName;
            }

            LinqToSqlDataContext db = new LinqToSqlDataContext();
            var OrderInfo           = db.USP_CreateOrderForUser(arc.ARCId, Session[enumSessions.User_Name.ToString()].ToString(), Session[enumSessions.User_Name.ToString()].ToString(), Session[enumSessions.User_Email.ToString()].ToString(), Session[enumSessions.User_Id.ToString()].ToString()).SingleOrDefault();
            if (OrderInfo != null)
            {
                Session[enumSessions.OrderId.ToString()] = OrderInfo.OrderId;
                lblOrderTotal.Text = OrderInfo.Amount.ToString();
                Session[enumSessions.HasUserAcceptedDuplicates.ToString()] = OrderInfo.HasUserAcceptedDuplicates;
                lblBasket.Text = OrderInfo.Quantity.ToString();
                Session[enumSessions.OrderNumber.ToString()] = OrderInfo.OrderNo.ToString();
                basketProducts = db.OrderItems.Where(num => num.OrderId == Convert.ToInt32(Session[enumSessions.OrderId.ToString()])).Count().ToString();
                if (basketProducts == "0")
                {
                    basketProducts = string.Empty;
                }


                if (OrderInfo.InstallerId != "0")
                {
                    Session[enumSessions.InstallerCompanyID.ToString()] = OrderInfo.InstallerId;
                    Session[enumSessions.SelectedInstaller.ToString()]  = OrderInfo.SelectedInstaller;
                }
            }
            db.Dispose();

            if (Session[enumSessions.User_Role.ToString()] != null && Session[enumSessions.User_Role.ToString()].ToString() == enumRoles.ARC_Admin.ToString())
            {
                lblOrderTotal.Text = "0.00";

                // AarcadminMenu.Style.Add("visibility", "visible");
            }
            Amyacc.Style.Add("visibility", "visible"); // Visible for all

            if (Session[enumSessions.SelectedInstaller.ToString()] != null)
            {
                if (Session[enumSessions.SelectedInstaller.ToString()].ToString().Length > 30)
                {
                    lblInstallerName.Text = Session[enumSessions.SelectedInstaller.ToString()].ToString().Substring(0, 30) + "...";
                }
                else
                {
                    lblInstallerName.Text = Session[enumSessions.SelectedInstaller.ToString()].ToString();
                }
            }

            if (Session[enumSessions.InstallerCompanyID.ToString()] != null)
            {
                HyperLink1.Enabled = true;
            }
            btnLogOut.Visible = true;
        }
        else
        {
            lblUsername.Text      = "Guest";
            lblARCCompany.Text    = "Guest";
            lblBasket.Text        = "0";
            lblOrderTotal.Text    = "0.00";
            lblInstallerName.Text = "";
        }
    }
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            LinqToSqlDataContext db = DatabaseSetup.Database;

            try
            {
                string   name         = ValidateProduct.Name(tbName.Text);
                int      quantity     = ValidateProduct.Quantity(tbQuantity.Text);
                string   unitName     = cbUnit.Text;
                decimal  unitQuantity = ValidateProduct.UnitQuantity(tbUnitQuantity.Text);
                DateTime?date         = ValidateProduct.Date(dpExpirationDate.SelectedDate);

                decimal price = ValidateProduct.Price(tbPrice.Text);
                price = Convert.ToDecimal(Math.Round(Convert.ToDouble(price), 1, MidpointRounding.AwayFromZero));
                bool priceForUnit = cbPriceForUnit.Text == "Ano" ? true : false;
                char VAT          = cbVAT.SelectedItem.ToString()[0];

                Product selectedProduct = (from p in db.Products
                                           where p.id == this._id
                                           select p).Single();

                int code = ValidateProduct.Code(tbCode.Text, selectedProduct.code);


                int uId = (from u in db.Units
                           where u.name == unitName
                           select u.id).Single();

                selectedProduct.name           = name;
                selectedProduct.quantity       = quantity;
                selectedProduct.unit           = uId;
                selectedProduct.unitQuantity   = unitQuantity;
                selectedProduct.expirationDate = date;
                selectedProduct.code           = code;
                selectedProduct.price          = price;
                selectedProduct.priceForUnit   = priceForUnit;
                selectedProduct.vatId          = VAT;

                db.SubmitChanges();
                DialogHelper.ShowInfo("Produkt byl upraven.");
                btnSubmit.IsEnabled = false;
            }
            catch (InvalidNameException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (InvalidQuantityException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (InvalidUnitQuantityException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (ExistingCodeException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (InvalidCodeException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }

            catch (InvalidPriceException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (NullDateTimeException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (Exception ex)
            {
                Errors.SaveError(ex.Message);
                DialogHelper.ShowError("Některé z polí není správně vyplněno.");
            }
        }
Exemple #29
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Page.Validate();
        if (Page.IsValid)
        {
            try
            {
                if (!string.IsNullOrEmpty(txtpwd.Text) && txtpwd.Text.Length < 6)
                {
                    string script = "alertify.alert('" + ltrSixChars.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    return;
                }

                var checkedroles = (from ListItem item in Chkboxroles.Items where item.Selected select item.Text).ToList();
                if (!checkedroles.Any())
                {
                    string script = "alertify.alert('" + ltrSelectRole.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    MaintainScrollPositionOnPostBack = false;
                    return;
                }
                if (Session[enumSessions.UserIdToUpdate.ToString()] == null)
                {
                    txtuname.Enabled = true;
                    if (!string.IsNullOrEmpty(txtpwd.Text.ToString().Trim()) && !string.IsNullOrEmpty(Txtuemail.Text.ToString().Trim()) && !string.IsNullOrEmpty(txtuname.Text.ToString().Trim()) && !string.IsNullOrEmpty(txtAnswer.Text.ToString().Trim()))
                    {
                        string username = txtuname.Text.ToString().Trim();
                        string password = txtpwd.Text.ToString().Trim();
                        string Emailid  = Txtuemail.Text.ToString().Trim();
                        string question = ddlSecurityQuestion.SelectedValue;
                        string answer   = txtAnswer.Text.ToString().Trim();
                        MembershipCreateStatus res;
                        MembershipUser         usr = Membership.CreateUser(username, password, Emailid, question, answer, ChkBoxIsapproved.Checked, out res);
                        if (usr == null)
                        {
                            string script = "alertify.alert('" + res.ToString() + "');";
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                            return;
                        }
                        else
                        {
                            Session[enumSessions.UserIdToUpdate.ToString()] = new Guid(usr.ProviderUserKey.ToString());
                            string script = "alertify.alert('User " + txtuname.Text + " created successfully.');";
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                            MaintainScrollPositionOnPostBack = false;
                        }
                    }
                }

                //updating user
                else
                {
                    if (!string.IsNullOrEmpty(Txtuemail.Text.ToString().Trim()) && !string.IsNullOrEmpty(txtuname.Text.ToString().Trim()))
                    {
                        txtuname.Enabled = false;
                        string         username = txtuname.Text.ToString().Trim();
                        string         password = txtpwd.Text.ToString().Trim();
                        string         Emailid  = Txtuemail.Text.ToString().Trim();
                        string         question = ddlSecurityQuestion.SelectedValue;
                        string         answer   = txtAnswer.Text.ToString().Trim();
                        MembershipUser user;
                        user = Membership.GetUser(new Guid(Session[enumSessions.UserIdToUpdate.ToString()].ToString()));
                        db   = new LinqToSqlDataContext();
                        var usrDtls = db.USP_GetUserDetailsByUserId(Session[enumSessions.UserIdToUpdate.ToString()].ToString()).FirstOrDefault();
                        //  string cur_pwd = user.GetPassword(usrDtls.PasswordAnswer);
                        //  user.ChangePasswordQuestionAndAnswer(cur_pwd, question, answer);//unable to retriee the password as password is hashed.

                        if (ChkBoxIsBlocked.Checked == false)
                        {
                            user.UnlockUser();
                        }
                        if (!string.IsNullOrEmpty(txtpwd.Text.ToString()))
                        {
                            user.ChangePassword(Membership.Provider.ResetPassword(username, usrDtls.PasswordAnswer), txtpwd.Text.ToString().Trim());//changed by Priya.
                        }

                        user.Email = Emailid.Trim();

                        Boolean approved = true;
                        if (ChkBoxIsapproved.Checked)
                        {
                            approved = true;
                        }
                        else
                        {
                            approved = false;
                        }

                        user.IsApproved = approved;
                        Membership.UpdateUser(user);

                        //deleting old existing roles of this user
                        string[] Rls = { "ARC_Manager", "ARC_Admin" };

                        foreach (string Urole in Rls)
                        {
                            if (Roles.IsUserInRole(txtuname.Text.ToString(), Urole))
                            {
                                Roles.RemoveUserFromRole(txtuname.Text.ToString(), Urole);
                            }
                        }

                        string script = "alertify.alert('User " + txtuname.Text + " updated successfully.');";
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                        MaintainScrollPositionOnPostBack = false;
                    }
                }

                //inserting checked roles
                for (int i = 0; i <= Chkboxroles.Items.Count - 1; i++)
                {
                    if (Chkboxroles.Items[i].Selected == true)
                    {
                        Roles.AddUserToRole(txtuname.Text.ToString(), Chkboxroles.Items[i].Text.ToString());
                    }
                }


                LoadData();
                MaintainScrollPositionOnPostBack = false;

                Audit audit = new Audit();
                audit.UserName  = Session[enumSessions.User_Name.ToString()].ToString();
                audit.ChangeID  = Convert.ToInt32(enumAudit.Update_User_Info);
                audit.CreatedOn = DateTime.Now;
                audit.IPAddress = Request.UserHostAddress;
                db.Audits.InsertOnSubmit(audit);
                db.SubmitChanges();
            }
            catch (Exception objException)
            {
                if (objException.Message.Trim() == "The E-mail supplied is invalid.")
                {
                    string script = "alertify.alert('" + ltrEmailExists.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                }
                db = new CSLOrderingARCBAL.LinqToSqlDataContext();
                db.USP_SaveErrorDetails(Request.Url.ToString(), "btnSave_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()]));
            }
        }
        else
        {
            string script = "alertify.alert('" + ltrFill.Text + "');";
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
            MaintainScrollPositionOnPostBack = false;
        }
    }
    protected void ProductsRepeater_ItemBound(object sender, RepeaterItemEventArgs args)
    {
        try
        {
            Session[enumSessions.PreviousOrderId.ToString()] = gvOrders.SelectedDataKey;

            if (args.Item.ItemType == ListItemType.Item || args.Item.ItemType == ListItemType.AlternatingItem)
            {
                LinqToSqlDataContext db = new LinqToSqlDataContext();
                if (String.IsNullOrEmpty(hidProductCode.Value))
                {
                    hidProductCode.Value = (args.Item.FindControl("lblProductCode") as Label).Text;
                }

                else if (hidProductCode.Value.ToString() != (args.Item.FindControl("lblProductCode") as Label).Text)
                {
                    hidProductCode.Value = (args.Item.FindControl("lblProductCode") as Label).Text;
                    count = 1;
                }
                if (Session[enumSessions.User_Role.ToString()] != null && Session[enumSessions.User_Role.ToString()].ToString() == enumRoles.ARC_Admin.ToString())
                {
                    Label lblProductPrice = (Label)args.Item.FindControl("lblProductPrice");
                    lblProductPrice.Text = "0.00";

                    Label lblProductPriceTotal = (Label)args.Item.FindControl("lblProductPriceTotal");
                    lblProductPriceTotal.Text = "0.00";
                }

                Label lblProductCode = (Label)args.Item.FindControl("lblProductCode");
                int   rowCount       = db.USP_GetBasketProductsOnCheckOut(Convert.ToInt32(hdnSelectedOrderID.Value)).Where(i => i.ProductCode == lblProductCode.Text.Trim()).Count();
                if (rowCount == count)
                {
                    USP_GetBasketProductsOnPreviousOrdersResult product = (USP_GetBasketProductsOnPreviousOrdersResult)args.Item.DataItem;
                    Repeater rep = (Repeater)args.Item.FindControl("rptrDependentProducts");

                    rep.DataSource = db.USP_GetBasketDependentProductsByProductId(Convert.ToInt32(hdnSelectedOrderID.Value), product.ProductId, product.CategoryId);
                    rep.DataBind();

                    if (rep.Items.Count == 0)
                    {
                        rep.Visible = false;
                    }

                    db.Dispose();
                }
                count++;
            }
            if (args.Item.ItemType == ListItemType.Footer)
            {
                Label lblTotalPrice = (Label)args.Item.FindControl("lblTotalPrice");
                Label lblTotalQty   = (Label)args.Item.FindControl("lblTotalQty");

                lblTotalPrice.Text = lblDtlsOrderTotal.Text;
                lblTotalQty.Text   = lblOrderQty.Text;

                if (Session[enumSessions.User_Role.ToString()] != null && Session[enumSessions.User_Role.ToString()].ToString() == enumRoles.ARC_Admin.ToString())
                {
                    lblTotalPrice.Text     = "0.00";
                    lblDtlsOrderTotal.Text = "0.00";
                    lblDtlsTotalToPay.Text = "0.00";
                }
            }
        }
        catch (Exception objException)
        {
            CSLOrderingARCBAL.LinqToSqlDataContext db;
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "ProductsRepeater_ItemBound", 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()]));
        }
    }