2021-04-30 10:28:37 +08:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Web ;
using System.Web.UI ;
using System.Web.UI.WebControls ;
using System.Data ;
using System.Data.SqlClient ;
using BLL ;
using Newtonsoft.Json.Linq ;
namespace FineUIPro.Web.JDGL.Check
{
public partial class QuantityCompletion : PageBase
{
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
2021-06-21 14:10:40 +08:00
GetButtonPower ( ) ;
2024-05-05 17:12:18 +08:00
btnNew . OnClientClick = Window1 . GetShowReference ( "QuantityCompletionEdit.aspx" ) + "return false;" ;
2024-05-10 15:46:52 +08:00
this . txtMonths . Text = string . Format ( "{0:yyyy-MM}" , DateTime . Now ) ;
2021-04-30 10:28:37 +08:00
BindGrid ( ) ;
}
}
#region 获 取 按 钮 权 限
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower ( )
{
if ( Request . Params [ "value" ] = = BLL . Const . _Null )
{
return ;
}
var buttonList = BLL . CommonService . GetAllButtonList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , BLL . Const . QuantityCompletionMenuId ) ;
if ( buttonList . Count ( ) > 0 )
{
if ( buttonList . Contains ( BLL . Const . BtnSave ) )
{
2024-05-05 17:12:18 +08:00
this . btnNew . Hidden = false ;
2024-05-06 15:57:32 +08:00
this . btnModify . Hidden = false ;
2021-06-21 14:10:40 +08:00
this . btnMenuDel . Hidden = false ;
2021-04-30 10:28:37 +08:00
}
}
}
#endregion
2024-05-06 15:57:32 +08:00
protected void btnModify_Click ( object sender , EventArgs e )
2024-05-05 17:12:18 +08:00
{
2024-05-06 15:57:32 +08:00
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "QuantityCompletionEdit.aspx?Months={0}" , this . txtMonths . Text , "编辑 - " ) ) ) ;
2021-08-13 11:15:59 +08:00
}
2021-04-30 10:28:37 +08:00
/// <summary>
/// 生成对应月份记录
/// </summary>
private void GetQuantityCompletion ( )
{
if ( ! string . IsNullOrEmpty ( this . txtMonths . Text . Trim ( ) ) )
{
DateTime months = Convert . ToDateTime ( this . txtMonths . Text . Trim ( ) + "-01" ) ;
Model . SGGLDB db = Funs . DB ;
var quantityLists = from x in db . JDGL_QuantityList where x . ProjectId = = this . CurrUser . LoginProjectId select x ;
var quantityCompletions = from x in db . JDGL_QuantityCompletion where x . ProjectId = = this . CurrUser . LoginProjectId & & x . Months = = months select x ;
foreach ( var item in quantityLists )
{
var quantityCompletion = quantityCompletions . FirstOrDefault ( x = > x . QuantityListId = = item . QuantityListId ) ;
if ( quantityCompletion = = null )
{
Model . JDGL_QuantityCompletion newQuantityCompletion = new Model . JDGL_QuantityCompletion ( ) ;
newQuantityCompletion . QuantityCompletionId = SQLHelper . GetNewID ( ) ;
newQuantityCompletion . ProjectId = this . CurrUser . LoginProjectId ;
newQuantityCompletion . QuantityListId = item . QuantityListId ;
newQuantityCompletion . Months = months ;
db . JDGL_QuantityCompletion . InsertOnSubmit ( newQuantityCompletion ) ;
db . SubmitChanges ( ) ;
}
}
}
}
/// <summary>
/// 加载Grid
/// </summary>
private void BindGrid ( )
{
2021-05-20 17:16:01 +08:00
//GetQuantityCompletion();
2024-05-06 15:57:32 +08:00
string strSql = @ "select qc.QuantityCompletionId,(select PlanNum from JDGL_QuantityCompletion where QuantityListId=ql.QuantityListId and Months=@month) as PlanNum,
( select RealNum from JDGL_QuantityCompletion where QuantityListId = ql . QuantityListId and Months = @month ) as RealNum ,
( select NextNum from JDGL_QuantityCompletion where QuantityListId = ql . QuantityListId and Months = @month ) as NextNum , ql . DesignNum , ql . Name , ql . Unit , ql . SortIndex ,
CONVERT ( FLOAT , ( select sum ( ISNULL ( PlanNum , 0 ) ) from JDGL_QuantityCompletion where ProjectId = ql . ProjectId and QuantityListId = qc . QuantityListId and Months < = @month ) ) as TotalPlanNum ,
CONVERT ( FLOAT , ( select sum ( ISNULL ( RealNum , 0 ) ) from JDGL_QuantityCompletion where ProjectId = ql . ProjectId and QuantityListId = qc . QuantityListId and Months < = @month ) ) as TotalRealNum ,
2024-05-05 17:12:18 +08:00
CONVERT ( NVARCHAR ( 10 ) , ( ( CAST ( CASE ISNULL ( qc . PlanNum , 0 ) WHEN 0 THEN 0
ELSE 100 * ISNULL ( qc . RealNum , 0 ) / ( 1.0 * qc . PlanNum ) END AS DECIMAL ( 9 , 2 ) ) ) ) ) + '%'
AS Rate ,
2024-05-06 15:57:32 +08:00
CONVERT ( NVARCHAR ( 10 ) , ( ( CAST ( CASE ( select sum ( ISNULL ( PlanNum , 0 ) ) from JDGL_QuantityCompletion where ProjectId = ql . ProjectId and QuantityListId = qc . QuantityListId and Months < = @month ) WHEN 0 THEN 0
2024-05-05 17:12:18 +08:00
2024-05-06 15:57:32 +08:00
ELSE 100 * ( select sum ( ISNULL ( RealNum , 0 ) ) from JDGL_QuantityCompletion where ProjectId = ql . ProjectId and QuantityListId = qc . QuantityListId and Months < = @month ) / ( 1.0 * ( select sum ( ISNULL ( PlanNum , 0 ) ) from JDGL_QuantityCompletion where ProjectId = ql . ProjectId and QuantityListId = qc . QuantityListId and Months < = @month ) ) END AS DECIMAL ( 9 , 2 ) ) ) ) ) + '%'
2024-05-05 17:12:18 +08:00
AS TotalRate ,
CONVERT ( NVARCHAR ( 10 ) , ( ( CAST ( CASE ISNULL ( ql . DesignNum , 0 ) WHEN 0 THEN 0
2024-05-06 15:57:32 +08:00
ELSE 100 * ( select sum ( ISNULL ( RealNum , 0 ) ) from JDGL_QuantityCompletion where ProjectId = ql . ProjectId and QuantityListId = qc . QuantityListId and Months < = @month ) / ( 1.0 * ql . DesignNum ) END AS DECIMAL ( 9 , 2 ) ) ) ) ) + '%'
2024-05-05 17:12:18 +08:00
AS SumRate ,
CONVERT ( FLOAT , ( select sum ( ISNULL ( PlanNum , 0 ) ) from JDGL_QuantityCompletion where ProjectId = ql . ProjectId and QuantityListId = qc . QuantityListId and Months < qc . Months ) ) as LastTotalPlanNum ,
CONVERT ( FLOAT , ( select sum ( ISNULL ( RealNum , 0 ) ) from JDGL_QuantityCompletion where ProjectId = ql . ProjectId and QuantityListId = qc . QuantityListId and Months < qc . Months ) ) as LastTotalRealNum
from [ dbo ] . JDGL_QuantityList ql
left join dbo . [ JDGL_QuantityCompletion ] qc on ql . QuantityListId = qc . QuantityListId
2024-05-06 15:57:32 +08:00
where qc . QuantityCompletionId = ( select top 1 QuantityCompletionId from [ JDGL_QuantityCompletion ] q where q . QuantityListId = qc . QuantityListId and q . Months < = @month order by q . Months desc ) and qc . ProjectId = @ProjectId order by ql . SortIndex , ql . Name ";
2024-05-05 17:12:18 +08:00
//string strSql = @"select *
// from dbo.View_JDGL_QuantityCompletion qc
// where qc.ProjectId=@ProjectId order by qc.SortIndex, qc.Name";
2021-05-20 17:16:01 +08:00
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
listStr . Add ( new SqlParameter ( "@ProjectId" , this . CurrUser . LoginProjectId ) ) ;
2024-05-06 15:57:32 +08:00
listStr . Add ( new SqlParameter ( "@month" , string . Format ( "{0:yyyy-MM-dd}" , Convert . ToDateTime ( this . txtMonths . Text . Trim ( ) + "-01" ) ) ) ) ;
2021-05-20 17:16:01 +08:00
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
Grid1 . RecordCount = tb . Rows . Count ;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table ;
Grid1 . DataBind ( ) ;
2021-04-30 10:28:37 +08:00
}
#region 月 份 选 择 事 件
/// <summary>
/// 月份选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtMonths_TextChanged ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 保 存 按 钮
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click ( object sender , EventArgs e )
{
if ( this . Grid1 . Rows . Count > 0 )
{
JArray mergedData = Grid1 . GetMergedData ( ) ;
foreach ( JObject mergedRow in mergedData )
{
JObject values = mergedRow . Value < JObject > ( "values" ) ;
int i = mergedRow . Value < int > ( "index" ) ;
Model . JDGL_QuantityCompletion quantityCompletion = BLL . QuantityCompletionService . GetQuantityCompletionById ( this . Grid1 . Rows [ i ] . RowID ) ;
if ( quantityCompletion ! = null )
{
if ( ! string . IsNullOrEmpty ( values . Value < string > ( "PlanNum" ) ) )
{
quantityCompletion . PlanNum = Convert . ToDecimal ( values . Value < string > ( "PlanNum" ) ) ;
}
if ( ! string . IsNullOrEmpty ( values . Value < string > ( "RealNum" ) ) )
{
quantityCompletion . RealNum = Convert . ToDecimal ( values . Value < string > ( "RealNum" ) ) ;
}
quantityCompletion . CompileMan = this . CurrUser . UserId ;
quantityCompletion . CompileDate = DateTime . Now ;
BLL . QuantityCompletionService . UpdateQuantityCompletion ( quantityCompletion ) ;
}
}
Alert . ShowInTop ( "保存成功!" , MessageBoxIcon . Success ) ;
}
else
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
}
#endregion
2021-06-21 14:10:40 +08:00
protected void btnMenuDel_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length > 0 )
{
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
{
2024-05-05 17:12:18 +08:00
string rowID = Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
BLL . QuantityCompletionService . DeleteQuantityCompletionByQuantityCompletionId ( rowID ) ;
2021-06-21 14:10:40 +08:00
}
BindGrid ( ) ;
ShowNotify ( "删除数据成功!" , MessageBoxIcon . Success ) ;
}
}
2021-04-30 10:28:37 +08:00
#region 导 入
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "QuantityCompletionIn.aspx?ProjectId={0}" , this . CurrUser . LoginProjectId , "导入 - " ) ) ) ;
}
/// <summary>
/// 关闭导入弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close ( object sender , WindowCloseEventArgs e )
{
BindGrid ( ) ;
}
#endregion
}
}