Example #1
0
        /// <summary>
        /// 保存任务组。
        /// </summary>
        public void Save()
        {
            if (this.Name == null || this.Name.Length == 0)
            {
                throw new Exception("任务组名称必须输入。");
            }

            AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    if (this.TaskGroupId == 0)
                    {
                        string strSql = "SELECT MAX(" + Tables.TaskGroup.TaskGroupId + ") FROM " + Tables.TaskGroup.TableName;
                        this.TaskGroupId = Function.ToInt(dbConn.ExecuteScalar(strSql)) + 1;

                        strSql = this.TaskGroupId + "," + Function.SqlStr(this.Name, 250);
                        strSql = "INSERT INTO " + Tables.TaskGroup.TableName + " (" + Tables.TaskGroup.TaskGroupId + "," + Tables.TaskGroup.Name + ") VALUES (" + strSql + ")";
                        dbConn.ExecuteNonQuery(strSql);
                    }
                    else
                    {
                        string strSql = "UPDATE " + Tables.TaskGroup.TableName + " Set " + Tables.TaskGroup.Name + "=" + Function.SqlStr(this.Name, 250) + " Where " + Tables.TaskGroup.TaskGroupId + "=" + this.TaskGroupId;
                        dbConn.ExecuteNonQuery(strSql);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
Example #2
0
        /// <summary>
        /// 保存当前任务信息。
        /// </summary>
        public void Save()
        {
            if (this.Name == null || this.Name.Length == 0)
            {
                throw new Exception("任务名称必须输入。");
            }
            else if (this.Group == null)
            {
                throw new Exception("必须设置任务所属的任务组。");
            }
            else if (this.Period == null)
            {
                throw new Exception("必须配置任务的运行周期。");
            }

            AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    string strConfig = null;
                    System.Xml.XmlDocument xmlDoc   = new System.Xml.XmlDocument();
                    System.Xml.XmlNode     xnConfig = xmlDoc.CreateElement(this.GetType().Name);
                    xmlDoc.AppendChild(xnConfig);

                    System.Xml.XmlNode xnPeriodType = xmlDoc.CreateElement("PeriodType");
                    xnPeriodType.InnerText = this.Period.GetType().FullName;
                    xnConfig.AppendChild(xnPeriodType);

                    System.Xml.XmlNode xnPeriodConfig = this.Period.GetTaskPeriodConfig(xmlDoc);
                    if (xnPeriodConfig != null)
                    {
                        System.Xml.XmlNode xnPeriod = xmlDoc.CreateElement("Period");
                        xnPeriod.AppendChild(xnPeriodConfig);
                        xnConfig.AppendChild(xnPeriod);
                    }

                    System.Xml.XmlNode xnMaxRunTime = xmlDoc.CreateElement("MaxRunTime");
                    xnMaxRunTime.InnerText = this.MaxRunTime.ToString();
                    xnConfig.AppendChild(xnMaxRunTime);

                    System.Xml.XmlNode xnRetryProgress = xmlDoc.CreateElement("RetryProgress");
                    xnRetryProgress.InnerText = this.RetryProgress.ToString();
                    xnConfig.AppendChild(xnRetryProgress);

                    System.Xml.XmlNode xnIsUnqualifiedRetry = xmlDoc.CreateElement("IsUnqualifiedRetry");
                    xnIsUnqualifiedRetry.InnerText = this.IsUnqualifiedRetry.ToString();
                    xnConfig.AppendChild(xnIsUnqualifiedRetry);

                    System.Xml.XmlNode xnRetryInterval = xmlDoc.CreateElement("RetryInterval");
                    for (int i = 0; i < this.RetryInterval.Length; i++)
                    {
                        System.Xml.XmlNode xnRetryIntervalChild = xmlDoc.CreateElement(string.Format("Interval{0}", i + 1));
                        xnRetryIntervalChild.InnerText = this.RetryInterval[i].ToString();
                        xnRetryInterval.AppendChild(xnRetryIntervalChild);
                    }
                    xnConfig.AppendChild(xnRetryInterval);

                    System.Xml.XmlNode xnTaskConfig = this.GetTaskConfig(xmlDoc);
                    if (xnTaskConfig != null)
                    {
                        System.Xml.XmlNode xn = xmlDoc.CreateElement("TaskConfig");
                        xn.AppendChild(xnTaskConfig);
                        xnConfig.AppendChild(xn);
                    }

                    strConfig = xmlDoc.OuterXml;

                    if (this.TaskConfigId == 0)
                    {
                        string strSql = "SELECT MAX(" + Tables.TaskConfig.TaskConfigId + ") FROM " + Tables.TaskConfig.TableName;
                        this.TaskConfigId = Function.ToInt(dbConn.ExecuteScalar(strSql)) + 1;

                        strSql = this.TaskConfigId + "," + Function.SqlStr(this.TaskType.Code, 250) + "," + Function.SqlStr(this.Name, 250) + "," + this.Group.TaskGroupId + "," + Function.BoolToByte(this.Enable) + "," + Function.SqlStr(strConfig);
                        strSql = "INSERT INTO " + Tables.TaskConfig.TableName + " (" + Tables.TaskConfig.TaskConfigId + "," + Tables.TaskConfig.TaskType + "," + Tables.TaskConfig.Name + "," + Tables.TaskConfig.TaskGroupId + "," + Tables.TaskConfig.EnableAuto + "," + Tables.TaskConfig.XMLConfig + ") VALUES (" + strSql + ")";
                        dbConn.ExecuteNonQuery(strSql);

                        this.Group.TaskConfigs.Add(this);
                    }
                    else
                    {
                        string strSql = "UPDATE " + Tables.TaskConfig.TableName + " Set " + Tables.TaskConfig.Name + "=" + Function.SqlStr(this.Name, 250) + "," + Tables.TaskConfig.EnableAuto + "=" + Function.BoolToByte(this.Enable) + "," + Tables.Device.XMLConfig + "=" + Function.SqlStr(strConfig) + " Where " + Tables.TaskConfig.TaskConfigId + "=" + this.TaskConfigId;
                        dbConn.ExecuteNonQuery(strSql);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
Example #3
0
        /// <summary>
        /// 保存分类。
        /// </summary>
        public virtual void Save()
        {
            if (this.Name == null || this.Name.Trim().Length == 0)
            {
                throw new Exception("未设置分类名称。");
            }
            else
            {
                //配置信息
                System.Xml.XmlDocument xmlDoc   = new System.Xml.XmlDocument();
                System.Xml.XmlNode     xnConfig = xmlDoc.CreateElement(this.GetType().Name);
                xmlDoc.AppendChild(xnConfig);

                System.Xml.XmlNode xnEnabledDevice = xmlDoc.CreateElement("EnabledDevice");
                xnEnabledDevice.InnerText = Function.BoolToByte(this.EnabledDevice).ToString();
                xnConfig.AppendChild(xnEnabledDevice);

                if (this.DeviceFilters != null && this.DeviceFilters.Count > 0)
                {
                    System.Xml.XmlNode xnDeviceFilters = xmlDoc.CreateElement("DeviceFilters");
                    xnDeviceFilters.AppendChild(this.DeviceFilters.GetFilterConfig(xmlDoc));
                    xnConfig.AppendChild(xnDeviceFilters);
                }

                System.Xml.XmlNode xnClassifyConfig = this.GetClassifyConfig(xmlDoc);
                if (xnClassifyConfig != null)
                {
                    xnConfig.AppendChild(xnClassifyConfig);
                }

                string strConfig = xmlDoc.OuterXml;

                //插入或更新
                string strSql;
                if (this.ClassifyId == 0)
                {
                    AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
                    if (dbConn != null)
                    {
                        strSql          = "SELECT MAX(" + Tables.Classify.ClassifyId + ") FROM " + Tables.Classify.TableName;
                        this.ClassifyId = Function.ToInt(dbConn.ExecuteScalar(strSql)) + 1;

                        try
                        {
                            if (this.OrdinalNumber == 0)
                            {
                                this.OrdinalNumber = this.ClassifyId;
                            }

                            strSql = this.ClassifyId + "," + Function.SqlStr(this.ClassifyType.Code, 250) + "," + (this.Parent == null ? 0 : this.Parent.ClassifyId) + "," + Function.SqlStr(this.Name, 250) + "," + Function.SqlStr(this.NameShortcut, 250) + "," + Function.SqlStr(this.Identifier, 250) + "," + this.OrdinalNumber + "," + Function.SqlStr(strConfig);
                            strSql = "INSERT INTO " + Tables.Classify.TableName + " (" + Tables.Classify.ClassifyId + "," + Tables.Classify.ClassifyType + "," + Tables.Classify.ParentId + "," + Tables.Classify.Name + "," + Tables.Classify.NameShortcut + "," + Tables.Classify.Identifier + "," + Tables.Classify.OrdinalNumber + "," + Tables.Classify.XMLConfig + ") VALUES (" + strSql + ")";
                            dbConn.ExecuteNonQuery(strSql);

                            if (this.Parent != null)
                            {
                                this.Parent.Children.Add(this);
                            }
                        }
                        finally
                        {
                            dbConn.Close();
                        }
                    }
                }
                else
                {
                    AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
                    if (dbConn != null)
                    {
                        try
                        {
                            strSql = "UPDATE " + Tables.Classify.TableName + " Set " + Tables.Classify.Name + "=" + Function.SqlStr(this.Name, 250) + "," + Tables.Device.NameShortcut + "=" + Function.SqlStr(this.NameShortcut, 250) + "," + Tables.Classify.Identifier + "=" + Function.SqlStr(this.Identifier, 250) + "," + Tables.Classify.OrdinalNumber + "=" + this.OrdinalNumber + "," + Tables.Classify.XMLConfig + "=" + Function.SqlStr(strConfig) + " Where " + Tables.Classify.ClassifyId + "=" + this.ClassifyId;
                            dbConn.ExecuteNonQuery(strSql);
                        }
                        finally
                        {
                            dbConn.Close();
                        }
                    }
                }
            }
        }