Example #1
0
		public static bool LoadImage(SplendidControl ctlPARENT, Guid gParentID, string sFIELD_NAME, IDbTransaction trn)
		{
			bool bNewFile = false;
			HtmlInputFile fileIMAGE = ctlPARENT.FindControl(sFIELD_NAME + "_File") as HtmlInputFile;
			if ( fileIMAGE != null )
			{
				HttpPostedFile pstIMAGE  = fileIMAGE.PostedFile;
				if ( pstIMAGE != null )
				{
					long lFileSize      = pstIMAGE.ContentLength;
					long lUploadMaxSize = Sql.ToLong(HttpContext.Current.Application["CONFIG.upload_maxsize"]);
					if ( (lUploadMaxSize > 0) && (lFileSize > lUploadMaxSize) )
					{
						throw(new Exception("ERROR: uploaded file was too big: max filesize: " + lUploadMaxSize.ToString()));
					}
					// 04/13/2005   File may not have been provided. 
					if ( pstIMAGE.FileName.Length > 0 )
					{
						string sFILENAME       = Path.GetFileName (pstIMAGE.FileName);
						string sFILE_EXT       = Path.GetExtension(sFILENAME);
						string sFILE_MIME_TYPE = pstIMAGE.ContentType;
						
						Guid gImageID = Guid.Empty;
						SqlProcs.spIMAGES_Insert
							( ref gImageID
							, gParentID
							, sFILENAME
							, sFILE_EXT
							, sFILE_MIME_TYPE
							, trn
							);
						// 09/06/2008   PostgreSQL does not require that we stream the bytes, so lets explore doing this for all platforms. 
						if ( Sql.StreamBlobs(trn.Connection) )
						{
							SplendidDynamic.LoadFile(gImageID, pstIMAGE.InputStream, trn);
						}
						else
						{
							using ( BinaryReader reader = new BinaryReader(pstIMAGE.InputStream) )
							{
								byte[] binBYTES = reader.ReadBytes((int) pstIMAGE.InputStream.Length);
								SqlProcs.spIMAGES_CONTENT_Update(gImageID, binBYTES, trn);
							}
						}
						// 04/17/2006   Update the dynamic control so that it can be accessed below. 
						DynamicControl ctlIMAGE = new DynamicControl(ctlPARENT, sFIELD_NAME);
						ctlIMAGE.ID = gImageID;
						bNewFile = true;
					}
				}
			}
			return bNewFile;
		}
Example #2
0
		// 09/09/2009   Change parameter name to be more logical.
		public static void UpdateCustomFields(SplendidControl ctlPARENT, IDbTransaction trn, Guid gID, string sTABLE_NAME, DataTable dtCustomFields)
		{
			if ( dtCustomFields.Rows.Count > 0 )
			{
				IDbConnection con = trn.Connection;
				using ( IDbCommand cmd = con.CreateCommand() )
				{
					cmd.Transaction = trn;
					cmd.CommandType = CommandType.Text;
					cmd.CommandText = "update " + sTABLE_NAME + "_CSTM" + ControlChars.CrLf;
					int nFieldIndex = 0;
					foreach(DataRow row in dtCustomFields.Rows)
					{
						// 01/11/2006   Uppercase looks better. 
						string sNAME   = Sql.ToString(row["NAME"  ]).ToUpper();
						string sCsType = Sql.ToString(row["CsType"]);
						// 01/13/2007   We need to truncate any long strings to prevent SQL error. 
						// String or binary data would be truncated. The statement has been terminated. 
						int    nMAX_SIZE = Sql.ToInteger(row["MAX_SIZE"]);
						DynamicControl ctlCustomField = new DynamicControl(ctlPARENT, sNAME);
						// 02/10/2008   Literals should not be updated. 
						if ( ctlCustomField.Exists && ctlCustomField.Type != "Literal" )
						{
							if ( nFieldIndex == 0 )
								cmd.CommandText += "   set ";
							else
								cmd.CommandText += "     , ";
							// 01/10/2006   We can't use a StringBuilder because the Sql.AddParameter function
							// needs to be able to replace the @ with the appropriate database specific token. 
							cmd.CommandText += sNAME + " = @" + sNAME + ControlChars.CrLf;
							
							DynamicControl ctlCustomField_File = new DynamicControl(ctlPARENT, sNAME + "_File");
							// 04/21/2006   If the type is Guid and it is accompanied by a File control, then assume it is an image. 
							if ( sCsType == "Guid" && ctlCustomField.Type == "HtmlInputHidden" && ctlCustomField_File.Exists )
							{
								LoadImage(ctlPARENT, gID, sNAME, trn);
							}
							// 04/21/2006   Even if there is no image to upload, we still need to update the field.
							// This is so that the image can be cleared. 
							switch ( sCsType )
							{
								case "Guid"    :  Sql.AddParameter(cmd, "@" + sNAME, ctlCustomField.ID          );  break;
								case "short"   :  Sql.AddParameter(cmd, "@" + sNAME, ctlCustomField.IntegerValue);  break;
								case "Int32"   :  Sql.AddParameter(cmd, "@" + sNAME, ctlCustomField.IntegerValue);  break;
								case "Int64"   :  Sql.AddParameter(cmd, "@" + sNAME, ctlCustomField.IntegerValue);  break;
								case "float"   :  Sql.AddParameter(cmd, "@" + sNAME, ctlCustomField.FloatValue  );  break;
								case "decimal" :  Sql.AddParameter(cmd, "@" + sNAME, ctlCustomField.DecimalValue);  break;
								case "bool"    :  Sql.AddParameter(cmd, "@" + sNAME, ctlCustomField.Checked     );  break;
								case "DateTime":  Sql.AddParameter(cmd, "@" + sNAME, ctlCustomField.DateValue   );  break;
								default        :  Sql.AddParameter(cmd, "@" + sNAME, ctlCustomField.Text        , nMAX_SIZE);  break;
							}
							nFieldIndex++;
						}
					}
					if ( nFieldIndex > 0 )
					{
						cmd.CommandText += " where ID_C = @ID_C" + ControlChars.CrLf;
						Sql.AddParameter(cmd, "@ID_C", gID);
						cmd.ExecuteNonQuery();
					}
				}
			}
		}
Example #3
0
		// 03/14/2014   DUPLICATE_CHECHING_ENABLED enables duplicate checking. 
		// Duplicate check for EditView will provide input data from Form variables. 
		public static int DuplicateCheck(HttpApplicationState Application, IDbConnection con, string sMODULE_NAME, Guid gID, SplendidControl ctl, DataRow rowCurrent)
		{
			int nDuplicates = 0;
			string sGRID_NAME = sMODULE_NAME + ".SearchDuplicates";
			DataTable dtGridView = SplendidCache.GridViewColumns(sGRID_NAME);
			if ( dtGridView != null && dtGridView.Rows.Count > 0 )
			{
				DbProviderFactory dbf = DbProviderFactories.GetFactory();
				using ( IDbCommand cmd = con.CreateCommand() )
				{
					string sTABLE_NAME = Crm.Modules.TableName(sMODULE_NAME);
					// 04/10/2014   The first thought was just to use a count(*), but by getting all fields for matching records, we allow business rules to further filter the result. 
					cmd.CommandText = "select *" + ControlChars.CrLf
					                + "  from vw" + sTABLE_NAME + "_List" + ControlChars.CrLf;
					Security.Filter(cmd, sMODULE_NAME, "list");
					if ( !Sql.IsEmptyGuid(gID) )
					{
						cmd.CommandText += "  and ID <> @ID" + ControlChars.CrLf;
						Sql.AddParameter(cmd, "@ID", gID);
					}
					
					int nValues = 0;
					foreach(DataRow rowSearch in dtGridView.Rows)
					{
						string sDATA_FIELD  = Sql.ToString (rowSearch["DATA_FIELD" ]);
						string sDATA_FORMAT = Sql.ToString (rowSearch["DATA_FORMAT"]);
						// 03/16/2014   When searching for duplicates, multiple fields can match, but don't match an empty field. 
						string sVALUE = new DynamicControl(ctl, rowCurrent, sDATA_FIELD).Text;
						if ( !Sql.IsEmptyString(sVALUE) )
						{
							Sql.AppendParameter(cmd, sVALUE, sDATA_FIELD);
							nValues++;
						}
					}
					// 03/16/2014   If no required fields were specified, then don't search. 
					if ( nValues > 0 )
					{
						using ( DbDataAdapter da = dbf.CreateDataAdapter() )
						{
							((IDbDataAdapter)da).SelectCommand = cmd;
							using ( DataTable dtDuplicates = new DataTable() )
							{
								da.Fill(dtDuplicates);

								SplendidDynamic.ApplyGridViewRules(sGRID_NAME, ctl, "PRE_LOAD_EVENT_XOML", "POST_LOAD_EVENT_XOML", dtDuplicates);
								foreach ( DataRow rowDuplicates in dtDuplicates.Rows )
								{
									if ( rowDuplicates.RowState != DataRowState.Deleted )
									{
										nDuplicates++;
									}
								}
							}
						}
					}
				}
			}
			return nDuplicates;
		}