/// <summary>
        /// 读取指定发布信息
        /// </summary>
        /// <param name="ap_id"></param>
        /// <returns></returns>
        public ADPublish ReadADPublish(long ap_id)
        {
            string      configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            DataContext dd         = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                Table <ADPublish> tbl       = dd.GetTable <ADPublish>();
                ADPublish         adPublish = (from p in tbl where p.AP_ID == ap_id select p).Single();
                return(adPublish);
            }
            catch {
                return(null);
            }
        }
        /// <summary>
        /// 发布广告
        /// </summary>
        /// <param name="ap_id"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public string ADPublish(long ap_id, PublishType type = PublishType.NewPublish)
        {
            M_ADService adservice = new M_ADService();
            string      result    = "";

            try
            {
                ADPublish adPublish = this.ReadADPublish(ap_id);
                result = adservice.PublishAD(adPublish, this.ReadPublishUser(ap_id), this.ReadADItems((long)adPublish.AC_ID), type);
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// 发布广告
        /// </summary>
        /// <param name="ap">广告发布信息</param>
        /// <param name="listMeter">广告用户列表</param>
        /// <param name="aDItems">广告内容列表</param>
        /// <param name="type">发布类型</param>
        /// <returns></returns>
        public string PublishAD(ADPublish ap, List <ADPublisMeter> listMeter, List <ADItem> aDItems, PublishType type)
        {
            //创建一个任务
            ser++;

            MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
            // DataItem_C109(byte ser, ADPublishOperatorCode operatorCode,byte fileCount,List<ADFile> fileList)
            //发布文件列表
            List <Common.Item.ADFile> fileList = new List <Common.Item.ADFile>();
            //操作码
            ADPublishOperatorCode operatorCode = type == PublishType.NewPublish ? ADPublishOperatorCode.ReDefineList : ADPublishOperatorCode.AddList;
            //文件条数
            byte fileCount = (byte)aDItems.Count;

            foreach (ADItem item in aDItems)
            {
                Common.Item.ADFile aDfile = new Common.Item.ADFile((int)item.OrderID, item.StoreName, (DateTime)item.BDate, (DateTime)item.EDate, (int)item.Length, (int)item.FileLength);
                fileList.Add(aDfile);
            }

            foreach (ADPublisMeter meter in listMeter)
            {
                Task task = new Task();
                task.MeterMac   = meter.MeterNo.Trim();
                task.TaskDate   = QuShi.getDate();
                task.TaskID     = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState  = TaskState.Waitting;
                task.TaskType   = TaskType.TaskType_发布广告;    //广告文件(GGF)
                task.TaskSource = string.Format("{0}|{1}|{2}", meter.AP_ID, meter.UserID, meter.CompanyID);
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);

                //meter.TaskID = task.TaskID;  //设置任务编号
                //准备指令
                Command       cmd       = new Command();
                DataItem_C109 item_c109 = new DataItem_C109(ser, operatorCode, fileCount, fileList);
                cmd.Identification = ((UInt16)item_c109.IdentityCode).ToString("X2");;
                cmd.ControlCode    = (byte)ControlCode.CYWriteData;//设置参数
                byte[] tmp = item_c109.GetBytes();
                cmd.DataLength  = Convert.ToByte(tmp.Length);
                cmd.DataCommand = MyDataConvert.BytesToHexStr(tmp);  //指令内容
                cmd.Order       = (byte)1;

                cmd.TaskID = task.TaskID;

                CommandDA.Insert(cmd);
            }

            //Command cmd = new Command();
            //byte ser = Convert.ToByte(new Random().Next(0, 255));
            //byte fileid = (byte)adfile.id;//广告命令 只存储文件编号
            //byte[] contentAllBytes = new byte[1];
            //contentAllBytes[0] = fileid;
            ////1.文件发送
            //DataItem_C108 item_C108 = new DataItem_C108(ser, adfile.FileName, 1, 1, 1, 1, contentAllBytes);//
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_C108.IdentityCode).ToString("X2"); ;
            //cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数
            //cmd.DataLength = Convert.ToByte(contentAllBytes.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C108.GetBytes()); ; //文件内容
            //cmd.Order = (byte)1;
            //CommandDA.Insert(cmd);


            //1.文件配置发送指令
            //cmd = new Command();
            //DataItem_C109 item_C109 = new DataItem_C109(Convert.ToByte(new Random().Next(0, 255)), adddfile.FileNO, adddfile.FileName, adddfile.DTStart, adddfile.DTEnd, adddfile.PollTime, adddfile.OpShowStatus, adddfile.OpDeleteStatus);//
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_C109.IdentityCode).ToString("X2");
            //cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数
            //cmd.DataLength = Convert.ToByte(item_C109.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C109.GetBytes());
            //cmd.Order = (byte)(2);
            //CommandDA.Insert(cmd);

            return("");//返回空表示成功
        }
Exemple #4
0
        public override void DoLoginedHandlerWork(HttpContext context)
        {
            Message jsonMessage;

            jsonMessage = new Message()
            {
                Result     = false,
                TxtMessage = "权限验证失败,可能原因:\n1、数据中心通讯失败。\n2、系统管理员未与您分配对应操作权限。"
            };

            string    AjaxType = context.Request.QueryString["AType"] == null ? string.Empty : context.Request.QueryString["AType"].ToString().ToUpper();
            ADPublish Info     = new ADPublish();
            WCFServiceProxy <IADPublishDAL>     proxy     = new WCFServiceProxy <IADPublishDAL>();
            WCFServiceProxy <IADPublishUserDAL> proxyPU   = new WCFServiceProxy <IADPublishUserDAL>();
            WCFServiceProxy <IADUserDAL>        proxyAdU  = new WCFServiceProxy <IADUserDAL>();
            WCFServiceProxy <IADContextDAL>     proxyGGZT = new WCFServiceProxy <IADContextDAL>();

            Info = new CommonModelFactory <ADPublish>().GetModelFromContext(context);


            try
            {
                switch (AjaxType)
                {//查询用户
                case "QUERY":

                    CommonSearch <View_AdPublish> InfoSearch = new CommonSearch <View_AdPublish>();
                    string Where = "1=1 and CompanyID='" + loginOperator.CompanyID + "' ";
                    if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty)
                    {
                        Where += context.Request.Form["TWhere"].ToString();
                    }
                    SearchCondition sCondition = new SearchCondition()
                    {
                        TBName = "View_AdPublish", TFieldKey = "AP_ID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "AP_ID asc", TWhere = Where
                    };
                    List <View_AdPublish> list = InfoSearch.GetList(ref sCondition, context);
                    jsonMessage = new Message()
                    {
                        Result     = true,
                        TxtMessage = JSon.ListToJson <View_AdPublish>(list, sCondition.TTotalCount)
                    };
                    break;

                //列表
                case "QUERYVIEW":

                    CommonSearch <View_AdPublish> InfoSearchView = new CommonSearch <View_AdPublish>();
                    Where = "1=1 and CompanyID='" + loginOperator.CompanyID + "' ";
                    if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty)
                    {
                        Where += context.Request.Form["TWhere"].ToString();
                    }
                    sCondition = new SearchCondition()
                    {
                        TBName = "View_AdPublish", TFieldKey = "AP_ID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = " AP_ID asc", TWhere = Where
                    };

                    List <View_AdPublish> listView = InfoSearchView.GetList(ref sCondition, context);

                    jsonMessage = new Message()
                    {
                        Result     = true,
                        TxtMessage = JSon.ListToJson <View_AdPublish>(listView, sCondition.TTotalCount)
                    };
                    break;

                //添加广告内容
                case "ADD":

                    //1.添加到发布主表
                    Info.CompanyID = base.loginOperator.CompanyID;
                    jsonMessage    = proxy.getChannel.Add(Info);
                    //当发布成功后再进行后续人员添加操作;
                    if (jsonMessage.Result)
                    {
                        //取得返回AP_ID
                        long recAP_ID = long.Parse(jsonMessage.TxtMessage);
                        //2.添加到发布用户表中;
                        if (context.Request.Form["strNo"] != null && context.Request.Form["strNo"].ToString().Trim() != string.Empty)
                        {
                            ADPublishUser adPUser = new ADPublishUser();
                            adPUser.AP_ID     = recAP_ID;
                            adPUser.CompanyID = loginOperator.CompanyID;
                            //State和FinishDate两个字段由APP程序完成
                            adPUser.State = 0;
                            //adPUser.FinishedDate = DateTime.Now;
                            adPUser.Context = context.Request.Form["CNContext"] == null ? string.Empty : context.Request.Form["CNContext"].ToString();
                            string strNo = context.Request.Form["strNo"];
                            jsonMessage = proxyPU.getChannel.groupAdd(adPUser, strNo);
                            if (!jsonMessage.Result)
                            {
                                break;
                            }
                        }
                        //当是发布状态时调用接口
                        if (Info.State == 1 || Info.State == 2)
                        {
                            //3.调用APP段发布接口
                            string pmApp = proxy.getChannel.ADPubManager(recAP_ID);
                            if (pmApp.IndexOf("APP接口") >= 0)
                            {
                                jsonMessage.TxtMessage = pmApp;
                                break;
                            }
                            //4.更新广告主题表中的状态;
                            if (Info.State == 1 || Info.State == 2)
                            {
                                jsonMessage = proxyGGZT.getChannel.UpadteAdStatus(long.Parse(Info.AC_ID.ToString()), 2);
                            }
                        }
                    }

                    break;

                case "EDIT":
                    Info.CompanyID = base.loginOperator.CompanyID;
                    jsonMessage    = proxy.getChannel.Edit(Info);
                    if (jsonMessage.Result)
                    {
                        ADPublishUser adPUser = new ADPublishUser();
                        adPUser.AP_ID     = Info.AP_ID;
                        adPUser.CompanyID = loginOperator.CompanyID;
                        //if (Info.State == 1 || Info.State == 2)
                        //{
                        //    adPUser.State = 1;
                        //}
                        //else
                        //{
                        adPUser.State = 0;
                        //}

                        adPUser.Context = context.Request.Form["CNContext"] == null ? string.Empty : context.Request.Form["CNContext"].ToString();
                        string strNo = context.Request.Form["strNo"];
                        jsonMessage = proxyPU.getChannel.groupAdd(adPUser, strNo);
                        if (!jsonMessage.Result)
                        {
                            break;
                        }

                        if (Info.State == 1 || Info.State == 2)
                        {
                            //3.调用APP段发布接口
                            string pmApp = proxy.getChannel.ADPubManager(long.Parse(Info.AP_ID.ToString()));
                            if (pmApp.IndexOf("APP接口") >= 0)
                            {
                                jsonMessage.TxtMessage = pmApp;
                                break;
                            }

                            //2.更新广告主题表中的状态;
                            if (Info.State == 1 || Info.State == 2)
                            {
                                jsonMessage = proxyGGZT.getChannel.UpadteAdStatus(long.Parse(Info.AC_ID.ToString()), 2);
                            }
                        }
                    }

                    break;

                //删除信息
                case "DELETINFO":

                    jsonMessage = proxy.getChannel.Delete(Info.AP_ID);

                    break;

                //更新状态
                case "UPDATESTATE":
                    jsonMessage = proxy.getChannel.UpadteAdStatus(Info.AP_ID, 1);
                    //3.更新广告主题表中的状态;
                    if (jsonMessage.Result)
                    {
                        //3.调用APP段发布接口
                        string pmApp = proxy.getChannel.ADPubManager(long.Parse(Info.AP_ID.ToString()));
                        if (pmApp.IndexOf("APP接口") >= 0)
                        {
                            jsonMessage.TxtMessage = pmApp;
                            break;
                        }
                        else
                        {
                            jsonMessage = proxyGGZT.getChannel.UpadteAdStatus(long.Parse(Info.AC_ID.ToString()), 2);
                        }
                    }
                    break;

                //发布人员信息
                case "QUERYVIEWPUINFO":

                    CommonSearch <View_AdPublishUserInfo> InfoSearchView_pu = new CommonSearch <View_AdPublishUserInfo>();
                    Where  = "1=1 ";
                    Where += "AND CompanyID='" + loginOperator.CompanyID + "' ";
                    if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty)
                    {
                        Where += context.Request.Form["TWhere"].ToString();
                    }
                    sCondition = new SearchCondition()
                    {
                        TBName = "View_AdPublishUserInfo", TFieldKey = " ID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "  ID asc", TWhere = Where
                    };

                    List <View_AdPublishUserInfo> listView_pu = InfoSearchView_pu.GetList(ref sCondition, context);

                    jsonMessage = new Message()
                    {
                        Result     = true,
                        TxtMessage = JSon.ListToJson <View_AdPublishUserInfo>(listView_pu, sCondition.TTotalCount)
                    };
                    break;

                default:
                    jsonMessage = new Message()
                    {
                        Result     = false,
                        TxtMessage = "操作未定义!"
                    };
                    break;
                }
            }
            catch (Exception ex)
            {
                jsonMessage = new Message()
                {
                    Result     = false,
                    TxtMessage = ex.Message
                };
            }
            finally
            {
                if (proxy != null)
                {
                    proxy.CloseChannel();
                }
            }
            context.Response.Write(JSon.TToJson <Message>(jsonMessage));
        }
Exemple #5
0
        /// <summary>
        /// 修改主题
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public Message Edit(ADPublish model)
        {
            Message jsonMessage;
            bool    resultB = false;
            string  recStr = "", recAPP = "";

            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update ADPublish set ");
                strSql.Append("CompanyID=@CompanyID,");
                strSql.Append("AC_ID=@AC_ID,");
                strSql.Append("AreaContext=@AreaContext,");
                strSql.Append("PublishDate=@PublishDate,");
                strSql.Append("UserCount=@UserCount,");
                strSql.Append("State=@State");
                strSql.Append(" where AP_ID=@AP_ID");
                SqlParameter[] parameters =
                {
                    new SqlParameter("@CompanyID",   SqlDbType.Char,        4),
                    new SqlParameter("@AC_ID",       SqlDbType.BigInt,      8),
                    new SqlParameter("@AreaContext", SqlDbType.VarChar,   200),
                    new SqlParameter("@PublishDate", SqlDbType.DateTime),
                    new SqlParameter("@UserCount",   SqlDbType.Int,         4),
                    new SqlParameter("@State",       SqlDbType.SmallInt,    2),
                    new SqlParameter("@AP_ID",       SqlDbType.BigInt, 8)
                };
                parameters[0].Value = model.CompanyID;
                parameters[1].Value = model.AC_ID;
                parameters[2].Value = model.AreaContext;
                parameters[3].Value = model.PublishDate;
                parameters[4].Value = model.UserCount;
                parameters[5].Value = model.State;
                parameters[6].Value = model.AP_ID;

                resultB = SQLHelper.ExecuteNonQuery(conString, CommandType.Text, strSql.ToString(), parameters) > 0;
                if (!resultB)
                {
                    recStr = "修改失败!";
                }
                else
                {
                    recStr = "修改成功!";
                    //if (model.State == 1 || model.State == 2) {
                    //    //当状态为发布的时间调用发布接口;
                    //    string adpjk = new ADPublishManager().ADPublish(model.AP_ID,PublishType.NewPublish);
                    //    if (adpjk.Length > 0)
                    //    {
                    //        //不成功时显示特定失败信息
                    //        recStr = "信息修改成功,但发布失败!";
                    //        recAPP = "APP接口调用失败! " + adpjk;
                    //        recStr += "," + recAPP;
                    //        //状态重新修改为未发布
                    //        string sqlStr = "update ADPublish set State= 0 where AP_ID = " + model.AP_ID;
                    //        SQLHelper.ExecuteNonQuery(conString, CommandType.Text, sqlStr.ToString());
                    //    };
                    //}
                }
            }
            catch (Exception e)
            {
                recStr = e.ToString();
            }


            jsonMessage = new Message()
            {
                Result     = resultB,
                TxtMessage = recStr
            };
            return(jsonMessage);
        }
Exemple #6
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public Message Add(ADPublish model)
        {
            Message jsonMessage;
            bool    resultB = false;
            string  recStr = "", recAPP = "";
            long    AutoId = 0;

            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ADPublish(");
            strSql.Append("CompanyID,AC_ID,AreaContext,PublishDate,UserCount,State)");
            strSql.Append(" values (");
            strSql.Append("@CompanyID,@AC_ID,@AreaContext,@PublishDate,@UserCount,@State)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CompanyID",   SqlDbType.Char,        4),
                new SqlParameter("@AC_ID",       SqlDbType.BigInt,      8),
                new SqlParameter("@AreaContext", SqlDbType.VarChar,   200),
                new SqlParameter("@PublishDate", SqlDbType.DateTime),
                new SqlParameter("@UserCount",   SqlDbType.Int,         4),
                new SqlParameter("@State",       SqlDbType.SmallInt, 2)
            };
            parameters[0].Value = model.CompanyID;
            parameters[1].Value = model.AC_ID;
            parameters[2].Value = model.AreaContext;
            parameters[3].Value = model.PublishDate;
            parameters[4].Value = model.UserCount;
            parameters[5].Value = model.State;


            //resultB = SQLHelper.ExecuteNonQuery(conString, CommandType.Text, strSql.ToString(), parameters) > 0;
            AutoId = long.Parse(SQLHelper.ExecuteScalar(conString, CommandType.Text, strSql.ToString(), parameters).ToString());
            if (AutoId > 0)
            {
                resultB = true;
                recStr  = AutoId.ToString();

                ////当状态为发布的时间调用发布接口;
                //string adpjk = new ADPublishManager().ADPublish(AutoId);
                //if(model.State==1||model.State==2){
                //    if (adpjk.Length > 0)
                //    { //不成功时显示特定失败信息
                //        recAPP = "APP接口调用失败! " + adpjk;
                //        recStr +=",信息添加成功,但发布失败!" + recAPP;
                //        //状态重新修改为未发布
                //        string sqlStr = "update ADPublish set State= 0 where AP_ID = " + AutoId;
                //        SQLHelper.ExecuteNonQuery(conString, CommandType.Text, sqlStr.ToString());
                //    };

                //}
            }
            else
            {
                resultB = false; recStr = "添加失败!";
            }

            jsonMessage = new Message()
            {
                Result     = resultB,
                TxtMessage = recStr
            };
            return(jsonMessage);
        }