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.StatisticalInquiry
{
public partial class FrmInventoryReport : LYFZ.Software.UI.StatisticalInquiry.FrmInventoryReport
{
LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
public FrmInventoryReport()
{
this.Shown += FrmInventoryReport_Shown;
this.btnSelect.Click += btnSelect_Click;
this.tabControlEx1.SelectedIndexChanged += tabControlEx1_SelectedIndexChanged;
#region 导出按钮;
this.btnExport.Click += BtnExport_Click;
#endregion
}
private void BtnExport_Click(object sender, EventArgs e)
{
if (dgvData.Rows.Count <= 0 )
{
MessageBoxCustom.Show("没有数据可以导出!");
return;
}
string strExportName = "";
if (this.tabControlEx1.SelectedIndex == 0)
strExportName = "入库记录";
else if (this.tabControlEx1.SelectedIndex == 1)
strExportName = "出库记录";
else if (this.tabControlEx1.SelectedIndex == 2)
strExportName = "当前库存";
dgvData.ExportDataTable(strExportName);
}
///
/// 窗体加载事件
///
///
///
void FrmInventoryReport_Shown(object sender, EventArgs e)
{
this.dgvData.DataColumns("商品名称,数量,商品类别,厂商,进价,卖价,库存金额,入库人员,入库时间");
this.dtpTimeStart.Text = SDateTime.Now.ToString("yyyy-MM") + "-01";
this.dtpTimeEnd.Text = Convert.ToDateTime(this.dtpTimeStart.Text).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_Vendor(this.cmbtreevVendor);
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee(this.cmbtreevCreateName, IsFirstNodeNull: true);
this.PublicFunctionRows();
bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(VersionControl.VersionFunctionEnum.统计查询库存报表);
if (!b)
{
this.Close();
}
}
///
/// 查询
///
///
///
void btnSelect_Click(object sender, EventArgs e)
{
this.PublicFunctionRows();
}
///
/// 选择查看
///
///
///
void tabControlEx1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.tabControlEx1.SelectedTab.Name.Trim())
{
case "tabPage_IntStorage":
this.panelDateTime.Visible = true;
this.panelCreateName.Visible = true;
this.panelVendor.Visible = true;
this.labelEx4.Text = "入库人:";
this.panelSelect.Visible = true;
break;
case "tabPage_OutStorage":
this.panelDateTime.Visible = true;
this.panelCreateName.Visible = true;
this.panelVendor.Visible = false;
this.labelEx4.Text = "出库人:";
this.panelSelect.Visible = true;
break;
case "tabPage_CurrentStorage":
this.panelDateTime.Visible = false;
this.panelCreateName.Visible = false;
this.panelVendor.Visible = false;
this.panelSelect.Visible = false;
break;
}
this.PublicFunctionRows();
}
///
/// 绑定数据
///
void PublicFunctionRows()
{
string StrWhere = "1 = 1";
string StrTableName = "";
string StrColumnName = "";
switch (this.tabControlEx1.SelectedTab.Name.Trim())
{
case "tabPage_IntStorage":
if (string.IsNullOrEmpty(this.dtpTimeStart.DateValue.Trim()) || string.IsNullOrEmpty(this.dtpTimeEnd.DateValue.Trim()))
{ StrWhere += " And ID = -1"; }
else
{
StrWhere += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Pis_CreateDatetime", this.dtpTimeStart.DateValue.Trim(), this.dtpTimeEnd.DateValue.Trim());
if (!string.IsNullOrEmpty(cmbtreevCreateName.Text.Trim()))
{ StrWhere += " And Pis_CreateName = '" + cmbtreevCreateName.Tag.ToString().Trim() + "'"; }
if (!string.IsNullOrEmpty(this.cmbtreevVendor.Text.Trim()))
{ StrWhere += " And Pis_PurchaseVendor='" + this.cmbtreevVendor.Text.Trim() + "'"; }
}
StrTableName = "tb_ErpProductIntStorage Left Join tb_ErpProduct on Prod_Number = Pis_ProductNumber Left Join tb_ErpSystemCategory on Sc_ClassCode = Pis_ProductCategory Left Join tb_ErpUser on User_EmployeeID = Pis_CreateName";
StrColumnName = "Sc_ClassName AS 商品类别,Prod_Name AS 商品名称,Pis_PurchaseQuantity AS 入库数量,Pis_PurchasePrice AS 商品进价,Prod_SalesPrice AS 商品卖价,Pis_PurchasePrice * Pis_PurchaseQuantity AS 进价总额,User_Name AS 入库人员,dbo.fn_CheckDateTime(Pis_CreateDatetime) AS 入库时间,Pis_PurchaseVendor AS 供应商";
break;
case "tabPage_OutStorage":
if (string.IsNullOrEmpty(this.dtpTimeStart.DateValue.Trim()) || string.IsNullOrEmpty(this.dtpTimeEnd.DateValue.Trim()))
{ StrWhere += " And ID = -1"; }
else
{
StrWhere += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Pos_OutTime", this.dtpTimeStart.DateValue.Trim(), this.dtpTimeEnd.DateValue.Trim());
if (!string.IsNullOrEmpty(cmbtreevCreateName.Text.Trim()))
{ StrWhere += " And Pos_OutName = '" + cmbtreevCreateName.Tag.ToString().Trim() + "'"; }
}
StrTableName = "tb_ErpProductOutStorage Left Join tb_ErpProduct on Prod_Number = Pos_ProductNumber Left Join tb_ErpSystemCategory on Sc_ClassCode = Pos_ProductCategory Left Join tb_ErpUser on User_EmployeeID = Pos_OutName";
StrColumnName = "Sc_ClassName AS 商品类别,Prod_Name AS 商品名称,Pos_OutQuantity AS 出库数量,Prod_CostPrice AS 商品进价,Prod_SalesPrice AS 商品卖价,Prod_CostPrice * Pos_OutQuantity AS 进价总额,User_Name AS 出库人员,dbo.fn_CheckDateTime(Pos_OutTime) AS 出库时间";
break;
case "tabPage_CurrentStorage":
StrWhere += " And ((Prod_Availability = 1 And Prod_IsEnabled = 1) or (Prod_Availability = 0 And Prod_IsEnabled = 0 And Prod_Quantity > 0))";
StrTableName = "tb_ErpProduct Left Join tb_ErpSystemCategory on Sc_ClassCode = Prod_Class";
StrColumnName = "Sc_ClassName AS 商品类别,Prod_Name AS 商品名称,Prod_Quantity AS 库存数量,Prod_CostPrice AS 商品进价,Prod_SalesPrice AS 商品卖价,Prod_CostPrice * Prod_Quantity AS 进价总额,Prod_Vendor AS 供应商";
break;
}
DataTable dt = orbll.GetView_Custom(StrTableName, StrWhere: StrWhere, ShowColumnName: StrColumnName).Tables[0];
this.dgvData.DataSource(dt, strHideField: "");
this.dgvData.Columns["商品类别"].Width = 200;
this.dgvData.Columns["商品名称"].Width = 250;
if (this.dgvData.Columns["入库时间"] != null)
{ this.dgvData.Columns["入库时间"].Width = 110; }
if (this.dgvData.Columns["出库时间"] != null)
{ this.dgvData.Columns["出库时间"].Width = 110; }
if (this.dgvData.Columns["供应商"] != null)
{ this.dgvData.Columns["供应商"].Width = 200; }
this.dgvData.FillLastColumn(isAddNullColumns: true);
this.dgvData.ClearSelection();
decimal decSumAmount = 0;
DataTable tbl = new DataTable();
switch (this.tabControlEx1.SelectedTab.Name.Trim())
{
case "tabPage_IntStorage":
tbl = orbll.GetView_Custom("tb_ErpProductIntStorage", StrWhere: StrWhere, ShowColumnName: "sum(Pis_PurchasePrice * Pis_PurchaseQuantity) AS SumCostPrice").Tables[0];
if (tbl.Rows.Count > 0 && !string.IsNullOrEmpty(tbl.Rows[0]["SumCostPrice"].ToString().Trim()))
{ decSumAmount = Convert.ToDecimal(tbl.Rows[0]["SumCostPrice"]); }
this.txtStatistics.Text = " 入库进价总额:" + decSumAmount;
break;
case "tabPage_OutStorage":
tbl = orbll.GetView_Custom("tb_ErpProductOutStorage Left Join tb_ErpProduct on Prod_Number = Pos_ProductNumber", StrWhere: StrWhere, ShowColumnName: "sum(Pos_OutQuantity * Prod_CostPrice) AS SumCostPrice,sum(Pos_OutQuantity*Prod_SalesPrice) AS SumSalesPrice").Tables[0];
if (tbl.Rows.Count > 0 && !string.IsNullOrEmpty(tbl.Rows[0]["SumCostPrice"].ToString().Trim()))
{ decSumAmount = Convert.ToDecimal(tbl.Rows[0]["SumCostPrice"]); }
decimal decSalesPrice = 0;
if (tbl.Rows.Count > 0 && !string.IsNullOrEmpty(tbl.Rows[0]["SumSalesPrice"].ToString().Trim()))
{ decSalesPrice = Convert.ToDecimal(tbl.Rows[0]["SumSalesPrice"]); }
this.txtStatistics.Text = " 出库进价总额:" + decSumAmount + " 出库卖价总额:" + decSalesPrice + " 出库利润总额:" + (decSalesPrice - decSumAmount);
break;
case "tabPage_CurrentStorage":
tbl = orbll.GetView_Custom("tb_ErpProduct", StrWhere: StrWhere, ShowColumnName: "sum(Prod_CostPrice * Prod_Quantity) AS SumCostPrice").Tables[0];
if (tbl.Rows.Count > 0 && !string.IsNullOrEmpty(tbl.Rows[0]["SumCostPrice"].ToString().Trim()))
{ decSumAmount = Convert.ToDecimal(tbl.Rows[0]["SumCostPrice"]); }
this.txtStatistics.Text = " 库存进价总额:" + decSumAmount;
break;
}
}
}
}