www.pudn.com > Tustena_CRM_OS_3.0.2_Stable.zip > offices.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.Resources; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Digita.Tustena.Database; namespace Digita.Tustena.Admin { public class offices : UserControl { public G G = new G(); private UserConfig UC = new UserConfig(); public static ResourceManager rm = (ResourceManager) HttpContext.Current.Application["RM"]; #region Codice generato da Progettazione Web Form protected override void OnInit(EventArgs e) { InitializeComponent(); base.OnInit(e); } private void InitializeComponent() { this.Load += new EventHandler(this.Page_Load); } #endregion protected DataGrid Categorie_Grid; protected Literal HelpLabel; public void Page_Load(object sender, EventArgs e) { UC = (UserConfig) HttpContext.Current.Session["userconfig"]; if (!Page.IsPostBack) { Categorie_Grid.Columns[0].HeaderText = rm.GetString("Aoftxt1"); HelpLabel.Text = G.FillHelp("HelpOffices", UC); FillGrid(); } } private void FillGrid() { Categorie_Grid.DataSource = DatabaseConnection.CreateDataset("select * from Offices order by Office"); Categorie_Grid.DataBind(); } public void Categorie_Grid_DataBound(object source, DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Footer) ((LinkButton) e.Item.FindControl("AddOffice")).Text = rm.GetString("Aoftxt2"); if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { ((LinkButton) e.Item.FindControl("LnkDel")).Text = rm.GetString("Delete"); try { LinkButton lb = (LinkButton) (e.Item.Cells[1].Controls[0]); lb.Text = rm.GetString("Rename"); } catch (Exception) { } } if (e.Item.ItemType == ListItemType.EditItem) { ((LinkButton) e.Item.FindControl("LnkDel")).Text = rm.GetString("Delete"); try { LinkButton lb = (LinkButton) (e.Item.Cells[1].Controls[0]); lb.Text = rm.GetString("Save"); LinkButton lb1 = (LinkButton) (e.Item.Cells[1].Controls[2]); lb1.Text = rm.GetString("Cancel"); } catch (Exception) { } } } public void CategoryGridItemCommand(object source, DataGridCommandEventArgs e) { string sqlString; Trace.Warn(e.CommandName); switch (e.CommandName) { case "Edit": Categorie_Grid.EditItemIndex = e.Item.ItemIndex; FillGrid(); break; case "Cancel": Categorie_Grid.EditItemIndex = -1; FillGrid(); break; case "Update": int CatId=int.Parse(((Literal) e.Item.FindControl("IDCat")).Text); sqlString = "select * from Offices where Office ='" + CatId + "';"; Trace.Warn("", sqlString); using (DigiDapter dg = new DigiDapter()) { dg.UpdateOnly(); dg.Add("Office", ((TextBox) e.Item.FindControl("LnkNameTextBox")).Text); dg.Add("LastModifiedDate", UC.LTZ.ToUniversalTime(DateTime.Now)); dg.Add("LastModifiedByID", UC.UserId); dg.Execute("Offices", "ID=" + int.Parse(((Literal) e.Item.FindControl("IDCat")).Text)); } Categorie_Grid.EditItemIndex = -1; FillGrid(); break; case "Delete": sqlString = "delete from Offices where ID ='" + int.Parse(((Literal) e.Item.FindControl("IDCat")).Text) + "';"; DatabaseConnection.DoCommand(sqlString); Categorie_Grid.EditItemIndex = -1; FillGrid(); break; case "Insert": string newOffice = ((TextBox) e.Item.FindControl("TxtNewCatName")).Text; if (newOffice.Length == 0) return; { using (DigiDapter dg = new DigiDapter()) { dg.Add("Office", newOffice); dg.Add("CreatedByID", UC.UserId); dg.Execute("Offices"); } } Categorie_Grid.EditItemIndex = -1; FillGrid(); break; } } } }