Пример #1
0
        public static void UpdateCustomFields(SplendidControl ctlPARENT, IDbTransaction trn, Guid gID, string sCUSTOM_MODULE, 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 " + sCUSTOM_MODULE + "_CSTM" + ControlChars.CrLf;
                    int nFieldIndex = 0;
                    foreach(DataRow row in dtCustomFields.Rows)
                    {
                        // 01/11/2006 Paul.  Uppercase looks better.
                        string sNAME   = Sql.ToString(row["NAME"  ]).ToUpper();
                        string sCsType = Sql.ToString(row["CsType"]);
                        DynamicControl ctlCustomField = new DynamicControl(ctlPARENT, sNAME);
                        if ( ctlCustomField.Exists )
                        {
                            if ( nFieldIndex == 0 )
                                cmd.CommandText += "   set ";
                            else
                                cmd.CommandText += "     , ";
                            // 01/10/2006 Paul.  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 Paul.  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 Paul.  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        );  break;
                            }
                            nFieldIndex++;
                        }
                    }
                    if ( nFieldIndex > 0 )
                    {
                        cmd.CommandText += " where ID_C = @ID_C" + ControlChars.CrLf;
                        Sql.AddParameter(cmd, "@ID_C", gID);
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
Пример #2
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 Paul.  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
                            );
                        SplendidDynamic.LoadFile(gImageID, pstIMAGE.InputStream, trn);
                        // 04/17/2006 Paul.  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;
        }