Ejemplo n.º 1
0
        void SaveNewsItem()
        {
            var editing        = RecordId != 0;
            var selectedLocale = LocaleSelector.GetSelectedLocale().Name;
            var expirationDate = txtDate.SelectedDate ?? System.DateTime.Now.AddMonths(1);
            var headline       = editing
                                ? AppLogic.FormLocaleXml("Headline", txtHeadline.Text.Trim(), selectedLocale, "News", RecordId)
                                : AppLogic.FormLocaleXml(txtHeadline.Text.Trim(), selectedLocale);

            var copyContent = UseHtmlEditor
                                ? radCopy.Content
                                : txtCopy.Text;

            var copy = editing
                                ? AppLogic.FormLocaleXml("NewsCopy", copyContent, selectedLocale, "News", RecordId)
                                : AppLogic.FormLocaleXml(copyContent, selectedLocale);

            var parameters = new[]
            {
                new SqlParameter("@newsId", RecordId),
                new SqlParameter("@headline", headline),
                new SqlParameter("@copy", copy),
                new SqlParameter("@expirationDate", expirationDate),
                new SqlParameter("@published", cbxPublished.Checked)
            };

            var query = editing
                                ? "UPDATE News SET Headline = @headline, NewsCopy = @copy, Published = @published, ExpiresOn = @expirationDate WHERE NewsID = @newsID"
                                : "INSERT News (Headline, NewsCopy, Published, ExpiresOn) VALUES (@headline, @copy, @published, @expirationDate); select cast(SCOPE_IDENTITY() as int) N;";

            var identity = DB.GetSqlN(query, parameters);

            if (!editing)
            {
                RecordId = identity;
            }

            StoresMapping.ObjectID = RecordId;
            StoresMapping.Save();
        }
Ejemplo n.º 2
0
        protected void updateOrderOptions()
        {
            ltValid.Text = "";

            string pageLocale = ddlPageLocales.SelectedValue;

            if (pageLocale.Equals(string.Empty))
            {
                pageLocale = Localization.GetDefaultLocale();
            }

            if (validateForm())
            {
                StringBuilder sql  = new StringBuilder();
                decimal       Cost = System.Decimal.Zero;
                if (txtCost.Text.Length != 0)
                {
                    Cost = Localization.ParseNativeDecimal(txtCost.Text);
                }

                bool Editing       = Localization.ParseBoolean(ViewState["EditingOrderOptions"].ToString());
                int  OrderOptionID = Localization.ParseNativeInt(ViewState["EditingOrderOptionsID"].ToString());


                if (!Editing)
                {
                    // ok to add them:
                    String NewGUID = DB.GetNewGUID();
                    sql.Append("insert into OrderOption(OrderOptionGUID,Name,Description,DefaultIsChecked,TaxClassID,Cost) values(");
                    sql.Append(DB.SQuote(NewGUID) + ",");
                    sql.Append(DB.SQuote(AppLogic.FormLocaleXml(ltName.Text, pageLocale)) + ",");
                    String desc = String.Empty;
                    if (bUseHtmlEditor)
                    {
                        desc = AppLogic.FormLocaleXml(radDescription.Content, pageLocale);
                    }
                    else
                    {
                        desc = AppLogic.FormLocaleXmlEditor("Description", "Description", pageLocale, "orderoption", OrderOptionID);
                    }
                    if (desc.Length != 0)
                    {
                        sql.Append(DB.SQuote(desc) + ",");
                    }
                    else
                    {
                        sql.Append("NULL,");
                    }
                    sql.Append(rbIsChecked.SelectedValue + ",");
                    sql.Append(ddTaxClass.SelectedValue + ",");
                    sql.Append(CommonLogic.IIF(Cost != System.Decimal.Zero, Localization.DecimalStringForDB(Cost), "0.0"));
                    sql.Append(")");
                    DB.ExecuteSQL(sql.ToString());

                    resetError("Order Option added.", false);

                    using (SqlConnection dbconn = DB.dbConn())
                    {
                        dbconn.Open();
                        using (IDataReader rs = DB.GetRS("select OrderOptionID from OrderOption   with (NOLOCK)  where OrderOptionGUID=" + DB.SQuote(NewGUID), dbconn))
                        {
                            rs.Read();
                            OrderOptionID = DB.RSFieldInt(rs, "OrderOptionID");
                            ViewState["EditingOrderOptions"]   = true;
                            ViewState["EditingOrderOptionsID"] = OrderOptionID.ToString();
                        }
                    }
                }
                else
                {
                    // ok to update:
                    sql.Append("update OrderOption set ");
                    sql.Append("Name=" + DB.SQuote(AppLogic.FormLocaleXml("Name", ltName.Text, pageLocale, "OrderOption", OrderOptionID)) + ",");
                    String desc = String.Empty;
                    if (bUseHtmlEditor)
                    {
                        desc = AppLogic.FormLocaleXml("Description", radDescription.Content, pageLocale, "OrderOption", OrderOptionID);
                    }
                    else
                    {
                        desc = AppLogic.FormLocaleXmlEditor("Description", "Description", pageLocale, "OrderOption", OrderOptionID);
                    }
                    if (desc.Length != 0)
                    {
                        sql.Append("Description=" + DB.SQuote(desc) + ",");
                    }
                    else
                    {
                        sql.Append("Description=NULL,");
                    }
                    sql.Append("DefaultIsChecked=" + rbIsChecked.SelectedValue + ",");
                    sql.Append("TaxClassID=" + ddTaxClass.SelectedValue + ",");
                    sql.Append("Cost=" + CommonLogic.IIF(Cost != System.Decimal.Zero, Localization.DecimalStringForDB(Cost), "0.0"));
                    sql.Append(" where OrderOptionID=" + OrderOptionID.ToString());
                    DB.ExecuteSQL(sql.ToString());

                    resetError(AppLogic.GetString("admin.orderOption.OrderOptionUpdated", SkinID, LocaleSetting), false);
                }
                StoresMapping.ObjectID = OrderOptionID;
                StoresMapping.Save();

                loadDL();
                // handle image uploaded:
                try
                {
                    String         Image1     = String.Empty;
                    HttpPostedFile Image1File = fuIcon.PostedFile;
                    if (Image1File.ContentLength != 0)
                    {
                        // delete any current image file first
                        try
                        {
                            System.IO.File.Delete(AppLogic.GetImagePath("OrderOption", "icon", true) + OrderOptionID.ToString() + ".jpg");
                            System.IO.File.Delete(AppLogic.GetImagePath("OrderOption", "icon", true) + OrderOptionID.ToString() + ".gif");
                            System.IO.File.Delete(AppLogic.GetImagePath("OrderOption", "icon", true) + OrderOptionID.ToString() + ".png");
                        }
                        catch
                        { }

                        String s = Image1File.ContentType;
                        switch (Image1File.ContentType)
                        {
                        case "image/gif":
                            Image1 = AppLogic.GetImagePath("OrderOption", "icon", true) + OrderOptionID.ToString() + ".gif";
                            Image1File.SaveAs(Image1);
                            break;

                        case "image/x-png":
                            Image1 = AppLogic.GetImagePath("OrderOption", "icon", true) + OrderOptionID.ToString() + ".png";
                            Image1File.SaveAs(Image1);
                            break;

                        case "image/jpg":
                        case "image/jpeg":
                        case "image/pjpeg":
                            Image1 = AppLogic.GetImagePath("OrderOption", "icon", true) + OrderOptionID.ToString() + ".jpg";
                            Image1File.SaveAs(Image1);
                            break;
                        }
                    }

                    getOrderOptionsDetails();
                }
                catch (Exception ex)
                {
                    ltError.Text = CommonLogic.GetExceptionDetail(ex, "<br/>");
                }
            }
        }
Ejemplo n.º 3
0
        bool SaveForm(int recordId)
        {
            var saved   = false;
            var editing = recordId != 0;

            try
            {
                var optionTaxClassId = int.Parse(ddlTaxClass.SelectedValue);

                var optionCost = 0m;
                var parsedCost = 0m;
                if (decimal.TryParse(txtCost.Text.Trim(), out parsedCost))
                {
                    optionCost = parsedCost;
                }

                var optionDisplayOrder = 1;
                var parsedDisplayOrder = 0;
                if (int.TryParse(txtDisplayOrder.Text.Trim(), out parsedDisplayOrder))
                {
                    optionDisplayOrder = parsedDisplayOrder;
                }

                var optionName = editing
                                        ? AppLogic.FormLocaleXml("Name", txtName.Text.Trim(), Locale, "orderoption", recordId)
                                        : AppLogic.FormLocaleXml(txtName.Text.Trim(), Locale);

                var description = String.Empty;
                if (editing)
                {
                    if (UseHtmlEditor)
                    {
                        description = AppLogic.FormLocaleXml("Description", radCopy.Content, Locale, "orderoption", recordId);
                    }
                    else
                    {
                        description = AppLogic.FormLocaleXmlEditor("Description", "Description", Locale, "orderoption", recordId);
                    }
                }
                else
                {
                    if (UseHtmlEditor)
                    {
                        description = AppLogic.FormLocaleXml(radCopy.Content, Locale);
                    }
                    else
                    {
                        description = AppLogic.FormLocaleXmlEditor("Description", "Description", Locale, "orderoption", recordId);
                    }
                }

                var parameters = new[]
                {
                    new SqlParameter("@OrderOptionID", recordId),
                    new SqlParameter("@Name", optionName),
                    new SqlParameter("@Description", description),
                    new SqlParameter("@Cost", optionCost),
                    new SqlParameter("@DisplayOrder", optionDisplayOrder),
                    new SqlParameter("@TaxClassID", optionTaxClassId)
                };

                var query = editing
                                        ? "UPDATE OrderOption SET Name = @Name, Description = @Description, Cost = @Cost, DisplayOrder = @DisplayOrder, TaxClassID = @TaxClassID WHERE OrderOptionID = @OrderOptionID"
                                        : "INSERT INTO OrderOption (Name, Description, Cost, DisplayOrder, TaxClassID) VALUES (@Name, @Description, @Cost, @DisplayOrder, @TaxClassID); select cast(SCOPE_IDENTITY() as int) N;";

                var identity = DB.GetSqlN(query, parameters);

                if (!editing)
                {
                    RecordId = identity;
                }

                StoresMapping.ObjectID = RecordId;
                StoresMapping.Save();

                SaveIconImage(RecordId);

                saved = true;
                ctlAlertMessage.PushAlertMessage("admin.orderdetails.UpdateSuccessful".StringResource(), AlertMessage.AlertType.Success);
            }
            catch (Exception exception)
            {
                ctlAlertMessage.PushAlertMessage(exception.Message, AlertMessage.AlertType.Error);
            }

            return(saved);
        }