예제 #1
0
파일: DBUitility.cs 프로젝트: yuyuzeze/Site
 public static int GetRecord(string name)
 {
     string sql = "select rank from Demo where name=@name";
     SQLiteDBHelper db = new SQLiteDBHelper(dbPath);
     SQLiteParameter[] parameters = new SQLiteParameter[] { new SQLiteParameter("@name", SqliteEscape(name)) };
     return int.Parse(db.ExecuteScalar(sql, parameters).ToString());
 }
예제 #2
0
파일: DBUitility.cs 프로젝트: yuyuzeze/Site
 public static bool DataExist(string name)
 {
     string sql = "select COUNT(0) from Demo where name=@name";
     SQLiteDBHelper db = new SQLiteDBHelper(dbPath);
     SQLiteParameter[] parameters = new SQLiteParameter[] { new SQLiteParameter("@name", SqliteEscape(name)) };
     int result = int.Parse(db.ExecuteScalar(sql, parameters).ToString());
     return result > 0;
 }
예제 #3
0
 public void SetInvoiceTitle()
 {
     try
     {
         string sql   = @"select Title from FromERPDetail LIMIT 1";
         object title = db.ExecuteScalar(sql, null);
         this.lblInvoiceTitle.Text = title.ToString();
     }
     catch (Exception ex)
     {
     }
 }
예제 #4
0
 /// <summary>
 /// 插入一条数据,返回插入的序号
 /// </summary>
 /// <param name="name">用户名</param>
 /// <param name="email">Email地址</param>
 /// <returns>序号ID</returns>
 public static int Insert(string name, string email)
 {
     try
     {
         StringBuilder strSQL = new StringBuilder();
         strSQL.AppendFormat("INSERT INTO user(name,email) VALUES ('{0}','{1}')", name, email);
         SQLiteDBHelper sqliteDB = new SQLiteDBHelper();
         return Convert.ToInt32(sqliteDB.ExecuteScalar(strSQL.ToString()));
     }
     catch(Exception e)
     {
         return 0;
     }
 }
예제 #5
0
        /// <summary>
        /// 增加书源
        /// </summary>
        /// <param name="bookSource">书源内容</param>
        /// <returns>返回结果</returns>
        public static bool SourceAdd(BookSource bookSource)
        {
            //增加之前先判断是否已经存在该书源

            int count = Convert.ToInt32(SQLiteDBHelper.ExecuteScalar("select count(*) as count from BookSource where Url='" + bookSource.Url + "' or Title='" + bookSource.Title + "'", "count"));

            if (count > 0)
            {
                return(false);
            }


            string sql = "INSERT INTO BookSource('Title','Url','SearchUrl','AddressRangeRegular','AddressCuttingRegular','AddressRegular','BookNameRegular','AuthorRegular','UpdateRegular','NewestRegular','DetailsRegular','StateRegular','DirectoryScopeRegular','DirectoryCuttingRegular','DirectoryTieleRegular','DirectoryUrlRegular','ContentTitleRegular','ContentRegular','ImageRegular','State') VALUES('" + bookSource.Title + "', '" + bookSource.Url + "', '" + bookSource.SearchUrl + "', '" + bookSource.AddressRangeRegular + "', '" + bookSource.AddressCuttingRegular + "', '" + bookSource.AddressRegular + "','" + bookSource.BookNameRegular + "', '" + bookSource.AuthorRegular + "', '" + bookSource.UpdateRegular + "', '" + bookSource.NewestRegular + "', '" + bookSource.DetailsRegular + "', '" + bookSource.StateRegular + "', '" + bookSource.DirectoryScopeRegular + "', '" + bookSource.DirectoryCuttingRegular + "', '" + bookSource.DirectoryTieleRegular + "', '" + bookSource.DirectoryUrlRegular + "', '" + bookSource.ContentTitleRegular + "', '" + bookSource.ContentRegular + "', '" + bookSource.ImageRegular + "'," + bookSource.State + ")";

            TempData.UpdateBookSourceS();

            return((SQLiteDBHelper.ExecuteNonQuery(sql, null) <= 0) ? false : true);
        }
예제 #6
0
        /// <summary>
        /// 将Flow数据写入至数据库
        /// </summary>
        /// <param name="f">Flow对象</param>
        public static void WriteDataByFlow(Flow f)
        {
            // 1 : 判断该程序是否存在数据库中  Y:下一步 N:新建
            // 2 :查看今天是否存在该PID。     Y:更新  N:新建
            //Flow f = (Flow)de.Value;
            string sql;
            string now = DateTime.Now.ToString("yyyy-MM-dd");
            long   up, down;

            sql = string.Format("select pid from program where name='{0}' AND path='{1}';", f.name, f.path);
            object id = db.ExecuteScalar(sql, null);

            if (id == null)
            {
                sql = string.Format("insert into program (name,path,describe) values ('{0}','{1}','{2}');", f.name, f.path, f.describe);
                db.ExecuteNonQuery(sql, null);
                id = db.ExecuteScalar("select MAX(pid) from program;", null);
            }

            sql = string.Format("select COUNT(*) from flow where pid={0} AND note_date='{1}';", id, now);
            // 如果不存在今天的程序流量
            if (Convert.ToInt32(db.ExecuteScalar(sql, null)) == 0)
            {
                // 则插入
                sql = string.Format("insert into flow (pid,flow_up,flow_down,note_date) values ({0},{1},{2},'{3}');", id, f.up, f.down, now);
                db.ExecuteNonQuery(sql, null);
            }
            else
            {
                sql = string.Format("select * from flow where pid={0} AND note_date='{1}';", id, now);
                DataRow dr = db.ExecuteDataTable(sql, null).Rows[0];
                up          = (long)dr["flow_up"];
                down        = (long)dr["flow_down"];
                up         += f.up - f.note_up;
                down       += f.down - f.note_down;
                f.note_up   = f.up;
                f.note_down = f.down;
                sql         = string.Format("update flow set flow_up={0}, flow_down={1} where pid={2} AND note_date='{3}';", up, down, id, now);
                db.ExecuteNonQuery(sql, null);
            }
        }
예제 #7
0
        /// <summary>
        /// 书架中是否存在该书籍
        /// </summary>
        /// <param name="BookName">书籍名称</param>
        /// <returns>返回查询结果</returns>
        public static bool BoolBookAdd(string BookName)
        {
            string Sql = "select count(*) as 次数 from Books where Name='" + BookName + "'";

            return((Convert.ToInt32(SQLiteDBHelper.ExecuteScalar(Sql, "次数")) > 0) ? true : false);
        }
예제 #8
0
        /// <summary>
        /// 纯盘篇提交
        /// </summary>
        /// <param name="code">编号</param>
        /// <param name="dic">标记的参数</param>
        /// <param name="TempDic">临时存储参数,用于提交成功后保存db</param>
        /// <param name="Work_Path">工作路径</param>
        public void ChunPan_Submit(object code, Dictionary <string, object> dic, Dictionary <string, string> TempDic, string Work_Path)
        {
            Register  reg      = new Register();
            string    Ini_Path = reg.ReadRegeditKey("QueuePath", "software\\CNKI\\Assistant\\Work\\", Register.RegDomain.CurrentUser).ToString();
            INIManage ini      = new INIManage(Ini_Path);

            MatchTask task = null;

            foreach (string strValue in ini.SectionValues("Task"))
            {
                string    strTask = strValue.Substring(strValue.IndexOf('=') + 1);
                MatchTask mt      = strTask.FromJson <MatchTask>();
                if (mt.TaskStatus == "0")
                {
                    task = mt;
                    break;
                }
            }
            TextLog.WritwLog("提交code" + task.Code);

            string filename = Work_Path + "\\Explain.xml";
            string unit     = XDocument.Load(filename).Element("ExplainInfo").Element("Info").Value;

            #region 生成提交信息的xml的Content字段

            SendTask sTask = new SendTask();
            sTask.code        = task.Code;
            sTask.ArticleCode = code.ToString();
            sTask.Units       = unit;
            sTask.Year        = dic["学位年度"] == null ? "" : dic["学位年度"].ToString();
            sTask.Level       = dic["级别"] == null ? "" : dic["级别"].ToString();
            sTask.IsSecret    = dic["保密"].ToString();
            sTask.IsSQ        = dic["授权"].ToString();
            sTask.IsQM        = dic["签名"].ToString();
            sTask.Iscopyright = dic["版权反馈"].ToString();
            sTask.Explain     = dic["备注"] == null ? "" : dic["备注"].ToString();
            sTask.DeleteWords = dic["删除字样"].ToString();
            sTask.DelayDate   = dic["滞后上网"].ToString();

            DataRow row = sqlite.ExecuteDataTable("select 小样数,提取页数 from XW_FileOrderinfo where 编号='" + code + "'", null).Rows[0];
            sTask.XiaoYangSum = Convert.ToInt32(row["小样数"]);
            sTask.TotalPage   = Convert.ToInt32(row["提取页数"]);

            sTask.Cutf       = "否";
            sTask.HardCoverf = "否";

            sTask.TaskComeTime = task.TaskComeTime;
            sTask.IsRead       = "";
            sTask.ProcMode     = task.ProcMode;
            sTask.SchoolName   = "";
            sTask.PaperSummary = "";
            sTask.ProductCode  = task.ProductCode;
            sTask.PostName     = "文件整理";

            string strSendTask = sTask.ToJson();

            string sql = string.Format("update XW_FileOrderinfo set 年度='{0}',级别='{1}',保密否='{2}',版权反馈否='{3}',是否签名='{4}',是否授权='{5}',备注='{6}',删除字样='{7}',滞后上网='{8}' where 编号='{9}'",
                                       sTask.Year, sTask.Level, sTask.IsSecret, sTask.Iscopyright, sTask.IsQM, sTask.IsSQ, sTask.Explain, sTask.DeleteWords, sTask.DelayDate, code);
            sqlite.ExecuteNonQuery(sql, null);
            TextLog.WritwLog("执行sql成功:" + sql);

            XDocument newdoc           = new XDocument();
            XElement  node_root        = new XElement("ArticleInfo");
            XElement  node_code        = new XElement("SN");
            XElement  node_articleCode = new XElement("ArticleCode");
            XElement  node_content     = new XElement("CONTENT");
            node_code.Value        = code.ToString();
            node_articleCode.Value = code.ToString();
            node_content.Value     = strSendTask;
            node_root.Add(node_code, node_articleCode, node_content);
            newdoc.Add(node_root);
            if (!Directory.Exists(Work_Path + "\\ArticlePublish"))
            {
                Directory.CreateDirectory(Work_Path + "\\ArticlePublish");
            }
            newdoc.Save(Work_Path + "\\ArticlePublish\\" + code + ".xml");
            //保存参数,用于在篇提交成功后更新db
            if (TempDic.Keys.Contains(code.ToString()))
            {
                TempDic.Remove(code.ToString());
            }
            TextLog.WritwLog("添加编号:" + code);
            TempDic.Add(code.ToString(), "是");
            string dics = "";
            foreach (string key in TempDic.Keys)
            {
                dics += key + "-";
            }
            TextLog.WritwLog("添加后字典里:" + dics);

            Console.WriteLine(code + ":生成提交信息的xml成功");

            #endregion

            int    c0         = Convert.ToInt32(sqlite.ExecuteScalar("select count(*) from db_File where 编号 ='" + code + "'", null));
            string uploadPath = Work_Path + "\\ArticleUpload";
            if (!Directory.Exists(Work_Path + "\\ArticleUpload\\" + code))
            {
                #region 移动篇提交文件至ArticleUpload文件夹
                string tempPath = sqlite.ExecuteScalar("select 路径 from XW_FileOrderinfo where 编号='" + code + "'", null).ToString();

                #region 验证'整理后'文件夹中的文件个数和db中是否一样

                int c1 = Traverse(tempPath);
                if (c0 != c1)
                {
                    TextLog.WritwLog(code + ":整理后文件夹中文件个数(" + c1 + ")与db中文件个数(" + c0 + ")不一致");
                    MessageBox.Show(code + ":整理后文件夹中文件个数(" + c1 + ")与db中文件个数(" + c0 + ")不一致,请联系研发!");
                    return;
                }
                #endregion

                DirectoryInfo dir = new DirectoryInfo(tempPath);

                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                if (!Directory.Exists(uploadPath + "\\" + code))
                {
                    Directory.Move(tempPath, uploadPath + "\\" + code);
                }
                Console.WriteLine(code + ":移动篇提交文件至ArticleUpload文件夹成功");
                #endregion
            }

            #region 验证upload文件夹中的文件个数和db中是否一样
            int c2 = Traverse(uploadPath + "\\" + code);
            if (c0 != c2)
            {
                TextLog.WritwLog(code + ":articleupload文件夹中文件个数(" + c2 + ")与db中文件个数(" + c0 + ")不一致");
                MessageBox.Show(code + ":articleupload文件夹中文件个数(" + c2 + ")与db中文件个数(" + c0 + ")不一致,请联系研发!");
                return;
            }
            #endregion

            #region 给加工助手发送udp进行篇提交
            Console.WriteLine(code + ":开始篇提交");

            //UdpServer udpServer =UdpServer.GetInstance();
            string transport_WorkPath = task.WorkPath.Replace("\\", "\\\\");
            string message            = "{\"ArticleCode\":\"" + code + "\"," + "\"Code\":\"" + task.Code + "\"," + "\"LineId\":\"" + task.LineID + "\"," + "\"PostId\":\"" + task.PostID + "\"," +
                                        "\"TaskComeTime\":\"" + task.TaskComeTime + "\"," + "\"WorkPath\":\"" + transport_WorkPath + "\"}";
            try
            {
                Byte[] sendBytes = Encoding.Default.GetBytes(message);
                PublicTool.localUdp.Send(sendBytes, sendBytes.Length, remotePoint);
                TextLog.WritwLog(message);
                //listView2.Items[code.ToString()].SubItems[1].Text = "提交中";
            }
            catch (Exception ss)
            {
                TextLog.WritwLog(code + "发送udp失败:" + ss.Message);
            }


            #endregion
        }