private List<ComboBoxItem> CustList = null, StorList = null, AreaList = null;获取
ComboBoxItem custItem = null;
cbxStorage.SelectedIndexChanged -= new EventHandler(cbxStorage_SelectedIndexChanged);
if (Session.ExistKey("Storages"))
{
this.StorList = Session.GetValue("Storages") as List<ComboBoxItem>;
}
else
{
ComboBoxItem[] _storages = dataService.Storage_GetStorageDataList(login.loginKey, Convert.ToInt32(login.userInfo.CompanyID));
if (_storages != null)
{
this.StorList = _storages.ToList<ComboBoxItem>();
}
if (this.StorList != null)
{
Session.SetValue("Storages", this.StorList);
}
}
Utility.InitComboxBox(cbxStorage, StorList);
if (Session.ExistKey("Customers"))
{
this.CustList = Session.GetValue("Customers") as List<ComboBoxItem>;
}
else
{
ComboBoxItem[] _customers = dataService.Customer_GetCustomerDataList(login.loginKey);
if (_customers != null)
{
this.CustList = _customers.ToList<ComboBoxItem>();
}
if (this.CustList != null)
{
Session.SetValue("Customers", this.CustList);
}
}
Utility.InitComboxBox(cbxCustomer, CustList);
private void cbxStorage_SelectedIndexChanged(object sender, EventArgs e)
{
if (cbxStorage.SelectedValue != null ||!cbxStorage.SelectedText.Equals("")) return;
if (Session.ExistKey("Areas" + cbxStorage.SelectedValue))
{
this.AreaList = Session.GetValue("Areas" + cbxStorage.SelectedValue) as List<ComboBoxItem>;
}
else
{
dataService = new IMLZ_Storage.DataService.DataService();
this.AreaList = dataService.Area_GetAreasDataListByStorage(login.loginKey, Convert.ToInt32(login.userInfo.CompanyID), Convert.ToInt32(cbxStorage.SelectedValue)).ToList<ComboBoxItem>();
if (this.AreaList != null)
{
Session.SetValue("Areas" + cbxStorage.SelectedValue, this.AreaList);
}
}
Utility.InitComboxBox(cbxArea, this.AreaList);
}
//cbxCustomer.DataSource = custMan.seleCustomer(login.loginKey);
//cbxCustomer.ValueMember = "id";
//cbxCustomer.DisplayMember = "fullName";
//cbxCustomer.SelectedIndex = -1;
//cbxStorage.DataSource = dataSer.StorageList_GetStorageListDataList(login.loginKey, Convert.ToInt32(login.userInfo.CompanyID));
//cbxStorage.ValueMember = "StorageID";
//cbxStorage.DisplayMember = "StorageName";
//cbxStorage.SelectedIndex = -1;
/*
* 作者:吕诗超
* 日期:2012年5月
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IMLZ_Storage.DataService;
namespace IMLZ_Storage.App
{
public class Utility
{
private static string[] actionList = null;
private static string[] ActionList
{
get
{
if (actionList == null)
{
actionList = Session.GetValue("ActionList") as string[];
}
return actionList;
}
}
public static bool Verify(string actionName)
{
return !ActionList.Contains<string>(actionName);
}
public static ComboBoxItem GetComboBoxSelectedItemByCode(ComboBox comboBox, List<ComboBoxItem> items)
{
if (comboBox == null || items == null) return null;
for (int i = 0, count = comboBox.Items.Count; i < count; i++)
{
if (comboBox.Text.Trim().ToUpper().Equals(items[i].Code.Trim().ToUpper()) || comboBox.Text.Trim().ToUpper().Equals(items[i].FormatText.Trim().ToUpper()) || comboBox.Text.Trim().ToUpper().Equals(items[i].Text.Trim().ToUpper()) || items[i].Text.Trim().ToUpper().IndexOf(comboBox.Text.Trim().ToUpper()) >= 0)
{
comboBox.Text = items[i].FormatText;
return items[i];
}
}
return null;
}
public static ComboBoxItem GetComboBoxSelectedItemByID(ComboBox comboBox, List<ComboBoxItem> items, int id)
{
if (comboBox == null || items == null) return null;
for (int i = 0, count = comboBox.Items.Count; i < count; i++)
{
if (items[i].ID == id)
{
comboBox.Text = items[i].FormatText;
return items[i];
}
}
return null;
}
public static ComboBoxItem GetComboBoxSelectedItemByText(ComboBox comboBox, List<ComboBoxItem> items, string text)
{
if (comboBox == null || items == null) return null;
for (int i = 0, count = comboBox.Items.Count; i < count; i++)
{
if (items[i].Text == text)
{
comboBox.Text = items[i].FormatText;
return items[i];
}
}
return null;
}
public static ComboBoxItem GetComboBoxSelectedItemByIndex(ComboBox comboBox, List<ComboBoxItem> items)
{
if (comboBox == null || items == null) return null;
comboBox.Text = items[comboBox.SelectedIndex].FormatText;
return items[comboBox.SelectedIndex];
}
public static void InitComboxBox(ComboBox comboBox, List<ComboBoxItem> items)
{
if (comboBox == null || items == null) return;
comboBox.Items.Clear();
for (int i = 0, count = items.Count; i < count; i++)
{
comboBox.Items.Add(items[i].FormatText);
}
comboBox.Text = string.Empty;
}
public static ComboBoxItem GetComboBoxItemByID(List<ComboBoxItem> items, int id)
{
if (items == null) return null;
for (int i = 0, count = items.Count; i < count; i++)
{
if (items[i].ID == id)
{
return items[i];
}
}
return null;
}
public static object SumTableColumnValues(System.Data.DataTable table, string fieldName)
{
if (table == null || !table.Columns.Contains(fieldName)) return 0M;
decimal sum = 0M;
for (int i = 0, count = table.Rows.Count; i < count; i++)
{
sum += decimal.Parse(table.Rows[i][fieldName].ToString());
}
return sum;
}
public static string DecimalToCNNumber(decimal value)
{
string result = string.Empty;
string[] number = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "点" };
string s = value.ToString("0万0仟0佰0拾0万0仟0佰0拾0万0仟0佰0拾0亿0仟0佰0拾0万0仟0佰0拾0.000");
string s2 = System.Text.RegularExpressions.Regex.Replace(s, @"^(0[亿万仟佰拾]){0,}", "");
s2 = System.Text.RegularExpressions.Regex.Replace(s, @"(0[亿万仟佰拾])+", "0");
s2 = System.Text.RegularExpressions.Regex.Replace(s2, @"^0", "");
result = s2.Replace("0", number[0])
.Replace("1", number[1])
.Replace("2", number[2])
.Replace("3", number[3])
.Replace("4", number[4])
.Replace("5", number[5])
.Replace("6", number[6])
.Replace("7", number[7])
.Replace("8", number[8])
.Replace("9", number[9])
.Replace(".", number[10]);
return result;
}
public static void ResetTableRowNo(System.Data.DataTable table)
{
if (table == null) return;
int i = 0, count = table.Rows.Count;
while (i < count)
{
table.Rows[i++]["RowNo"] = i;
}
}
public static void ResetTableRowNo(System.Data.DataTable table, string rowNoFieldNamne)
{
if (table == null) return;
int i = 0, count = table.Rows.Count;
while (i < count)
{
table.Rows[i++][rowNoFieldNamne] = i;
}
}
public static void ResetDataGridViewRowNo(DataGridView table)
{
if (table == null) return;
int i = 0, count = table.Rows.Count;
while (i < count)
{
table.Rows[i++].Cells["RowNo"].Value = i;
}
}
public static void ResetDataGridViewRowNo(DataGridView table, string rowNoFieldNamne)
{
if (table == null) return;
int i = 0, count = table.Rows.Count;
while (i < count)
{
table.Rows[i++].Cells[rowNoFieldNamne].Value = i;
}
}
public static void SetTableColumnValue(System.Data.DataTable table, string columnName, object columnValue)
{
if (table == null) return;
for (int i = 0; i < table.Rows.Count; i++)
{
table.Rows[i][columnName] = columnValue;
}
}
public static void SignDataGridViewRows(DataGridView grid, string columnName, string conumnValue, System.Drawing.Color backColor)
{
if (grid == null || !grid.Columns.Contains(columnName)) return;
int i = -1;
int count = grid.Rows.Count;
while (++i < count)
{
if (grid.Rows[i].Cells[columnName].Value.ToString().Equals(conumnValue)) grid.Rows[i].DefaultCellStyle.BackColor = backColor;
}
}
public static void SignDataGridViewRows(DataGridView grid, string columnName, Dictionary<string, System.Drawing.Color> columnValueColors)
{
if (grid == null || !grid.Columns.Contains(columnName) || columnValueColors == null) return;
int i = -1;
int count = grid.Rows.Count;
while (++i < count)
{
foreach (var column in columnValueColors)
{
if (grid.Rows[i].Cells[columnName].Value.ToString().Equals(column.Key)) grid.Rows[i].DefaultCellStyle.BackColor = column.Value;
}
}
}
public static void Clipboard_KeyEvent(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.C)
{
DataGridView grid = (DataGridView)sender;
if (grid != null)
{
string value = grid.CurrentCell.Value != null ? grid.CurrentCell.Value.ToString() : "";
Clipboard.SetText(value);
}
}
}
}
}