Click here to Skip to main content
15,896,269 members
Articles / Database Development / SQL Server / SQL Server 2008

Architecture Guide: Windows Forms, Generics, Auto-Mapper, Entity Framework, Framework Design, and many more..

Rate me:
Please Sign up or sign in to vote.
4.93/5 (39 votes)
12 Dec 2013CPOL15 min read 142K   3.8K   175  
Architecting a Windows Forms based system on top of a framework. This will help you develop a form based application faster.
USE [Demo_Main]
GO
/****** Object:  StoredProcedure [dbo].[InsertWeeklyOfMonthLeafWeight]    Script Date: 10/27/2010 10:47:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author		:	G.R.N.Gunathilake
-- Create date	:	10/18/2010 1:56 PM	
-- Description	:	This SP for Insert Weekly Weight Summary Data of Month into central Database
-- =============================================
ALTER PROCEDURE [dbo].[InsertWeeklyOfMonthLeafWeight]
--	(
--		@FactoryId AS Int,
--		@Year AS int
--	)
AS

BEGIN	
	SET NOCOUNT ON;	
	DECLARE @FactoryId as varchar(20)
	DECLARE @FactoryName as varchar(50)
	DECLARE @Year As Int
	DECLARE @Month as int	
	DECLARE @Week as int
	DECLARE @Weight as Float
	DECLARE @DisplayedWeight as Float
	DECLARE @GainWeight as Float
	DECLARE @ProjectedWeight as Float	
	DECLARE @ProcessedWeight as Float
	DECLARE @isWeekOfMonthWeightExist as int

	--BEGIN	
		DECLARE recWeeklyWeightSummary CURSOR FOR 
		SELECT FactoryId,FactoryName,Year,Month,Week
		,SUM(Weight),SUM(DisplayedWeight)
		,SUM(GainWeight),SUM(ProjectedWeight)
		,SUM(ProcessedWeight)
		FROM dbo.DailyLeafWeight
		GROUP BY
		FactoryId,FactoryName,Year,Month,Week
		
		OPEN recWeeklyWeightSummary

		FETCH NEXT FROM recWeeklyWeightSummary INTO 
			@FactoryId,@FactoryName,@Year,@Month, @Week,
			@Weight,@DisplayedWeight,@GainWeight,@ProjectedWeight,@ProcessedWeight
		
		WHILE (@@FETCH_STATUS=0)
			BEGIN
				SET @isWeekOfMonthWeightExist = (SELECT Count(*) FROM dbo.WeeklyLeafWeight 
										WHERE FactoryId = @FactoryId and FactoryName = @FactoryName and Year = @Year and Month = @Month and Week=@Week)
			
				IF 	@isWeekOfMonthWeightExist = 0 
					BEGIN	
						INSERT INTO dbo.WeeklyLeafWeight
						SELECT @FactoryId,@FactoryName,@Year,@Month,@Week,
								@Weight,@DisplayedWeight,@GainWeight,@ProjectedWeight,@ProcessedWeight								
					END
				IF 	@isWeekOfMonthWeightExist = 1 
					BEGIN
						UPDATE dbo.WeeklyLeafWeight SET 
							Weight = @Weight,
							DisplayedWeight = @DisplayedWeight,
							GainWeight = @GainWeight,
							ProjectedWeight = @ProjectedWeight,
							ProcessedWeight =0 
						WHERE FactoryId = @FactoryId and FactoryName = @FactoryName and Year = @Year and Month = @Month and Week = @Week
					END				
					

				FETCH NEXT FROM recWeeklyWeightSummary INTO 
						@FactoryId,@FactoryName,@Year,@Month,@Week,
						@Weight,@DisplayedWeight,@GainWeight,@ProjectedWeight,@ProcessedWeight		
			END
		CLOSE recWeeklyWeightSummary;
		DEALLOCATE recWeeklyWeightSummary;
	END
--END	




By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Virtusa Pvt. Ltd.
Sri Lanka Sri Lanka
In-depth coverage of Microsoft .Net, Cloud and many other cutting-edge Technologies.

- The Mandelbrot set – someone has called it the thumb-print of God – is one of the most beautiful and remarkable discoveries in the entire history of mathematics. My profile picture is generated with that equation.

You may contact Nirosh for Consultations, Code Reviews and Architecture Guide Workshops via c_nir*o*sh@hotmail.com (Remove * to use)



View Nirosh L.W.C.'s profile on LinkedIn


Other Links

Comments and Discussions