www.pudn.com > Tustena_CRM_OS_3.0.2_Stable.zip > currency.ascx.cs
///TUSTENA PUBLIC LICENSE v1.0 ////// Portions Copyright (c) 2003-2005 Digita S.r.l. All Rights Reserved. /// /// Tustena CRM is a trademark of: /// Digita S.r.l. /// Viale Enrico Fermi 14/z /// 31011 Asolo (Italy) /// Tel. +39-0423-951251 /// Mail. info@digita.it /// /// This file contains Original Code and/or Modifications of Original Code /// as defined in and that are subject to the Tustena Public Source License /// Version 1.0 (the 'License'). You may not use this file except in /// compliance with the License. Please obtain a copy of the License at /// http://www.tustena.com/TPL/ and read it before using this // file. /// /// The Original Code and all software distributed under the License are /// distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER /// EXPRESS OR IMPLIED, AND DIGITA S.R.L. HEREBY DISCLAIMS ALL SUCH WARRANTIES, /// INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, /// FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. /// Please see the License for the specific language governing rights and /// limitations under the License. /// /// YOU MAY NOT REMOVE OR ALTER THIS COPYRIGHT NOTICE! /// using System; using System.Data; using System.Resources; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using Digita.Tustena.Base; using Digita.Tustena.Database; using Digita.Tustena.Localize; namespace Digita.Tustena.Admin { public class currency : UserControl { protected TextBox CurrName; protected TextBox CurrChange1; protected TextBox CurrChange2; protected TextBox CurrSymbol; protected TextBox CurrID; protected LinkButton CurrSubmit; protected Repeater CurrencyRepeater; protected Label currencySymbol; protected LinkButton ChangeCurrency; protected Label CurrInfo; protected HtmlTable companyCurrencyTable; protected HtmlTable currencyTable; protected DropDownList DropCompanyCurrency; protected LinkButton NewCurrSubmit; protected TextBox NewCurrName; protected TextBox NewCurrSymbol; protected Label CurrInfo2; public G G = new G(); private UserConfig UC = new UserConfig(); protected LocalizedLiteral LocalizedLiteral1; protected LocalizedLiteral LocalizedLiteral2; protected LocalizedLiteral LocalizedLiteral3; protected LocalizedLiteral LocalizedLiteral4; protected LocalizedLiteral LocalizedLiteral5; protected LocalizedLiteral LocalizedLiteral6; protected LocalizedLiteral LocalizedLiteral7; protected LocalizedLiteral LocalizedLiteral8; public static ResourceManager rm = (ResourceManager) HttpContext.Current.Application["RM"]; private void Page_Load(object sender, EventArgs e) { UC = (UserConfig) HttpContext.Current.Session["userconfig"]; if (!Page.IsPostBack) { Start(); } } private void Start() { CurrSubmit.Text = rm.GetString("Save"); NewCurrSubmit.Text = rm.GetString("Save"); CurrChange1.Attributes.Add("onchange", "change(0)"); CurrChange2.Attributes.Add("onchange", "change(1)"); CancelForm(); CurrencyRepeater.DataSource = DatabaseConnection.CreateDataset("select * from CurrencyTable").Tables[0]; CurrencyRepeater.DataBind(); CurrencyRepeater.Visible = true; currencyTable.Visible = true; currencySymbol.Text = DatabaseConnection.SqlScalar("select currency from currencytable where (changetoeuro=1 and changefromeuro=1)"); ChangeCurrency.Text = rm.GetString("Curtxt7"); companyCurrencyTable.Visible = false; } private void CancelForm() { CurrName.Text = String.Empty; CurrChange1.Text = String.Empty; CurrChange2.Text = String.Empty; CurrSymbol.Text = String.Empty; CurrID.Text = "-1"; } #region Codice generato da Progettazione Web Form protected override void OnInit(EventArgs e) { InitializeComponent(); base.OnInit(e); } private void InitializeComponent() { this.ChangeCurrency.Click += new EventHandler(this.ChangeCurrency_Click); this.NewCurrSubmit.Click += new EventHandler(this.NewCurrSubmit_Click); this.CurrSubmit.Click += new EventHandler(this.CurrSubmit_Click); this.CurrencyRepeater.ItemDataBound += new RepeaterItemEventHandler(this.CurrencyRepeater_ItemDataBound); this.CurrencyRepeater.ItemCommand += new RepeaterCommandEventHandler(this.CurrencyRepeater_ItemCommand); this.Load += new EventHandler(this.Page_Load); } #endregion private void CurrSubmit_Click(object sender, EventArgs e) { try { int cId = int.Parse(CurrID.Text); using (DigiDapter dg = new DigiDapter()) { dg.Add("Currency", CurrName.Text); dg.Add("CurrencySymbol", CurrSymbol.Text); dg.Add("ChangeToEuro", StaticFunctions.FixDecimal(CurrChange1.Text)); dg.Add("ChangeFromEuro", StaticFunctions.FixDecimal(CurrChange2.Text)); dg.Execute("currencytable", "ID =" + cId); } CurrencyRepeater.DataSource = DatabaseConnection.CreateDataset("select * from CurrencyTable").Tables[0]; CurrencyRepeater.DataBind(); CancelForm(); Start(); } catch { Page.RegisterStartupScript("", ""); } } private void CurrencyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { switch (e.Item.ItemType) { case ListItemType.Item: case ListItemType.AlternatingItem: LinkButton edit = (LinkButton) e.Item.FindControl("edit"); edit.Text = rm.GetString("Modify"); LinkButton delete = (LinkButton) e.Item.FindControl("Delete"); delete.Text = rm.GetString("Delete"); delete.Attributes.Add("onclick", "return confirm('" + rm.GetString("Curtxt13") + "')"); if ((double) DataBinder.Eval((DataRowView) e.Item.DataItem, "ChangeToEuro") == 1 && (double) DataBinder.Eval((DataRowView) e.Item.DataItem, "ChangeToEuro") == 1) { edit.Visible = false; delete.Visible = false; } break; } } private void CurrencyRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) { int cId = int.Parse(((Literal) e.Item.FindControl("CurrencyID")).Text); switch (e.CommandName) { case "edit": DataRow dr = DatabaseConnection.CreateDataset("select * from currencytable where id=" + cId).Tables[0].Rows[0]; CurrName.Text = dr["Currency"].ToString(); CurrSymbol.Text = dr["CurrencySymbol"].ToString(); CurrChange1.Text = dr["ChangeToEuro"].ToString(); CurrChange2.Text = dr["ChangeFromEuro"].ToString(); CurrID.Text = dr["id"].ToString(); break; case "Delete": DatabaseConnection.DoCommand("delete from currencytable where id=" + cId); Start(); break; } } private void ChangeCurrency_Click(object sender, EventArgs e) { companyCurrencyTable.Visible = true; currencyTable.Visible = false; this.CurrencyRepeater.Visible = false; CurrInfo.Text = String.Format(rm.GetString("Curtxt8"), DatabaseConnection.SqlScalar("select count(*) from CatalogProducts")); DropCompanyCurrency.DataTextField = "Currency"; DropCompanyCurrency.DataValueField = "id"; DropCompanyCurrency.DataSource = DatabaseConnection.CreateDataset("select id,currency from currencyTable where currency<>'" + DatabaseConnection.FilterInjection(currencySymbol.Text) + "'"); DropCompanyCurrency.DataBind(); DropCompanyCurrency.Items.Insert(0, new ListItem(rm.GetString("Curtxt9"), "-1")); DropCompanyCurrency.SelectedIndex = 0; } private void NewCurrSubmit_Click(object sender, EventArgs e) { if (DropCompanyCurrency.SelectedValue != "-1") { DatabaseConnection.DoCommand("UPDATE currencyTable SET ChangeToEuro=0, ChangeFromEuro=0 WHERE ChangeToEuro=1 and ChangeFromEuro=1"); DatabaseConnection.DoCommand("UPDATE currencyTable SET ChangeToEuro=1, ChangeFromEuro=1 WHERE id=" + int.Parse(DropCompanyCurrency.SelectedValue)); Start(); } else { if (NewCurrName.Text.Length <= 0 || NewCurrSymbol.Text.Length <= 0) CurrInfo2.Text = rm.GetString("Curtxt11"); else { DatabaseConnection.DoCommand("UPDATE currencyTable SET ChangeToEuro=0, ChangeFromEuro=0 WHERE ChangeToEuro=1 and ChangeFromEuro=1"); DatabaseConnection.DoCommand(String.Format("INSERT INTO CurrencyTable(Currency, ChangeToEuro, ChangeFromEuro, currencySymbol) VALUES( '{0}', 1, 1, '{1}')", DatabaseConnection.FilterInjection(NewCurrName.Text), DatabaseConnection.FilterInjection(NewCurrSymbol.Text))); Start(); } } } } }