public static void UpdateCustomFields(CRMControl ctlPARENT, IDbTransaction trn, Guid gID, string sCUSTOM_MODULE, DataTable dtCustomFields)
 {
     UpdateCustomFields(ctlPARENT, gID, sCUSTOM_MODULE, dtCustomFields);
 }
        public static void UpdateCustomFields(CRMControl ctlPARENT, Guid gID, string sCUSTOM_MODULE, DataTable dtCustomFields)
        {
            if (dtCustomFields.Rows.Count > 0)
            {
                InlineQueryDBManager oQuery = new InlineQueryDBManager();
                oQuery.CommandText = "update " + sCUSTOM_MODULE + "_CSTM" + ControlChars.CrLf;
                int nFieldIndex = 0;
                foreach (DataRow row in dtCustomFields.Rows)
                {
                    string sNAME = TypeConvert.ToString(row["NAME"]).ToUpper();
                    string sCsType = TypeConvert.ToString(row["CsType"]);

                    int nMAX_SIZE = TypeConvert.ToInteger(row["MAX_SIZE"]);
                    DynamicControl ctlCustomField = new DynamicControl(ctlPARENT, sNAME);

                    if (ctlCustomField.Exists && ctlCustomField.Type != "Literal")
                    {
                        if (nFieldIndex == 0)
                            oQuery.CommandText += "   set ";
                        else
                            oQuery.CommandText += "     , ";

                        oQuery.CommandText += sNAME + " = @" + sNAME + ControlChars.CrLf;

                        DynamicControl ctlCustomField_File = new DynamicControl(ctlPARENT, sNAME + "_File");

                        if (sCsType == "Guid" && ctlCustomField.Type == "HtmlInputHidden" && ctlCustomField_File.Exists)
                        {
                            LoadImage(ctlPARENT, gID, sNAME);
                        }
                        SqlParameter oParam = new SqlParameter();
                        switch (sCsType)
                        {
                            case "Guid":
                                oParam = new SqlParameter("@" + sNAME, SqlDbType.UniqueIdentifier);
                                oParam.Value = ctlCustomField.ID;
                                break;
                            case "short":
                                oParam = new SqlParameter("@" + sNAME, SqlDbType.Int);
                                oParam.Value = ctlCustomField.IntegerValue;
                                break;
                            case "Int32":
                                oParam = new SqlParameter("@" + sNAME, SqlDbType.Int);
                                oParam.Value = ctlCustomField.IntegerValue;
                                break;
                            case "Int64":
                                oParam = new SqlParameter("@" + sNAME, SqlDbType.Int);
                                oParam.Value = ctlCustomField.IntegerValue;
                                break;
                            case "float":
                                oParam = new SqlParameter("@" + sNAME, SqlDbType.Float);
                                oParam.Value = ctlCustomField.FloatValue;
                                break;
                            case "decimal":
                                oParam = new SqlParameter("@" + sNAME, SqlDbType.Decimal);
                                oParam.Value = ctlCustomField.DecimalValue;
                                break;
                            case "bool":
                                oParam = new SqlParameter("@" + sNAME, SqlDbType.Bit);
                                oParam.Value = ctlCustomField.Checked;
                                break;
                            case "DateTime":
                                oParam = new SqlParameter("@" + sNAME, SqlDbType.DateTime);
                                oParam.Value = ctlCustomField.DateValue;
                                break;
                            default:
                                oParam = new SqlParameter("@" + sNAME, SqlDbType.NVarChar, nMAX_SIZE);
                                oParam.Value = ctlCustomField.Text;
                                break;
                        }
                        nFieldIndex++;
                    }
                }
                if (nFieldIndex > 0)
                {
                    oQuery.CommandText += " where ID_C = @ID_C" + ControlChars.CrLf;
                    SqlParameter oParamID = new SqlParameter("@ID_C", SqlDbType.UniqueIdentifier);
                    oParamID.Value = gID;
                    oQuery.CommandType = CommandType.Text;
                    oQuery.ExecuteNonQuery(oQuery.CommandText);
                }
            }
        }
        public static bool LoadImage(CRMControl ctlPARENT, Guid gParentID, string sFIELD_NAME)
        {
            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 = TypeConvert.ToLong(ConfigurationManager.AppSettings["upload_maxsize"]);
                    if ((lUploadMaxSize > 0) && (lFileSize > lUploadMaxSize))
                    {
                        throw (new Exception("ERROR: uploaded file was too big: max filesize: " + lUploadMaxSize.ToString()));
                    }

                    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;
                        ModelLayer.CommonProcedure.ImagesInsert(ref gImageID, gParentID, sFILENAME, sFILE_EXT, sFILE_MIME_TYPE);
                        CRMDynamic.LoadFile(gImageID, pstIMAGE.InputStream);

                        DynamicControl ctlIMAGE = new DynamicControl(ctlPARENT, sFIELD_NAME);
                        ctlIMAGE.ID = gImageID;
                        bNewFile = true;
                    }
                }
            }
            return bNewFile;
        }