1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
using System;
using System.Runtime.InteropServices;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
namespace ClassificationControl
{
// TODO: Replace, as needed, "TextField" with some other class derived from Microsoft.SharePoint.WebControls.BaseFieldControl.
[CLSCompliant(false)]
[Guid("e3bd01c1-e222-4324-8b85-b1a27291cbb0")]
public class BSClassControlFieldControl : TextField
{
private DropDownList lstBox;
private HtmlTable table;
protected override void CreateChildControls()
{
base.CreateChildControls();
if (ControlMode == SPControlMode.Display)
return;
// get data from database
Dictionary<int, string> lstBus = null;
try {
using (dataInfo df = new dataInfo()) {
lstBus = df.getBusSectorClass((SPContext.Current.RegionalSettings.InstalledLanguages[0].LCID == 1036));
}
}
catch { }
this.table = new HtmlTable();
//this.table.Attributes["border"] = "1";
HtmlTableRow row = new HtmlTableRow();
table.Rows.Add(row);
HtmlTableCell cell = null;
if (this.ControlMode == SPControlMode.Edit || this.ControlMode == SPControlMode.New) {
cell = new HtmlTableCell();
cell.Attributes["class"] = "ms-formdescription";
cell.InnerText = "Choose a business:";
row.Cells.Add(cell);
row = new HtmlTableRow();
cell = new HtmlTableCell();
// create the treeview BSC
this.lstBox = new DropDownList();
lstBox.Items.Add(new ListItem(this.ID, this.ID));
lstBox.Items.Add(new ListItem("11", "11"));
// si il a réussi de récupérer les valeurs :
if (lstBus != null) {
foreach (int iKey in lstBus.Keys) {
//lstBox.Items.Add(new ListItem(lstBus[iKey], iKey.ToString()));
lstBox.Items.Add(new ListItem(lstBus[iKey], lstBus[iKey]));
}
// Get the current value of the field :
string itemfieldvalue = (string)this.ItemFieldValue;
if (!string.IsNullOrEmpty(itemfieldvalue)) {
// search the value in the listbox
lstBox.SelectedIndex = lstBox.Items.IndexOf(lstBox.Items.FindByValue(itemfieldvalue));
}
}
else {
lstBox.Items.Add("No Value");
}
// ajout du treeview
cell.Controls.Add(this.lstBox);
row.Cells.Add(cell);
table.Rows.Add(row);
}
lstBus = null;
base.Controls.Add(this.table);
}
public override void UpdateFieldValueInItem()
{
this.EnsureChildControls();
try {
this.Value = this.lstBox.Items[this.lstBox.SelectedIndex].Text;
this.ItemFieldValue = this.Value;
}
catch { ; }
}
protected override void Render(HtmlTextWriter output)
{
this.table.RenderControl(output);
}
}
public class dataInfo : IDisposable
{
#region properties
private string _connectionString;
public string ConnectionString
{
get { return _connectionString; }
set { _connectionString = value; }
}
#endregion
public dataInfo()
{
IDictionary dico = Environment.GetEnvironmentVariables();
foreach (DictionaryEntry de in dico)
if (de.Key.ToString() == "CnString")
{
ConnectionString = de.Value.ToString();
break;
}
dico = null;
}
public Dictionary<int, string> getBusSectorClass(bool cultureFR)
{
Dictionary<int, string> lstResult = new Dictionary<int, string>();
using (System.Data.OleDb.OleDbConnection dbCN = new System.Data.OleDb.OleDbConnection(ConnectionString))
{
System.Data.OleDb.OleDbCommand dbCM = new System.Data.OleDb.OleDbCommand();
dbCM.Connection = dbCN;
dbCM.CommandType = System.Data.CommandType.StoredProcedure;
dbCM.CommandText = "sp_GetBusiness";
dbCM.Parameters.Add("@FR_culture", System.Data.OleDb.OleDbType.Boolean);
dbCM.Parameters["@FR_culture"].Value = cultureFR;
dbCN.Open();
System.Data.OleDb.OleDbDataReader reader = dbCM.ExecuteReader();
if (reader.HasRows) {
while (reader.Read()) {
lstResult.Add(Int32.Parse(reader[0].ToString()), reader[1].ToString());
}
}
dbCN.Close();
}
return lstResult;
}
#region IDisposable Members
void IDisposable.Dispose()
{
//throw new Exception("The method or operation is not implemented.");
}
#endregion
}
} |
Partager