Exemplo n.º 1
0
        public bool Update(out string Err, MySqlConnection ConX = null, bool SaveChildren = true)
        {
            Err = "";
            bool openConX = ConX == null;

            if (openConX)
            {
                ConX = new MySqlConnection(DBOps.ConnectionString);
                ConX.Open();
            }
            try
            {
                string sql = @"UPDATE template
                    SET Description=@Description,X=@X,Y=@Y,Width=@Width,Height=@Height,Expression=@Expression,URL=@URL,
                    Contents=@Contents,IsContainer=@IsContainer,IsRepeatingItem=@IsRepeatingItem,CanExpand=@CanExpand,
                    StickToTop=@StickToTop,StickToBottom=@StickToBottom,ContinuedOver=@ContinuedOver,
                    ContinuedFrom=@ContinuedFrom,NotContinuedOver=@NotContinuedOver,NotContinuedFrom=@NotContinuedFrom,
                    KeepTogether=@KeepTogether,MinOrphanWidowRows=@MinOrphanWidowRows,OwnerID=@OwnerID
                    WHERE TemplateID=@TemplateID;
                    SELECT ROW_COUNT();";
                var    cmd = new MySqlCommand(sql, ConX);
                cmd.Parameters.AddWithValue("TemplateID", TemplateID);
                cmd.Parameters.AddWithValue("Description", (Description ?? "").Trim());
                cmd.Parameters.AddWithValue("X", X);
                cmd.Parameters.AddWithValue("Y", Y);
                cmd.Parameters.AddWithValue("Width", Width);
                cmd.Parameters.AddWithValue("Height", Height);
                cmd.Parameters.AddWithValue("Expression", (Expression ?? "").Trim());
                cmd.Parameters.AddWithValue("URL", (URL ?? "").Trim());
                cmd.Parameters.AddWithValue("Contents", Contents);
                cmd.Parameters.AddWithValue("IsContainer", IsContainer);
                cmd.Parameters.AddWithValue("IsRepeatingItem", IsRepeatingItem);
                cmd.Parameters.AddWithValue("CanExpand", CanExpand);
                cmd.Parameters.AddWithValue("StickToTop", StickToTop);
                cmd.Parameters.AddWithValue("StickToBottom", StickToBottom);
                cmd.Parameters.AddWithValue("ContinuedOver", ContinuedOver);
                cmd.Parameters.AddWithValue("ContinuedFrom", ContinuedFrom);
                cmd.Parameters.AddWithValue("NotContinuedOver", NotContinuedOver);
                cmd.Parameters.AddWithValue("NotContinuedFrom", NotContinuedFrom);
                cmd.Parameters.AddWithValue("KeepTogether", KeepTogether);
                cmd.Parameters.AddWithValue("MinOrphanWidowRows", MinOrphanWidowRows);
                int?ownerID = OwnerID <= 0 ? null : (int?)OwnerID;
                cmd.Parameters.AddWithValue("OwnerID", ownerID);
                int rv = cmd.ExecuteScalarInt32();
                if (rv <= 0)
                {
                    Err = "The template could not be saved.";
                }

                if (TemplateID > 0 && SaveChildren)
                {
                    ChildTemplates.SaveChildenForTemplate(TemplateID, out Err, ConX);
                    if (!string.IsNullOrWhiteSpace(Err))
                    {
                        return(false);
                    }
                }

                return(TemplateID > 0);
            }
            catch (Exception ex)
            {
                Err = ex.Message;
                return(false);
            }
            finally
            {
                if (openConX)
                {
                    ConX.Close();
                }
            }
        }
Exemplo n.º 2
0
        public bool Create(out string Err, MySqlConnection ConX = null)
        {
            Err = "";
            bool openConX = ConX == null;

            if (openConX)
            {
                ConX = new MySqlConnection(DBOps.ConnectionString);
                ConX.Open();
            }
            try
            {
                string sql = @"INSERT INTO template
                    (Description,X,Y,Width,Height,Expression,URL,Contents,IsContainer,IsRepeatingItem,CanExpand,
                    StickToTop,StickToBottom,ContinuedOver,ContinuedFrom,NotContinuedOver,NotContinuedFrom,KeepTogether,
                    MinOrphanWidowRows,OwnerID)
                    VALUES(@Description,@X,@Y,@Width,@Height,@Expression,@URL,@Contents,@IsContainer,@IsRepeatingItem,@CanExpand,
                    @StickToTop,@StickToBottom,@ContinuedOver,@ContinuedFrom,@NotContinuedOver,@NotContinuedFrom,@KeepTogether,
                    @MinOrphanWidowRows,@OwnerID);
                    SELECT LAST_INSERT_ID();";
                var    cmd = new MySqlCommand(sql, ConX);
                cmd.Parameters.AddWithValue("Description", (Description ?? "").Trim());
                cmd.Parameters.AddWithValue("X", X);
                cmd.Parameters.AddWithValue("Y", Y);
                cmd.Parameters.AddWithValue("Width", Width);
                cmd.Parameters.AddWithValue("Height", Height);
                cmd.Parameters.AddWithValue("Expression", (Expression ?? "").Trim());
                cmd.Parameters.AddWithValue("URL", (URL ?? "").Trim());
                cmd.Parameters.AddWithValue("Contents", Contents);
                cmd.Parameters.AddWithValue("IsContainer", IsContainer);
                cmd.Parameters.AddWithValue("IsRepeatingItem", IsRepeatingItem);
                cmd.Parameters.AddWithValue("CanExpand", CanExpand);
                cmd.Parameters.AddWithValue("StickToTop", StickToTop);
                cmd.Parameters.AddWithValue("StickToBottom", StickToBottom);
                cmd.Parameters.AddWithValue("ContinuedOver", ContinuedOver);
                cmd.Parameters.AddWithValue("ContinuedFrom", ContinuedFrom);
                cmd.Parameters.AddWithValue("NotContinuedOver", NotContinuedOver);
                cmd.Parameters.AddWithValue("NotContinuedFrom", NotContinuedFrom);
                cmd.Parameters.AddWithValue("KeepTogether", KeepTogether);
                cmd.Parameters.AddWithValue("MinOrphanWidowRows", MinOrphanWidowRows);
                int?ownerID = OwnerID <= 0 ? null : (int?)OwnerID;
                cmd.Parameters.AddWithValue("OwnerID", ownerID);
                int rv = cmd.ExecuteScalarInt32();
                if (rv > 0)
                {
                    TemplateID = rv;
                }
                if (TemplateID <= 0)
                {
                    Err = "The template could not be saved.";
                }

                if (TemplateID > 0)
                {
                    ChildTemplates.SaveChildenForTemplate(TemplateID, out Err, ConX);
                    if (!string.IsNullOrWhiteSpace(Err))
                    {
                        return(false);
                    }
                }

                return(TemplateID > 0);
            }
            catch (Exception ex)
            {
                Err = ex.Message;
                return(false);
            }
            finally
            {
                if (openConX)
                {
                    ConX.Close();
                }
            }
        }