using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LYFZ.Software.MainBusiness.InitialSet.SetSmallForm
{
public partial class SelectVendorSetSmallForm : LYFZ.Software.UI.InitialSet.SetSmallForm.SelectVendorSetSmallForm
{
LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
public SelectVendorSetSmallForm()
{
this.Load += SelectSupplierSetSmallForm_Load;
this.Shown += SelectSupplierSetSmallForm_Shown;
this.btnAdded.Click += btnAdded_Click;
this.btnRemove.Click += btnRemove_Click;
this.listViewData_Source.MouseDoubleClick += listViewData_Source_MouseDoubleClick;
this.listViewData_Selected.MouseDoubleClick += listViewData_Selected_MouseDoubleClick;
this.btnOK.Click += btnOK_Click;
}
///
/// 是否保存
///
public bool IsSaveed = false;
///
/// 选择的供应商
///
public string StrSelectedValue = "";
///
/// 提供的供应商(即提供源)
///
public string StrProvideValue = "";
///
/// 窗体加载事件
///
///
///
void SelectSupplierSetSmallForm_Load(object sender, EventArgs e)
{
this.listViewData_Source.View = View.Details;
this.listViewData_Source.GridLines = true;
ImageList imgList = new ImageList();
imgList.ImageSize = new Size(1, 25);
this.listViewData_Source.SmallImageList = imgList;
string[] StrColumns = "供应商,联系电话,地址".Split(',');
int SurplusCount = 90 + 85 + 23;
for (int i = 0; i < StrColumns.Length; i++)
{
ColumnHeader ch = new ColumnHeader();
ch.Text = StrColumns[i].Trim();
ch.TextAlign = HorizontalAlignment.Left;
if (i == 0)
{ ch.Width = this.listViewData_Source.Width - SurplusCount; }
else if (i == StrColumns.Length - 1)
{ ch.Width = 90; }
else
{ ch.Width = 85; }
ch.TextAlign = HorizontalAlignment.Center;
this.listViewData_Source.Columns.Add(ch);
}
this.listViewData_Selected.View = View.Details;
this.listViewData_Selected.GridLines = true;
this.listViewData_Selected.SmallImageList = imgList;
for (int i = 0; i < StrColumns.Length; i++)
{
ColumnHeader ch = new ColumnHeader();
ch.Text = StrColumns[i].Trim();
ch.TextAlign = HorizontalAlignment.Left;
if (i == 0)
{ ch.Width = this.listViewData_Selected.Width - SurplusCount; }
else if (i == StrColumns.Length - 1)
{ ch.Width = 90; }
else
{ ch.Width = 85; }
ch.TextAlign = HorizontalAlignment.Center;
this.listViewData_Selected.Columns.Add(ch);
}
}
///
/// 窗体加载事件
///
///
///
void SelectSupplierSetSmallForm_Shown(object sender, EventArgs e)
{
List ListValue = StrProvideValue.Trim().Split(',').ToList();
DataTable dt = orbll.GetView_Custom("tb_ErpVendor", StrWhere: "", ShowColumnName: "Vd_Name,Vd_Telephone,Vd_Address").Tables[0];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (ListValue.Count > 0)
{
for (int j = 0; j < ListValue.Count; j++)
{
if (!string.IsNullOrEmpty(ListValue[j].Trim()))
{
if (dt.Rows[i]["Vd_Name"].ToString().Trim() == ListValue[j].Trim())
{
ListViewItem lvItem2 = new ListViewItem();
lvItem2.Tag = dt.Rows[i]["Vd_Name"].ToString().Trim();
lvItem2.Text = dt.Rows[i]["Vd_Name"].ToString().Trim();
ListViewItem.ListViewSubItem ListSubItem2 = new ListViewItem.ListViewSubItem();
ListSubItem2.Name = "联系电话";
ListSubItem2.Text = dt.Rows[i]["Vd_Name"].ToString().Trim();
lvItem2.SubItems.Add(ListSubItem2);
ListSubItem2 = new ListViewItem.ListViewSubItem();
ListSubItem2.Name = "地址";
ListSubItem2.Text = dt.Rows[i]["Vd_Name"].ToString().Trim();
lvItem2.SubItems.Add(ListSubItem2);
this.listViewData_Selected.Items.Add(lvItem2);
ListValue.Remove(ListValue[j]);
}
}
}
}
ListViewItem lvItem = new ListViewItem();
lvItem.Tag = dt.Rows[i]["Vd_Name"].ToString().Trim();
lvItem.Text = dt.Rows[i]["Vd_Name"].ToString().Trim();
ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "联系电话";
ListSubItem.Text = dt.Rows[i]["Vd_Telephone"].ToString().Trim();
lvItem.SubItems.Add(ListSubItem);
ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "地址";
ListSubItem.Text = dt.Rows[i]["Vd_Address"].ToString().Trim();
lvItem.SubItems.Add(ListSubItem);
this.listViewData_Source.Items.Add(lvItem);
}
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData_Source);
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData_Selected);
}
}
///
/// 添加
///
///
///
void btnAdded_Click(object sender, EventArgs e)
{
if (this.listViewData_Source.Items.Count > 0 && this.listViewData_Source.SelectedItems.Count > 0)
{
for (int j = 0; j < this.listViewData_Source.SelectedItems.Count; j++)
{
ListViewItem SelectItem = this.listViewData_Source.SelectedItems[j];
for (int i = 0; i < this.listViewData_Selected.Items.Count; i++)
{
if (this.listViewData_Selected.Items[i].Text.Trim() == SelectItem.Text.Trim())
{ return; }
}
ListViewItem lvItem = new ListViewItem();
lvItem.Tag = SelectItem.Text.Trim();
lvItem.Text = SelectItem.Tag.ToString().Trim();
ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "联系电话";
ListSubItem.Text = SelectItem.SubItems[0].Text.Trim();
lvItem.SubItems.Add(ListSubItem);
ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "地址";
ListSubItem.Text = SelectItem.SubItems[1].Text.Trim();
lvItem.SubItems.Add(ListSubItem);
if ((this.listViewData_Selected.Items.Count % 2) > 0)
{ lvItem.BackColor = System.Drawing.Color.PapayaWhip; }
else
{ lvItem.BackColor = System.Drawing.Color.PowderBlue; }
this.listViewData_Selected.Items.Add(lvItem);
}
}
}
///
/// 移除
///
///
///
void btnRemove_Click(object sender, EventArgs e)
{
if (this.listViewData_Selected.Items.Count > 0 && this.listViewData_Selected.SelectedItems.Count > 0)
{
List delList = new List();
for (int i = 0; i < this.listViewData_Selected.SelectedItems.Count; i++)
{ delList.Add(this.listViewData_Selected.SelectedItems[i]); }
for (int i = 0; i < delList.Count; i++)
{ this.listViewData_Selected.Items.Remove(delList[i]); }
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData_Selected);
}
}
///
/// 源供应商双击添加
///
///
///
void listViewData_Source_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.listViewData_Source.Items.Count > 0 && this.listViewData_Source.SelectedItems.Count > 0)
{
ListViewItem SelectItem = this.listViewData_Source.SelectedItems[0];
for (int i = 0; i < this.listViewData_Selected.Items.Count; i++)
{
if (this.listViewData_Selected.Items[i].Text.Trim() == SelectItem.Text.Trim())
{ return; }
}
ListViewItem lvItem = new ListViewItem();
lvItem.Tag = SelectItem.Text.Trim();
lvItem.Text = SelectItem.Tag.ToString().Trim();
ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "联系电话";
ListSubItem.Text = SelectItem.SubItems[0].Text.Trim();
lvItem.SubItems.Add(ListSubItem);
ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "地址";
ListSubItem.Text = SelectItem.SubItems[1].Text.Trim();
lvItem.SubItems.Add(ListSubItem);
if ((this.listViewData_Selected.Items.Count % 2) > 0)
{ lvItem.BackColor = System.Drawing.Color.PapayaWhip; }
else
{ lvItem.BackColor = System.Drawing.Color.PowderBlue; }
this.listViewData_Selected.Items.Add(lvItem);
}
}
///
/// 已选择供应商双击移除
///
///
///
void listViewData_Selected_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.listViewData_Selected.Items.Count > 0 && this.listViewData_Selected.SelectedItems.Count > 0)
{
this.listViewData_Selected.Items.Remove(this.listViewData_Selected.SelectedItems[0]);
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData_Selected);
}
}
///
/// 确定
///
///
///
void btnOK_Click(object sender, EventArgs e)
{
string strItemText = "";
for (int i = 0; i < this.listViewData_Selected.Items.Count; i++)
{ strItemText += this.listViewData_Selected.Items[i].Text.Trim() + ","; }
this.StrSelectedValue = strItemText.TrimEnd(',');
this.IsSaveed = true;
this.Close();
}
}
}