예제 #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!Visible)
        {
            return;
        }

        if (ValidateFormData())
        {
            var parameters = _ucSpecific == null ? null : _ucSpecific.Parameters;

            if (parameters != null)
            {
                var method = new ShippingMethod
                {
                    Type             = ShippingType,
                    ShippingMethodId = ShippingMethodID,
                    Name             = txtName.Text,
                    Description      = txtDescription.Text,
                    SortOrder        = txtSortOrder.Text.TryParseInt(),
                    Enabled          = chkEnabled.Checked && (_ucSpecific == null || _ucSpecific.Parameters != null)
                };
                if (ShippingMethodService.UpdateShippingMethod(method))
                {
                    if (ShippingType == ShippingType.eDost)
                    {
                        //COD
                        if (Convert.ToBoolean(parameters[EdostTemplate.EnabledCOD]))
                        {
                            int idShip = 0;
                            Int32.TryParse(parameters[EdostTemplate.ShipIdCOD], out idShip);
                            var payment = PaymentService.GetPaymentMethod(idShip);
                            if (payment == null)
                            {
                                var payMethod = PaymentMethod.Create(PaymentType.CashOnDelivery);
                                payMethod.Name    = Resources.Resource.CashOnDeliveryName;
                                payMethod.Enabled = true;
                                if (payMethod.Parameters.ContainsKey(CashOnDelivery.ShippingMethodTemplate))
                                {
                                    payMethod.Parameters[CashOnDelivery.ShippingMethodTemplate] = ShippingMethodID.ToString();
                                }
                                else
                                {
                                    payMethod.Parameters.Add(CashOnDelivery.ShippingMethodTemplate,
                                                             ShippingMethodID.ToString());
                                }

                                var id = PaymentService.AddPaymentMethod(payMethod);
                                parameters[EdostTemplate.ShipIdCOD] = id.ToString();
                            }
                        }
                        else
                        {
                            int idShip = 0;
                            Int32.TryParse(parameters[EdostTemplate.ShipIdCOD], out idShip);
                            PaymentService.DeletePaymentMethod(idShip);
                        }

                        //PickPoint
                        if (Convert.ToBoolean(parameters[EdostTemplate.EnabledPickPoint]))
                        {
                            int idShip = 0;
                            Int32.TryParse(parameters[EdostTemplate.ShipIdPickPoint], out idShip);
                            var payment = PaymentService.GetPaymentMethod(idShip);
                            if (payment == null)
                            {
                                var payMethod = PaymentMethod.Create(PaymentType.PickPoint);
                                payMethod.Name    = Resources.Resource.OrderPickPointMessage;
                                payMethod.Enabled = true;
                                if (payMethod.Parameters.ContainsKey(PickPoint.ShippingMethodTemplate))
                                {
                                    payMethod.Parameters[PickPoint.ShippingMethodTemplate] = ShippingMethodID.ToString();
                                }
                                else
                                {
                                    payMethod.Parameters.Add(PickPoint.ShippingMethodTemplate, ShippingMethodID.ToString());
                                }
                                var id = PaymentService.AddPaymentMethod(payMethod);
                                parameters[EdostTemplate.ShipIdPickPoint] = id.ToString();
                            }
                        }
                        else
                        {
                            int idShip = 0;
                            Int32.TryParse(parameters[EdostTemplate.ShipIdPickPoint], out idShip);
                            PaymentService.DeletePaymentMethod(idShip);
                        }
                    }

                    var payments = new System.Collections.Generic.List <int>();
                    foreach (RepeaterItem item in rptrPayments.Items)
                    {
                        if (!((CheckBox)item.FindControl("ckbUsePayment")).Checked)
                        {
                            payments.Add(Convert.ToInt32(((HiddenField)item.FindControl("hfPaymentId")).Value));
                        }
                    }
                    ShippingMethodService.UpdateShippingPayments(ShippingMethodID, payments);

                    if (ShippingMethodService.UpdateShippingParams(method.ShippingMethodId, parameters))
                    {
                        Method = ShippingMethodService.GetShippingMethod(method.ShippingMethodId);
                        LoadFormData(_ucSpecific != null && _ucSpecific.Parameters != null);
                        OnSaved(new SavedEventArgs {
                            Enabled = method.Enabled, Name = method.Name
                        });
                    }
                }
            }
        }
    }
        private void BindPage()
        {
            using (SqlConnection dbconn = DB.dbConn())
            {
                dbconn.Open();
                using (IDataReader rs = DB.GetRS("select Name, DisplayName, IsRTShipping, ImageFileName from ShippingMethod with (NOLOCK) where ShippingMethodID=" + ShippingMethodID.ToString(), dbconn))
                {
                    if (rs.Read())
                    {
                        Editing = true;
                    }

                    if (DB.RSFieldBool(rs, "IsRTShipping"))
                    {
                        DisplayNameLocaleField.Text = DB.RSField(rs, "DisplayName");
                        IsRealTime = true;
                    }
                    else
                    {
                        DisplayNameRow.Visible = false;
                    }

                    NameLocaleField.Text   = DB.RSField(rs, "Name");
                    SelectedImageFileName  = DB.RSField(rs, "ImageFileName");
                    hdnImageFileName.Value = SelectedImageFileName;
                }
            }

            // Databind the image file name repeater
            ImageFileNameList.DataSource = Shipping.GetShippingIconFileNames();

            if (ShippingMethodStoreFilteringEnabled)
            {
                StoreMappingPanel.Visible   = true;
                MappedStores.DataSource     = Store.GetStoreList();
                MappedStores.DataValueField = "StoreID";
                MappedStores.DataTextField  = "Name";
                MappedStores.DataBind();

                //wire up existing mappings
                if (Editing)
                {
                    //bind the store mapper
                    var sqlParameters = new SqlParameter[] {
                        new SqlParameter {
                            ParameterName = "ShippingMethodID",
                            Value         = ShippingMethodID
                        }
                    };
                    var sql = "SELECT StoreId FROM ShippingMethodStore WITH (NOLOCK) WHERE ShippingMethodId = @ShippingMethodID";

                    using (SqlConnection conn = new SqlConnection(DB.GetDBConn()))
                    {
                        conn.Open();

                        using (IDataReader rsMap = DB.GetRS(sql, sqlParameters, conn))
                        {
                            while (rsMap.Read())
                            {
                                var storeId = rsMap.FieldInt("StoreId");
                                foreach (ListItem item in MappedStores.Items)
                                {
                                    if (item.Value == storeId.ToString())
                                    {
                                        item.Selected = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            ImageFileNameList.DataBind();
        }
예제 #3
0
        private void RenderHtml()
        {
            StringBuilder writer = new StringBuilder();

            if (!String.IsNullOrEmpty(ErrorMsg))
            {
                writer.Append("<p><b><font color=red>" + ErrorMsg + "</font></b></p>\n");
            }

            if (DataUpdated)
            {
                writer.Append("<p align=\"left\"><b><font color=blue>" + AppLogic.GetString("admin.editCreditCard.Updated", SkinID, LocaleSetting) + "</font></b></p>\n");
            }

            if (AppLogic.NumLocaleSettingsInstalled() > 1)
            {
                writer.Append("<script type='text/javascript' src='Scripts/tabs.js'></script>");
            }

            if (!String.IsNullOrEmpty(ErrorMsg))
            {
                ltContent.Text = writer.ToString();
                return;
            }

            using (SqlConnection dbconn = DB.dbConn())
            {
                dbconn.Open();
                using (IDataReader rs = DB.GetRS("select * from ShippingMethod   with (NOLOCK)  where ShippingMethodID=" + ShippingMethodID.ToString(), dbconn))
                {
                    if (rs.Read())
                    {
                        Editing = true;
                    }

                    if (Editing)
                    {
                        writer.Append("<b>" + String.Format(AppLogic.GetString("admin.editshippingmethod.EditingShippingMethod", SkinID, LocaleSetting), DB.RSFieldByLocale(rs, "Name", LocaleSetting), DB.RSFieldInt(rs, "ShippingMethodID").ToString()) + "<br/><br/></b>\n");
                    }
                    else
                    {
                        writer.Append("<div style=\"height:17;padding-top:3px;\" class=\"tablenormal\">" + AppLogic.GetString("admin.editshippingmethod.AddNewShippingMethod", SkinID, LocaleSetting) + ":</div><br/></b>\n");
                    }

                    writer.Append("<script type=\"text/javascript\">\n");
                    writer.Append("function ShippingMethodForm_Validator(theForm)\n");
                    writer.Append("{\n");
                    writer.Append("submitonce(theForm);\n");
                    writer.Append("return (true);\n");
                    writer.Append("}\n");
                    writer.Append("</script>\n");

                    writer.Append("<p>" + AppLogic.GetString("admin.editshippingmethod.ShippingMethodInfo", SkinID, LocaleSetting) + "</p>\n");
                    writer.Append("<form action=\"" + AppLogic.AdminLinkUrl("editshippingmethod.aspx") + "?ShippingMethodID=" + ShippingMethodID.ToString() + "&edit=" + Editing.ToString() + "\" method=\"post\" id=\"ShippingMethodForm\" name=\"ShippingMethodForm\" onsubmit=\"return (validateForm(this) && ShippingMethodForm_Validator(this))\" onReset=\"return confirm('" + AppLogic.GetString("admin.common.ResetAllFieldsPrompt", SkinID, LocaleSetting) + "');\">\n");
                    writer.Append("<input type=\"hidden\" name=\"IsSubmit\" value=\"true\">\n");
                    writer.Append("<table width=\"100%\" cellpadding=\"4\" cellspacing=\"0\">\n");
                    writer.Append("              <tr valign=\"middle\">\n");
                    writer.Append("                <td width=\"100%\" colspan=\"2\" align=\"left\">\n");
                    writer.Append("                </td>\n");
                    writer.Append("              </tr>\n");
                    writer.Append("              <tr valign=\"middle\">\n");
                    writer.Append("                <td width=\"25%\" align=\"right\" valign=\"middle\">*" + AppLogic.GetString("admin.common.Name", SkinID, LocaleSetting) + ":&nbsp;&nbsp;</td>\n");
                    writer.Append("                <td align=\"left\" valign=\"top\">\n");
                    if (DB.RSFieldBool(rs, "IsRTShipping"))
                    {
                        writer.Append(DB.RSFieldByLocale(rs, "Name", LocaleSetting));
                    }
                    else
                    {
                        writer.Append(AppLogic.GetLocaleEntryFields(DB.RSField(rs, "Name"), "Name", false, true, true, AppLogic.GetString("admin.editshippingmethod.EnterShippingMethod", SkinID, LocaleSetting), 100, 30, 0, 0, false));
                    }

                    writer.Append("                	</td>\n");
                    writer.Append("              </tr>\n");

                    if (AppLogic.AppConfigBool("ShipRush.Enabled"))
                    {
                        writer.Append("              <tr valign=\"middle\">\n");
                        writer.Append("                <td width=\"25%\" align=\"right\" valign=\"middle\">*" + AppLogic.GetString("admin.editshippingmethod.ShipRushTemplate", SkinID, LocaleSetting) + ":&nbsp;&nbsp;</td>\n");
                        writer.Append("                <td align=\"left\">\n");
                        writer.Append("                	<input maxLength=\"100\" size=\"50\" name=\"ShipRushTemplate\" value=\"" + CommonLogic.IIF(Editing, Server.HtmlEncode(DB.RSField(rs, "ShipRushTemplate")), "") + "\"> " + AppLogic.GetString("admin.editshippingmethod.Sample", SkinID, LocaleSetting) + "\n");
                        writer.Append("                	</td>\n");
                        writer.Append("              </tr>\n");
                    }
                }
            }

            if (MultiStoreFilteringEnabled)
            {
                List <int> mappedStoreIds = new List <int>();
                string     mappingQuery   = string.Format("SELECT StoreId FROM ShippingMethodStore WITH (NOLOCK) WHERE ShippingMethodId = {0}", ShippingMethodID);

                if (Editing)
                {
                    using (SqlConnection conn = new SqlConnection(DB.GetDBConn()))
                    {
                        conn.Open();

                        using (IDataReader rsMap = DB.GetRS(mappingQuery, conn))
                            while (rsMap.Read())
                            {
                                mappedStoreIds.Add(rsMap.FieldInt("StoreId"));
                            }
                    }
                }

                writer.Append("              <tr valign=\"middle\">\n");
                writer.Append("                <td width=\"25%\" align=\"right\" valign=\"middle\">" + AppLogic.GetString("admin.editshippingmethod.MappedStores", SkinID, LocaleSetting) + ":&nbsp;&nbsp;</td>\n");
                writer.Append("                <td align=\"left\">\n");

                foreach (var store in Store.GetStoreList())
                {
                    bool   alreadyMapped = Editing && mappedStoreIds.Contains(store.StoreID);
                    string html          = string.Format("<input type=\"checkbox\" name=\"chkStoreMap_{0}\" value=\"{1}\" {2} /> {1}\n", store.StoreID, HttpUtility.HtmlEncode(store.Name), alreadyMapped ? "checked" : string.Empty);
                    writer.Append(html + "<br />");
                }

                writer.Append("                	</td>\n");
                writer.Append("              </tr>\n");
            }


            writer.Append("<tr>\n");
            writer.Append("<td></td><td align=\"left\" valign=\"top\"><br/>\n");

            string backText = string.Empty;

            if (Editing)
            {
                writer.Append("<input class=\"normalButtons\" type=\"submit\" value=\"" + AppLogic.GetString("admin.common.Update", SkinID, LocaleSetting) + "\" name=\"submit\">\n");
                backText = AppLogic.GetString("admin.common.Back", SkinID, LocaleSetting);
            }
            else
            {
                writer.Append("<input type=\"submit\" class=\"normalButtons\" value=\"" + AppLogic.GetString("admin.common.AddNew", SkinID, LocaleSetting) + "\" name=\"submit\">\n");
                backText = AppLogic.GetString("admin.common.Cancel", SkinID, LocaleSetting);
            }

            string backLink = string.Format("&nbsp;<a href=\"" + AppLogic.AdminLinkUrl("shippingmethods.aspx") + "?storeid={0}\">{1}</a>", StoreFilter, backText);

            writer.Append(backLink);

            writer.Append("        </td>\n");
            writer.Append("      </tr>\n");
            writer.Append("  </table>\n");
            writer.Append("</form>\n");

            ltContent.Text = writer.ToString();
        }