using LYFZ.ComponentLibrary;
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
{
public partial class FrmPackagesSet : LYFZ.Software.UI.InitialSet.FrmPackagesSet
{
LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
LYFZ.BLL.BLL_ErpPackages pkbll = new BLL.BLL_ErpPackages();
LYFZ.BLL.BLL_ErpSystemCategory scbll = new BLL.BLL_ErpSystemCategory();
public FrmPackagesSet()
{
this.Load += FrmPackagesSet_Load;
this.Shown += FrmPackagesSet_Shown;
this.listViewData.MouseClick += listViewData_MouseClick;
this.btnClear.Click += btnClear_Click;
this.btnSave.Click += btnSave_Click;
this.btnDelete.Click += btnDelete_Click;
this.txtPak_UnitPrice.KeyPress += txtPak_UnitPrice_KeyPress;
this.CtvSelect.ComboBoxTree_NodeMouseClick += CtvSelect_ComboBoxTree_NodeMouseClick;
this.btnSet.Click += btnSet_Click;
this.btnCloseed.Click += btnCloseed_Click;
}
///
/// 套系大类类型
///
public int StrPackagesType;
///
/// 是否保存
///
public bool IsSaveed = false;
///
/// 窗体加载事件
///
///
///
void FrmPackagesSet_Load(object sender, EventArgs e)
{
string StrColumnName = "";
if (this.StrPackagesType == 1)
{
this.Text = "套系礼包名称设置";
StrColumnName = ",可选几";
}
else
{
this.labelEx1.Visible = false;
this.labelEx5.Visible = false;
this.numOptionalSeveral.Visible = false;
}
this.listViewData.View = View.Details;
this.listViewData.GridLines = true;
ImageList imgList = new ImageList();
imgList.ImageSize = new Size(1, 25);
this.listViewData.SmallImageList = imgList;
string[] StrColumns = (",套系名称,套系价格,状态,套系类别" + StrColumnName).Split(',');
for (int i = 0; i < StrColumns.Length; i++)
{
ColumnHeader ch = new ColumnHeader();
ch.Text = StrColumns[i].Trim();
if (i == 0)
{
ch.Width = 40;
}
else
{
ch.Width = (this.listViewData.Width - 23 - 40) / (StrColumns.Length - 1);
}
switch (StrColumns[i].Trim())
{
case "套系名称":
case "套系类别": ch.TextAlign = HorizontalAlignment.Left; break;
case "套系价格": ch.TextAlign = HorizontalAlignment.Right; break;
case "状态": ch.TextAlign = HorizontalAlignment.Center; break;
default: ch.TextAlign = HorizontalAlignment.Left; break;
}
this.listViewData.Columns.Add(ch);
}
}
///
/// 窗体加载事件
///
///
///
void FrmPackagesSet_Shown(object sender, EventArgs e)
{
this.PublicFunctionRows();
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_SystemCategory(Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), StrPackagesType).ToString().Trim(), this.CtvPak_PackagesClass, IsFirstNodeNull: false);
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_SystemCategory(Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), StrPackagesType).ToString().Trim(), this.CtvSelect, IsFirstNodeNull: true, IsFirstNodeName: "全部");
}
///
/// 获取表名
///
string GetTableName()
{
return "(select Pak_DividedShop,Pak_PackagesClass,Pak_PackagesID As 套系编号,Pak_Name AS 套系名称,Pak_UnitPrice AS 套系价格,case when Sc_ClassName is null then '' else Sc_ClassName end AS 套系类别," +
"case when Pak_IsDisable = 0 then '显示' else '隐藏' end AS 状态,Pak_OptionalSeveral AS 可选几 from tb_ErpPackages left join tb_ErpSystemCategory on tb_ErpPackages.Pak_PackagesClass=tb_ErpSystemCategory.Sc_ClassCode " +
"Where " + //Pak_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'
" Pak_PackagesMainClass = '" + Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), StrPackagesType).ToString().Trim() + "') as tb";
}
///
/// 绑定数据
///
void PublicFunctionRows(string StrWhere = "")
{
DataTable dt = orbll.GetView_Custom(GetTableName(), StrWhere: StrWhere, ShowColumnName: "套系编号,套系名称,套系价格,套系类别,可选几,状态").Tables[0];
this.listViewData.Items.Clear();
for (int i = 0; i < dt.Rows.Count; i++)
{
ListViewItem lvItem = new ListViewItem();
lvItem.Tag = dt.Rows[i]["套系编号"].ToString().Trim();
lvItem.Text = (i + 1).ToString();
ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "套系名称";
ListSubItem.Text = dt.Rows[i]["套系名称"].ToString().Trim();
lvItem.SubItems.Add(ListSubItem);
ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "套系价格";
ListSubItem.Text = dt.Rows[i]["套系价格"].ToString().Trim();
lvItem.SubItems.Add(ListSubItem);
ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "状态";
ListSubItem.Text = dt.Rows[i]["状态"].ToString().Trim();
lvItem.SubItems.Add(ListSubItem);
ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "套系类别";
ListSubItem.Text = dt.Rows[i]["套系类别"].ToString().Trim();
lvItem.SubItems.Add(ListSubItem);
if (this.StrPackagesType == 1)
{
ListSubItem = new ListViewItem.ListViewSubItem();
ListSubItem.Name = "可选几";
ListSubItem.Text = Convert.ToInt32(dt.Rows[i]["可选几"]) == -1 ? "全部" : dt.Rows[i]["可选几"].ToString().Trim();
lvItem.SubItems.Add(ListSubItem);
}
if ((this.listViewData.Items.Count % 2) > 0)
{
lvItem.BackColor = System.Drawing.Color.PapayaWhip;
}
else
{
lvItem.BackColor = System.Drawing.Color.PowderBlue;
}
this.listViewData.Items.Add(lvItem);
}
}
///
/// 控件显示单击事件
///
///
///
void listViewData_MouseClick(object sender, MouseEventArgs e)
{
try
{
//更新赋值
if (this.listViewData.Items.Count > 0 && this.listViewData.SelectedItems.Count > 0)
{
this.CtvPak_PackagesClass.SetTextAndTag_ValueNull();
string Pak_PackagesID = this.listViewData.SelectedItems[0].Tag.ToString().Trim();// this.dgv.CurrentRow.Cells["套系编号"].Value.ToString();
DataTable dt = pkbll.GetList("Pak_PackagesID='" + Pak_PackagesID + "'").Tables[0];
this.CtvPak_PackagesClass.TagFindText(dt.Rows[0]["Pak_PackagesClass"].ToString());
this.txtPak_Name.Enabled = !orbll.isSeriesNameUse(this.listViewData.SelectedItems[0].SubItems["套系名称"].Text, this.StrPackagesType);
this.txtPak_Name.Text = dt.Rows[0]["Pak_Name"].ToString();
this.txtPak_Name.Tag = dt.Rows[0]["Pak_PackagesID"].ToString();
this.txtPak_UnitPrice.Text = dt.Rows[0]["Pak_UnitPrice"].ToString();
//this.txtPak_IntoTheArchive.Value = Convert.ToDecimal(dt.Rows[0]["Pak_IntoTheArchive"]);
//this.txtPak_IntoTheBook.Value = Convert.ToDecimal(dt.Rows[0]["Pak_IntoTheBook"]);
this.cmbPak_IsDisable.Text = Convert.ToBoolean(dt.Rows[0]["Pak_IsDisable"].ToString()) == true ? "隐藏" : "显示";
if (this.StrPackagesType == 1)
{
this.numOptionalSeveral.Value = Convert.ToInt32(dt.Rows[0]["Pak_OptionalSeveral"]);
}
}
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
///
/// 清空填写
///
///
///
void btnClear_Click(object sender, EventArgs e)
{
ClearBind();
}
///
/// 保存
///
///
///
void btnSave_Click(object sender, EventArgs e)
{
#region 判断资料不能为空
if (string.IsNullOrEmpty(CtvPak_PackagesClass.Text))
{
MessageBoxCustom.Show("套系大类不能为空!"); return;
}
if (string.IsNullOrEmpty(txtPak_Name.Text))
{
MessageBoxCustom.Show("套系名称能为空!"); return;
}
if (string.IsNullOrEmpty(txtPak_UnitPrice.Text))
{
MessageBoxCustom.Show("套系价格不能为空!"); return;
}
if (string.IsNullOrEmpty(cmbPak_IsDisable.Text))
{
MessageBoxCustom.Show("状态不能为空!"); return;
}
#endregion
LYFZ.Model.Model_ErpPackages model = null;
DataTable dt = new DataTable();
try
{
if (this.txtPak_Name.Tag == null)
{
#region 增加
dt = pkbll.GetList("Pak_Name='" + txtPak_Name.Text.Trim() + "'").Tables[0];
if (dt.Rows.Count > 0)
{
MessageBoxCustom.Show("套系名称已经存在!"); return;
}
Random action = new Random();
model = new Model.Model_ErpPackages();
model.Pak_PackagesID = "TX" + SDateTime.Now.ToString("yyyyMMddHHmmss") + action.Next(100, 1000);
model.Pak_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID();
model.Pak_PackagesMainClass = Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), this.StrPackagesType).Trim().Trim();
model.Pak_PackagesClass = CtvPak_PackagesClass.Tag.ToString();
model.Pak_Name = txtPak_Name.Text;
model.Pak_UnitPrice = Convert.ToDecimal(txtPak_UnitPrice.Text);
if (this.StrPackagesType == 1)
{
model.Pak_OptionalSeveral = Convert.ToInt32(this.numOptionalSeveral.Value);
}
else
{
model.Pak_OptionalSeveral = 0;
}
if (cmbPak_IsDisable.Text == "显示")
{ model.Pak_IsDisable = false; }
else
{
model.Pak_IsDisable = true;
}
model.Pak_Remark = "";
//model.Pak_IntoTheArchive = Convert.ToInt32(txtPak_IntoTheArchive.Value);
//model.Pak_IntoTheBook = Convert.ToInt32(txtPak_IntoTheBook.Value);
model.Pak_CreateDatetime = SDateTime.Now;
model.Pak_PackagesClassName = CtvPak_PackagesClass.Text;
if (!pkbll.Add(model))
{
MessageBoxCustom.Show("保存失败!"); return;
}
#endregion
}
else
{
#region 更新
#region 判断套系名称是否存在
if (!string.IsNullOrEmpty(txtPak_Name.Text))
{
dt = pkbll.GetList("Pak_PackagesID='" + this.txtPak_Name.Tag + "'", "ID desc").Tables[0];
string Pak_Name = dt.Rows[0]["Pak_Name"].ToString().Trim();
if (Pak_Name != txtPak_Name.Text.Trim())
{
dt = pkbll.GetList("Pak_Name='" + txtPak_Name.Text.Trim() + "'").Tables[0];
if (dt.Rows.Count > 0)
{
MessageBoxCustom.Show("套系名称已经存在!"); return;
}
}
}
#endregion
model = pkbll.GetModel("Pak_PackagesID", this.txtPak_Name.Tag.ToString().Trim());
if (model.ID <= 0)
{
MessageBoxCustom.Show("此套系名称不存在或已经被删除!"); return;
}
model.Pak_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID();
model.Pak_PackagesClass = CtvPak_PackagesClass.Tag.ToString();
model.Pak_Name = txtPak_Name.Text;
model.Pak_UnitPrice = Convert.ToDecimal(txtPak_UnitPrice.Text);
if (this.StrPackagesType == 1)
{
model.Pak_OptionalSeveral = Convert.ToInt32(this.numOptionalSeveral.Value);
}
if (cmbPak_IsDisable.Text == "显示")
{
model.Pak_IsDisable = false;
}
else
{
model.Pak_IsDisable = true;
}
model.Pak_Remark = "";
//model.Pak_IntoTheArchive = Convert.ToInt32(txtPak_IntoTheArchive.Value);
//model.Pak_IntoTheBook = Convert.ToInt32(txtPak_IntoTheBook.Value);
model.Pak_UpdateDatetime = SDateTime.Now;
model.Pak_PackagesClassName = CtvPak_PackagesClass.Text;
if (!pkbll.Update(model))
{
MessageBoxCustom.Show("保存失败!"); return;
}
#endregion
}
IsSaveed = true;
//清空
ClearBind();
CtvPak_PackagesClass.Text = "";
MessageBoxCustom.Show("保存成功!");
this.GetForNodeCount(this.CtvSelect.GetNodeItem_TextToTag(this.CtvSelect.Text.Trim()));
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
///
/// 删除
///
///
///
void btnDelete_Click(object sender, EventArgs e)
{
try
{
if (this.listViewData.SelectedItems.Count == 0)
{
MessageBoxCustom.Show("请选中你要删除的数据!"); return;
}
DataTable dt = pkbll.GetList("Pak_PackagesID='" + this.listViewData.SelectedItems[0].Tag.ToString().Trim() + "'", "ID desc").Tables[0];
if (StrPackagesType == 0)
{
DataTable tbl = orbll.GetView_Custom("tb_ErpOrder", StrWhere: "Ord_SeriesName = '" + this.listViewData.SelectedItems[0].SubItems["套系名称"].Text.Trim() + "' or Ord_PhotographyCategory = '" + this.listViewData.SelectedItems[0].SubItems["套系名称"].Text.Trim() + "'", ShowColumnName: "ID").Tables[0];
if (tbl.Rows.Count > 0)
{
MessageBoxCustom.Show("套系已被选中下订单,不能删除套系"); return;
}
}
else if (StrPackagesType == 1)
{
DataTable tbl = orbll.GetView_Custom("tb_ErpOrder", StrWhere: "Ord_PackageName = '" + this.listViewData.SelectedItems[0].SubItems["套系名称"].Text.Trim() + "'", ShowColumnName: "ID").Tables[0];
if (tbl.Rows.Count > 0)
{
MessageBoxCustom.Show("礼包已被选中下订单,不能删除套系"); return;
}
}
int id = Convert.ToInt32(dt.Rows[0]["ID"]);
if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (pkbll.Delete(id) == true)
{
MessageBoxCustom.Show("删除成功!");
IsSaveed = true;
//清空
ClearBind();
}
else
{
MessageBoxCustom.Show("删除失败!");
}
}
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
///
/// 输入框设置
///
///
///
void txtPak_UnitPrice_KeyPress(object sender, KeyPressEventArgs e)
{
//获取或设置一个值,指示是否处理过System.Windows.Forms.Control.KeyPress事件
if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
{
e.Handled = true;
}
else if (Char.IsPunctuation(e.KeyChar))
{
if (e.KeyChar == '.')
{
if (((TextBox)sender).Text.LastIndexOf('.') != -1)
{
e.Handled = true;
}
}
else
{
e.Handled = true;
}
}
}
///
/// 查询套系大类
///
///
///
void CtvSelect_ComboBoxTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (CtvSelect.Text == "全部" || CtvSelect.Tag != null)
{
this.GetForNodeCount(e.Node);
}
}
void GetForNodeCount(TreeNode nodes)
{
StringBuilder str = new StringBuilder();
if (nodes != null)
{
//str.Append(" Pak_DividedShop = '" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'");
if (CtvSelect.Text != "全部")
{
string StrContent = "";
foreach (TreeNode node in nodes.Nodes)
{
if (node.Tag != null)
{
StrContent += "'" + node.Tag.ToString().Trim() + "',";
}
}
StrContent += "'" + nodes.Tag.ToString().Trim() + "'";
if (!string.IsNullOrEmpty(StrContent))
{
str.Append(" Pak_PackagesClass in (" + StrContent + ")");//And
}
}
}
this.PublicFunctionRows(str.ToString());
}
///
/// 清空
///
public void ClearBind()
{
this.txtPak_Name.Text = "";
this.txtPak_Name.Tag = null;
this.txtPak_UnitPrice.Text = "";
this.cmbPak_IsDisable.Text = "显示";
this.txtPak_Name.Enabled = true;
//this.txtPak_IntoTheArchive.Value = 0;
//this.txtPak_IntoTheBook.Value = 0;
}
///
/// 关闭
///
///
///
void btnCloseed_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 设置套系大类
///
///
///
void btnSet_Click(object sender, EventArgs e)
{
LYFZ.Software.MainBusiness.InitialSet.FrmSystemSet frm = new FrmSystemSet();
frm.TypeName = Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), StrPackagesType).ToString().Trim();
frm.Version = "Version";
if (frm.ShowDialog() == DialogResult.OK)
{
this.FrmPackagesSet_Shown(this, null);
}
}
}
}