protected void btnSubmit_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(Globals.ConnectionString))
            {
                string password = this.txtPassword.Text;
                string newpassword = this.txtNewPassword.Text;
                string newpassword2 = this.txtNewPassword2.Text;

                //string password_md5 = CommonBLL.GetMD5Password(password);

                CommonDAL cdal = new CommonDAL(conn);

                string dPassword = "";
                dPassword = cdal.GetFieldValueStringBySQL("select UserPassWord  from Server_D_UserInfor where UserName='******'", "UserPassWord");


                if (password.Equals(dPassword))
                {
                    //string newpassword_md5 = CommonBLL.GetMD5Password(newpassword);
                    string sql = "update Server_D_UserInfor set UserPassWord='******' where UserName='******' " ;
                    cdal.ExecSQL(sql);
                    GetSuccessMsg("密码已更新" );
                    return;
                }
                else
                {
                    GetSuccessMsg("原密码不正确" );
                    return;
                }
            }
        }
Beispiel #2
0
        //返回权限
        public int CheckLogin(string username, string password)
        {
            using (SqlConnection conn = new SqlConnection(Globals.ConnectionString))
            {
                //string password_md5 = CommonBLL.GetMD5Password(password);
                //get user password
                CommonDAL cdal = new CommonDAL(conn);
                DataRow dr = cdal.GetDR("select * from Server_D_UserInfor where UserName='******' ");


                if (null == dr) return -1;
                
                if (dr["UserPassWord"].Equals(password))
                {
                    //get total right value 
                    //get totalrightvalue ,isnull(dbo.f_GetUserTotalRightValue(id),0) as totalrightvalue
                    string sql = "select isnull(dbo.f_GetUserTotalRightValue('"+username+"'),0) as totalrightvalue ";
                    int totalrightvalue = Functions.ParseInt(cdal.GetFieldValueStringBySQL(sql, "totalrightvalue"), 0);
                    return totalrightvalue;
                }
                else
                {
                    return -2;
                }

          
            }

        }
Beispiel #3
0
 //BindSysResCheckBoxList(cblProblems,"res_fileproblems","name","name")
 public void BindSysResCheckBoxList(System.Web.UI.WebControls.CheckBoxList cbl,string tablename,string fieldv,string fieldt)
 {
     CommonDAL commonDAL = new CommonDAL(conn);
     string sql = "select * from " + tablename + " ";
     DataSet ds = commonDAL.GetDS(sql);
     cbl.DataSource = ds;
     cbl.DataTextField = fieldt;
     cbl.DataValueField = fieldv;
     cbl.DataBind();
 }
Beispiel #4
0
        //outin status同时修改 in(生效) out(发布)
        public bool BatchSetIn2Out(string driverids, string username, out string msg)
        {

            using (SqlConnection conn = new SqlConnection(Globals.ConnectionString))
            {
                CommonDAL cdal = new CommonDAL(conn);
                if (driverids.EndsWith(",")) driverids += "0";
                string sql = "select distinct outin from Server_D_Drivers where id in (" + driverids + ")";
                DataSet ds = cdal.GetDS(sql);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    msg = "Driver信息不存在!";
                    return false;
                }
                if (ds.Tables[0].Rows.Count != 1)
                {
                    msg = "Driver的内外状态不一致,请重新选择!";
                    return false;
                }
                string outin = Functions.CleanDBString(ds.Tables[0].Rows[0]["outin"]);
                if (! outin.Equals( Convert.ToInt32(DriverOutIn.Driver_OutIn_InYan).ToString() ) )
                {
                    msg = "Driver的内外状态不为[内验]无法设置为[外],请重新选择!";
                    return false;
                }
                sql = "update Server_D_Drivers set outin=" + Convert.ToInt32(DriverOutIn.Driver_OutIn_Out)
                    + " , status=" + Convert.ToInt32(DriverStatus.Driver_Status_Published) + " "
                    + " , activetime=getdate() " //2016-3-8 发布时间,影响到外网显示
                    + " , ApproveTime=getdate() "
                    + " , ApproveBy='" + username + "' "
                    + " , lastupdatetime=getdate() "
                    + " , lastupdateby='" + username + "' "
                    + " where id in (" + driverids + ") ";
                //log
                /* saveDataLog "8012",strSameSysIdList(i),"驱动管理模块","审批否决:"&strDriverNameNewTemp,"补充说明:"&request("ApproveMemo"),strTempStatusN,"1","",session("UserName")
                 * saveDataLog(ModuleID,SourceID,ActionModule,ActionName,Remark,DataStatus,ISStatusLog,ISNew,User)
                 * strSQL="insert into Server_D_Log(LogType,IPAddress,UserName,Remark,ActionName,ActionModule,ModuleID,SourceID,DataStatus,ISStatusLog,FromID) 
                 * values('业务日志','"&Session("_LogUserIPAddress")&"','"&User &"','"&Remark&"','"&ActionName&"','"&ActionModule&"','"&ModuleID&"','"&SourceID&"','"&DataStatus&"','"&ISStatusLog&"','"&FromID&"')"
                 * IPAddress = Functions.ParseStr(Session["_LogUserIPAddress"]);
                 */
                //IPAddress暂时未用,所以先标定为0.0.0.0
                //string IPAddress = Functions.ParseStr(Session["_LogUserIPAddress"]);
                string IPAddress = "0.0.0.0";
                //FromID暂时未用,所以先标定为0
                sql += " insert into Server_D_Log(LogType,IPAddress,UserName,Remark,ActionName,ActionModule,ModuleID,SourceID,DataStatus,ISStatusLog,FromID)  "
                    + "select '业务日志', '" + IPAddress + "','" + username + "','补充说明:批量外传内' ,'批量外传内','驱动管理模块','8012',id,'已发布','1','0'"
                    + "  from Server_D_Drivers where id in (" + driverids + ")  ";
                cdal.ExecSQL(sql);

                msg = "";
                return true;

            }

        }
Beispiel #5
0
        protected void btnOK_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(Globals.ConnectionString))
            {
                CommonDAL cdal = new CommonDAL(conn);
                //初始密码1234509876
                //string password_md5 = CommonBLL.GetMD5Password("1234509876");
                string password = txtPassword.Text;//"123456";
                string username = txtUsername.Text;

                int userid = Functions.ParseInt(ViewState["userid"], 0);
                string sql = "";
                if (userid == 0)
                { //add
                    sql = "select count(*) as cnt from Server_D_UserInfor where username ='******' ";
                    int cnt = Functions.ParseInt(cdal.GetFieldValueStringBySQL(sql, "cnt"), 0);
                    if (cnt > 0) {
                        GetErrMsg("用户名已存在请重新选择.");
                        return;
                    }

                    sql = " declare @username nvarchar(20) set @username='******' ";
                    sql += " insert into [Server_D_UserInfor](username,userpassword,currentstate) values( @username,'" + password + "','ON' ) ";
                    //sql += " declare @userid int set @userid=@@identity ";
                    foreach (ListItem li in cblRoles.Items)
                    {
                        if (li.Selected)    //表示某一项被选中了 
                        {
                            sql += " insert into user_role(username,roleid) values(@username," + li.Value + ") ";
                        }
                    }
                }
                else 
                { //edit
                    sql = " declare @username nvarchar(20) set @username='******' ";
                    /* 不允许修改用户名,只允许修改权限;
                    sql += " if not exists ( select * from [Server_D_UserInfor] where username=@username and id<>" + userid + " ) "
                    + " begin update [Server_D_UserInfor] set username=@username where id=" + userid + " end ";
                    */
                    //修改密码
                    sql += " update Server_D_UserInfor set userpassword='******' where username=@username ";
                    sql += " delete from user_role where username=@username ";
                    foreach (ListItem li in cblRoles.Items)
                    {
                        if (li.Selected)    //表示某一项被选中了 
                        {
                            sql += " insert into user_role(username ,roleid) values(@username," + li.Value + ") ";
                        }
                    }
                }
                cdal.ExecSQL(sql);
                GetSuccessMsg("保存成功!", "userlist.aspx");
            }

        }
Beispiel #6
0
        protected void btnOK_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(Globals.ConnectionString))
            {
                CommonDAL cdal = new CommonDAL(conn);
              
                string rolename = txtRolename.Text;
                string remark = txtRemark.Text;

                int roleid = Functions.ParseInt(ViewState["roleid"], 0);
                string sql = "";
                if (roleid == 0)
                { //add
                    sql = "select count(*) as cnt from [role] where [name] ='" + rolename + "' ";
                    int cnt = Functions.ParseInt(cdal.GetFieldValueStringBySQL(sql, "cnt"), 0);
                    if (cnt > 0) {
                        GetErrMsg("角色名已存在请重新选择.");
                        return;
                    }

                    sql = " declare @rolename nvarchar(20) set @rolename='" + rolename + "' ";
                    sql += " insert into [role](name,remark) values( @rolename,'" + remark + "' ) ";
                    sql += " declare @roleid int set @roleid=@@identity ";
                    foreach (ListItem li in cblRights.Items)
                    {
                        if (li.Selected)    //表示某一项被选中了 
                        {
                            sql += " insert into role_right(roleid,rightid) values(@roleid," + li.Value + ") ";
                        }
                    }
                }
                else
                { //edit
                    sql = " declare @rolename nvarchar(20) set @rolename='" + rolename + "' ";
                    sql += " declare @roleid int set @roleid=" + roleid + " ";

                    sql += " if not exists ( select * from [role] where [name]=@rolename and id<>@roleid ) "
                    + " begin update [role] set [name]=@rolename where id=@roleid end ";
                    
                    sql += " delete from role_right where roleid=@roleid ";
                    foreach (ListItem li in cblRights.Items)
                    {
                        if (li.Selected)    //表示某一项被选中了 
                        {
                            sql += " insert into role_right(roleid,rightid) values(@roleid," + li.Value + ") ";
                        }
                    }
                }
                cdal.ExecSQL(sql);
                GetSuccessMsg("保存成功!", "rolelist.aspx");
            }

        }
Beispiel #7
0
        public bool IsUsernameExist(string username)
        {

            using (SqlConnection conn = new SqlConnection(Globals.ConnectionString))
            {
                CommonDAL cdal = new CommonDAL(conn);
                DataRow dr = cdal.GetDR("select * from Server_D_UserInfor where UserName='******' ");
                if (dr != null) return true;
                return false;
            }

        }
        private void MonitorFolder() {
            //get appsettings
            m_MonitorFolder = Functions.GetAppConfigString("MonitorFolder", "")+@"\";
            m_MonitorFolder = m_MonitorFolder.Replace(@"\\",@"\");
            m_DestFolderRoot = Functions.GetAppConfigString("DestFolderRoot", "") + @"\";  // /DriverFilesUploadFloder/ 对应这个url的物理路径    `
            m_MonitorInterval = Functions.GetAppConfigInt("MonitorInterval", 1000); //default 1000ms


            log.Info(logPrefix + "conf.connStr:" + connString);
            log.Info(logPrefix + "begin to monitor folder [" + m_MonitorFolder + "], interval [" + m_MonitorInterval + "] ms, dest [" + m_DestFolderRoot + "]");

            using (SqlConnection conn = new SqlConnection(connString))
            {
                CommonDAL cdal = new CommonDAL(conn);


                #region test
                //test
                /*
                            string res = "";
                            //string res = GetFileCode(@"com.kissmett.Common.dll", "md5");

                            res = GetFileCode(@"c:\ws\lnv\post\git\lnv.post\des\ServerDriverDB.ndm", "md5");
                            log.Info(logPrefix+"file md5 res:" + res);

                            res = GetFileCode(@"c:\ws\lnv\post\git\lnv.post\des\ServerDriverDB.ndm", "sha1");
                            log.Info(logPrefix+"file sha1 res:" + res);

                            res = GetFileCode(@"c:\ws\lnv\post\git\lnv.post\des\ServerDriverDB.ndm", "sha256");
                            log.Info(logPrefix+"file sha256 res:" + res);
                */
                #endregion

                //monitoring - dead loop   

                while (true)
                {
                    DirectoryInfo TheFolder = new DirectoryInfo(m_MonitorFolder);

                    ProcFolder(conn, cdal, TheFolder);



                    Thread.Sleep(m_MonitorInterval);
                    //log.Info("Sleep [" + m_MonitorInterval + "] ms;");
                }
            }
        
        }
Beispiel #9
0
 void CheckUsernameExist()
 {
     using (SqlConnection conn = new SqlConnection(Globals.ConnectionString))
     {
         CommonDAL commonDAL = new CommonDAL(conn);
         string username = Functions.ParseStr(Request["username"], "");
         string sql = "select * from person where username='******'";
         DataSet ds1 = commonDAL.GetDS(sql);
         string res = "0";
         if (ds1.Tables[0].Rows.Count > 0)
         {
             res = "1";
         }
         ltRes.Text = res;
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            string filename = Functions.ParseStr(Request["filename"], "");

            using (SqlConnection conn = new SqlConnection(Globals.ConnectionString)) {

                CommonDAL cdal = new CommonDAL(conn);
                string sql = " select count(*) as cnt from driversfiles where filename='" + filename + "' ";

                int cnt = Functions.ParseInt(cdal.GetFieldValueStringBySQL(sql, "cnt"), 0);

                sql = " select count(*) as cnt from Server_D_DriversFiles where filename='" + filename + "' ";

                int cnt0 = Functions.ParseInt(cdal.GetFieldValueStringBySQL(sql, "cnt"), 0);

                Response.Write(cnt+cnt0);
            
            
            }

        }
Beispiel #11
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(Globals.ConnectionString))
            {
                string password = this.txtPassword.Text;
                string newpassword = this.txtNewPassword.Text;
                string newpassword2 = this.txtNewPassword2.Text;

                string password_md5 = CommonBLL.GetMD5Password(password);

                //if (!newpassword.Equals(newpassword2)) {
                //    GetSuccessMsg("两次输入新密码不一致.");
                //    return;
                //}

                PersonDAL personDAL = new PersonDAL(conn);
                DataRow person = personDAL.GetAPerson(personid);

                CommonDAL dal = new CommonDAL(conn);

                if (password_md5.Equals(Functions.CleanDBString(person["password"])))
                {
                    string newpassword_md5 = CommonBLL.GetMD5Password(newpassword);
                    string sql = "update person set password='******',passworduserchanged=1 where id='" + personid+"'";
                    dal.ExecSQL(sql);
                    Session["person.passworduserchanged"] = 1;
                    GetSuccessMsg("密码已更新", "../index.aspx");
                    return;
                }
                else
                {
                    GetSuccessMsg("原密码不正确");
                    return;
                }
            }
        }
Beispiel #12
0
        /*
        public static void OutputXlsFile(XmlGrid objList, string excelFilePath)
        {


            //get sql
            string sql = objList.Sql;
            //Response.Write(sql + "<br>");

            //get xmlgrid cols
            DataGridColumnCollection cols = objList.Columns;
            Dictionary<string, string> colsdic = new Dictionary<string, string>(); //field,title
            for (int i = 0; i < cols.Count; i++)
            {
                DataGridColumn col = cols[i];
                if (col is XmlGridColumn)
                {
                    XmlGridHyperLinkColumn c = (XmlGridHyperLinkColumn)col;
                    //Response.Write(i+":"+c.DataTextField + ";" + c.DataTextFieldAlias +";"+c.HeaderText+ "<br>");
                    //3:f_processapplyintime_f; CONVERT(varchar(12), f.processapplyintime, 23) 
                    colsdic.Add(c.DataTextField, c.HeaderText);
                }
            }

            DataSet ds = CommonDAL.GetDS(sql);
            System.Data.DataTable dt = ds.Tables[0];

            //ApplicationClass xlsApp = new ApplicationClass(); 
            Application xlsApp = new Application();
            xlsApp.Visible = false;
            //Workbook workbook = xlsApp.Workbooks.Open(excelFilePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            Workbook workbook = xlsApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
            try
            {
                Worksheet mySheet = workbook.Sheets[1] as Worksheet;
                mySheet.Name = "output";


                object[,] objData = new object[dt.Rows.Count + 1, colsdic.Count];

                int xlsrow = 0;
                int xlscol = 0;
                foreach (KeyValuePair<string, string> it in colsdic)
                {
                    //mySheet.Cells[xlsrow, xlscol] = it.Value;
                    objData[xlsrow, xlscol] = it.Value;
                    xlscol++;
                }
                xlsrow++;


                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    xlscol = 0;
                    foreach (KeyValuePair<string, string> it in colsdic)
                    {
                        //mySheet.Cells[xlsrow, xlscol] = dt.Rows[i][it.Key];
                        objData[xlsrow, xlscol] = dt.Rows[i][it.Key];
                        xlscol++;

                    }
                    xlsrow++;

                }


                // 写入Excel 
                Range range;
                range = mySheet.get_Range(xlsApp.Cells[1, 1], xlsApp.Cells[dt.Rows.Count + 1, colsdic.Count]);
                //range.NumberFormat = "@";//设置单元格为文本格式
                range.Value2 = objData;


                workbook.Saved = true;
                workbook.SaveCopyAs(excelFilePath);


            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {
                workbook.Close(true, Type.Missing, Type.Missing);
                workbook = null;
                xlsApp.Quit();
                xlsApp = null;
            }


        }
         */

        public static void OutputCsvFile(SqlConnection conn, XmlGrid objList, string csvFilePath)
        {

            string content=""; 

            //get sql
            string sql = objList.Sql;
            //Response.Write(sql + "<br>");

            //get xmlgrid cols
            DataGridColumnCollection cols = objList.Columns;
            Dictionary<string, string> colsdic = new Dictionary<string, string>(); //field,title
            for (int i = 0; i < cols.Count; i++)
            {
                DataGridColumn col = cols[i];
                if (col is XmlGridColumn)
                {
                    XmlGridHyperLinkColumn c = (XmlGridHyperLinkColumn)col;
                    //Response.Write(i+":"+c.DataTextField + ";" + c.DataTextFieldAlias +";"+c.HeaderText+ "<br>");
                    //3:f_processapplyintime_f; CONVERT(varchar(12), f.processapplyintime, 23) 
                    colsdic.Add(c.DataTextField, c.HeaderText);
                }
            }
            CommonDAL commonDAL = new CommonDAL(conn);
            DataSet ds = commonDAL.GetDS(sql);
            System.Data.DataTable dt = ds.Tables[0];


           
            foreach (KeyValuePair<string, string> it in colsdic)
            {
                //mySheet.Cells[xlsrow, xlscol] = it.Value;
                content +=it.Value +"," ;                   
                     
            }
            content +="\r\n";



            for (int i = 0; i < dt.Rows.Count; i++)
            {
                    
                foreach (KeyValuePair<string, string> it in colsdic)
                {
                    //mySheet.Cells[xlsrow, xlscol] = dt.Rows[i][it.Key];
                    content += dt.Rows[i][it.Key]+",";
                        

                }
                content +="\r\n";
                     

            }

            //save
            FileStream fs = new FileStream(csvFilePath, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs, Encoding.Default);
            sw.Write(content);
            sw.Close();
            fs.Close();


        }
Beispiel #13
0
        void BindData(SqlConnection conn)
        {
            CommonDAL cdal = new CommonDAL(conn);
            string sql = "select * from [role] ";
            DataSet ds = cdal.GetDS(sql);
            cblRoles.DataSource = ds;
            cblRoles.DataTextField = "name";
            cblRoles.DataValueField = "id";
            cblRoles.DataBind();

            int userid = Functions.ParseInt(ViewState["userid"], 0);
            if (userid != 0)
            {
                DataSet ds0 = cdal.GetDS(" select * from user_role where username in (select username from Server_D_UserInfor where id=" + userid + ") ");
                CommonBLL.BindCheckBoxListValues(cblRoles, ds0, "roleid");

                DataSet ds1 = cdal.GetDS("select * from [Server_D_UserInfor] where id=" + userid);
                txtUsername.Text = ds1.Tables[0].Rows[0]["username"].ToString();
                txtPassword.Text = ds1.Tables[0].Rows[0]["userpassword"].ToString();
                txtPassword2.Text = ds1.Tables[0].Rows[0]["userpassword"].ToString();
            }
           
        }
Beispiel #14
0
 public CorpPersonDAL(SqlConnection conn)
 {
     this.conn = conn;
     commonDAL = new CommonDAL(conn);
 }
Beispiel #15
0
        void BindData(SqlConnection conn)
        {
            CommonDAL cdal = new CommonDAL(conn);
            string sql = "select * from [right] ";
            DataSet ds = cdal.GetDS(sql);
            cblRights.DataSource = ds;
            cblRights.DataTextField = "name";
            cblRights.DataValueField = "id";
            cblRights.DataBind();

            int roleid = Functions.ParseInt(ViewState["roleid"], 0);
            if (roleid != 0)
            {
                DataSet ds0 = cdal.GetDS(" select * from role_right where roleid=" + roleid + " ");
                CommonBLL.BindCheckBoxListValues(cblRights, ds0, "rightid");
                DataSet ds1 = cdal.GetDS("select * from [role] where id=" + roleid);
                txtRolename.Text = ds1.Tables[0].Rows[0]["name"].ToString();
            }
           
        }
Beispiel #16
0
 public SysRightDAL(SqlConnection conn)
 {
     this.conn = conn;
     this.commonDAL = new CommonDAL(conn);
 }
        // db-->ui
        private void DataFromDBToUI( )
        {
            if (PersonID.Equals("")) return;

            //PersonDAL pd = new PersonDAL(_conn);
            //DataRow p = pd.GetAPerson(PersonID);
            string sql = string.Format(_fieldsInfo.SQL, PersonID);//sql 中含有一个变量'{0}'
            CommonDAL cd = new CommonDAL(_conn);
            DataRow p = cd.GetDR(sql);

            //循环界面的ui元素
            for (int x = 0; x < FieldsHolderTable.Rows.Count; x++)
            {
                TableRow row = FieldsHolderTable.Rows[x];

                TextBox tb = (TextBox)row.Cells[1].Controls[0];
                string fieldName = tb.ID.Substring(4);
                string dbfield = _fieldsInfo.GetItem(fieldName).DBField;
                if (dbfield.Equals("")) continue;
                tb.Text = Functions.ParseStr(p[dbfield]);

            }
        }
        //递归处理文件夹
        private void ProcFolder(SqlConnection conn, CommonDAL cdal, DirectoryInfo TheFolder)
        {
            //避开 dup 文件夹
            string dupfolder = m_MonitorFolder + "dup";
            log.Info(logPrefix + "ProcFolder[" + TheFolder.FullName + "]");
            
            if (TheFolder.FullName.ToLower().Equals(dupfolder))
            {
                log.Info(logPrefix + "避开dup文件夹");
                return;
            }


          
            //procfiles
            foreach (FileInfo NextFile in TheFolder.GetFiles())
            {
                ProcFile(conn, cdal, NextFile);

            }//for each fileinfo

            foreach (DirectoryInfo NextFolder in TheFolder.GetDirectories())
            {               
                //NextFolder.FullName是某个子目录的绝对地址
                ProcFolder(conn, cdal,  NextFolder);//递归 
            }
        }
        private void ProcFile(SqlConnection conn, CommonDAL cdal , FileInfo NextFile)
        {
            log.Info(logPrefix + "ProcFolder[" + NextFile.Name + "]");

            //any files in the m folder:
            //1.mv to dest;
            //2.calc md5/sha1/sha265
            string destdir = "", relpath = "", dupdir = "";
            string srcfilename = "", destfilename = "";
            long filesize = 0;
            string fileext = "";
            string md5 = "", sha1 = "", sha256 = "";
            string sql = "";

            try
            {
                srcfilename = NextFile.FullName;

                ////db中是否已经存在该文件名DriversFiles 和 Server_D_DriversFiles(老数据)
                //sql = "select count(*) as cnt from DriversFiles where [FileName]='" + NextFile.Name + "'";
                //int cnt = Functions.ParseInt(cdal.GetFieldValueStringBySQL(sql, "cnt"), 0);
                //sql = "select count(*) as cnt from Server_D_DriversFiles where [FileName]='" + NextFile.Name + "'";
                //int cnt0 = Functions.ParseInt(cdal.GetFieldValueStringBySQL(sql, "cnt"), 0);
                //log.Info(logPrefix + "db已存在FileName[" + NextFile.Name + "]数量(新):" + cnt + ";(老):" + cnt0);
                //if (cnt + cnt0 > 0)

                //2016-3-8 修改为后入为主的策略,Server_D_DriversFiles 存在于此就修改此表,DriversFiles 存在于此就修改此表,否则就新加到DriversFiles ;
                sql = "select * from Server_D_DriversFiles where [FileName]='" + NextFile.Name + "'";
                DataSet dsOld = cdal.GetDS(sql);
                sql = "select * from DriversFiles where [FileName]='" + NextFile.Name + "'";
                DataSet dsNew = cdal.GetDS(sql);

                if (dsOld.Tables[0].Rows.Count > 0) //存在于 Server_D_DriversFiles
                {
                    log.Info(logPrefix + "File[" + NextFile.Name + "] 存在于Server_D_DriversFiles;");
                    #region 先入为主的策略 (否决)
                    ////若存在记录,则忽略该记录,move to dup dir记录日志;
                    ////move to dupdir
                    //log.Info(logPrefix + "FileName[" + NextFile.Name + "] Has Existed in System and Will Be Moved to dup!");
                    //dupdir = m_MonitorFolder + @"\dup\";
                    //if (!Directory.Exists(dupdir)) Directory.CreateDirectory(dupdir);
                    //File.Move(srcfilename, dupdir + NextFile.Name);

                    ////continue;
                    //return;
                    #endregion


                    relpath = ""; // 2016030811223308096/
                    string F_Path = dsOld.Tables[0].Rows[0]["F_Path"].ToString(); // /DriverFilesUploadFloder/server/2008101712345610916/3008ESASHBAREDHATAS40X86.exe
                    if (!F_Path.StartsWith("/DriverFilesUploadFloder/server/")) {
                        log.Error(logPrefix + "db.Server_D_DriversFiles.F_Path[" + F_Path + "] not begin with /DriverFilesUploadFloder/server/,无法处理此文件. ");
                        return;                        
                    }
                    string[] arrF_Path = F_Path.Split("/".ToCharArray());
                    if (arrF_Path.Length < 4) {
                        log.Error(logPrefix + "db.Server_D_DriversFiles.F_Path[" + F_Path + "] 格式错误,少于4段. ");
                        return;    
                    }
                    relpath = arrF_Path[arrF_Path.Length - 2];
                    log.Info(logPrefix + "get relpath [" + relpath + "] from db. ");

                    //创建目标目录
                    destdir = m_DestFolderRoot + "/" + relpath;
                    log.Info(logPrefix + "创建目标目录:" + destdir);
                    if (!Directory.Exists(destdir)) Directory.CreateDirectory(destdir);

                    destfilename = destdir + NextFile.Name;

                    //move file to dest
                    if (File.Exists(destfilename)) File.Delete(destfilename);
                    File.Move(srcfilename, destfilename);
                    log.Info(logPrefix + "File[" + srcfilename + "] move to Dest;");

                    //get filesize
                    filesize = NextFile.Length;
                    log.Info(logPrefix + "Dest File[" + destfilename + "];filesieze:[" + filesize + "];");
                    if (NextFile.Extension.Length > 1)
                        fileext = NextFile.Extension.Substring(1, NextFile.Extension.Length - 1);

                    //get filecodes
                    md5 = GetFileCode(destfilename, "md5");
                    sha1 = GetFileCode(destfilename, "sha1");
                    sha256 = GetFileCode(destfilename, "sha256");
                    log.Info(logPrefix + "Dest File[" + destfilename + "];Calc==> md5:[" + md5 + "],sha1:[" + sha1 + "],sha256:[" + sha256 + "];");

                    //update to db Server_D_DriversFiles
                    sql = " update Server_D_DriversFiles set md5='" + md5 + "', sha1='" + sha1 + "', sha256='" + sha256 + "',uploadtime=getdate() where FileName='" + NextFile.Name + "'";
                    cdal.ExecSQL(sql);
                    log.Info(logPrefix + "update 1 table Server_D_DriversFiles ;");


                }
                else if (dsNew.Tables[0].Rows.Count > 0) //存在于 DriversFiles
                {
                    log.Info(logPrefix + "File[" + NextFile.Name + "] 存在于DriversFiles;");

                    relpath = ""; // 2016030811223308096/
                    string F_Path = dsNew.Tables[0].Rows[0]["F_Path"].ToString(); // /DriverFilesUploadFloder/server/2008101712345610916/3008ESASHBAREDHATAS40X86.exe
                    if (!F_Path.StartsWith("/DriverFilesUploadFloder/server/"))
                    {
                        log.Error(logPrefix + "db.DriversFiles.F_Path[" + F_Path + "] not begin with /DriverFilesUploadFloder/server/,无法处理此文件. ");
                        return;
                    }
                    string[] arrF_Path = F_Path.Split("/".ToCharArray());
                    if (arrF_Path.Length < 4)
                    {
                        log.Error(logPrefix + "db.DriversFiles.F_Path[" + F_Path + "] 格式错误,少于4段. ");
                        return;
                    }
                    relpath = arrF_Path[arrF_Path.Length - 2];
                    log.Info(logPrefix + "get relpath [" + relpath + "] from db. ");

                    //创建目标目录
                    destdir = m_DestFolderRoot + "/" + relpath;
                    log.Info(logPrefix + "创建目标目录:" + destdir);
                    if (!Directory.Exists(destdir)) Directory.CreateDirectory(destdir);

                    destfilename = destdir + NextFile.Name;

                    //move file to dest
                    if (File.Exists(destfilename)) File.Delete(destfilename);
                    File.Move(srcfilename, destfilename);
                    log.Info(logPrefix + "File[" + srcfilename + "] move to Dest;");

                    //get filesize
                    filesize = NextFile.Length;
                    log.Info(logPrefix + "Dest File[" + destfilename + "];filesieze:[" + filesize + "];");
                    if (NextFile.Extension.Length > 1)
                        fileext = NextFile.Extension.Substring(1, NextFile.Extension.Length - 1);

                    //get filecodes
                    md5 = GetFileCode(destfilename, "md5");
                    sha1 = GetFileCode(destfilename, "sha1");
                    sha256 = GetFileCode(destfilename, "sha256");
                    log.Info(logPrefix + "Dest File[" + destfilename + "];Calc==> md5:[" + md5 + "],sha1:[" + sha1 + "],sha256:[" + sha256 + "];");

                    //update to db DriversFiles and Server_D_DriversFiles
                    sql = " update DriversFiles set md5='" + md5 + "', sha1='" + sha1 + "', sha256='" + sha256 + "',uploadtime=getdate(),F_OldPath='"+srcfilename+"' where FileName='" + NextFile.Name + "'";
                    sql = sql + " update Server_D_DriversFiles set md5='" + md5 + "', sha1='" + sha1 + "', sha256='" + sha256 + "',uploadtime=getdate() where FileName='" + NextFile.Name + "'";
                    cdal.ExecSQL(sql);
                    log.Info(logPrefix + "update 2 tables DriversFiles and Server_D_DriversFiles ;");
                }
                else
                {
                    relpath = (new Random()).Next(99999).ToString().PadLeft(5, '0') + "/"; // 08096/
                    relpath = DateTime.Now.ToString("yyyyMMddHHmmss") + relpath; // 2016030811223308096/

                    //创建目标目录
                    destdir = m_DestFolderRoot + "/" + relpath;
                    log.Info(logPrefix + "创建目标目录:" + destdir);
                    if (!Directory.Exists(destdir)) Directory.CreateDirectory(destdir);

                    destfilename = destdir + NextFile.Name;

                    //move file to dest
                    //若文件还在上传中是否会引起一个异常退出?tbd
                    if (File.Exists(destfilename)) File.Delete(destfilename);
                    File.Move(srcfilename, destfilename);
                    log.Info(logPrefix + "File[" + srcfilename + "] move to Dest;");

                    //get filesize
                    filesize = NextFile.Length;
                    log.Info(logPrefix + "Dest File[" + destfilename + "];filesieze:[" + filesize + "];");
                    if (NextFile.Extension.Length > 1)
                        fileext = NextFile.Extension.Substring(1, NextFile.Extension.Length - 1);

                    //get filecodes
                    md5 = GetFileCode(destfilename, "md5");
                    sha1 = GetFileCode(destfilename, "sha1");
                    sha256 = GetFileCode(destfilename, "sha256");
                    log.Info(logPrefix + "Dest File[" + destfilename + "];Calc==> md5:[" + md5 + "],sha1:[" + sha1 + "],sha256:[" + sha256 + "];");

                    //rec to db DriversFiles
                    /*
                         
                    [FileName] [varchar](500) NOT NULL,
                    [NFileName] [varchar](500) NOT NULL,
                    [FileExt] [varchar](50) NULL,
                    [FileType] [varchar](200) NULL,
                    [FileSize] [numeric](18, 0) NULL,
                    [ISDriver] [varchar](1) NULL,
                    [UploadBy] [varchar](200) NULL,
                    [UploadTime] [datetime] NULL,
                    [F_Path] [varchar](2000) NULL,
                    [F_DownloadTimes] [int] NULL,
                    [F_URL] [varchar](500) NULL,
                    [F_OldPath] [varchar](500) NULL,
                    [FormatFileSize] [numeric](18, 2) NULL,
                    [md5] [nvarchar](100) NULL,
                    [sha1] [nvarchar](100) NULL,
                    [sha256] [nvarchar](100) NULL,
                         
                     */

                    MyDBTable t = new MyDBTable(conn, "select * from DriversFiles");//可以得到自增id,前提:select 全部数据
                    //DataRow dr = t.Table.NewRow();
                    DataRow dr = t.NewRow();

                    dr["FileName"] = NextFile.Name;
                    dr["NFileName"] = NextFile.Name;
                    dr["FileExt"] = fileext;
                    dr["FileType"] = dr["FileExt"];
                    dr["FileSize"] = filesize;
                    dr["ISDriver"] = "1"; // ???
                    dr["UploadBy"] = "administrator";//tbd...
                    dr["UploadTime"] = DateTime.Now;
                    dr["F_Path"] = "/DriverFilesUploadFloder/server/" + relpath + NextFile.Name; // /DriverFilesUploadFloder/server/2008101712345610916/3008ESASHBAREDHATAS40X86.exe
                    dr["F_DownloadTimes"] = 0;
                    dr["F_URL"] = "http://driverdl.lenovo.com.cn/lenovo";
                    dr["F_OldPath"] = srcfilename;// ""; // E:\3008ESASHBAREDHATAS40X86.exe //2016-4-7 用作存 源头目录
                    dr["FormatFileSize"] = filesize / 1024;
                    dr["md5"] = md5;
                    dr["sha1"] = sha1;
                    dr["sha256"] = sha256;

                    //t.Table.Rows.Add(dr);
                    t.AddRow(dr);// ==> t.Rows.Add(dr);
                    t.Update();

                    log.Info(logPrefix + "Dest File[" + destfilename + "];Rec in DB;");


                }//if 存在与否


            }
            catch (IOException ioe)
            {
                log.Error(logPrefix + "Proc File IOError:" + ioe.ToString());
                //@20160327
                //这个错误将发生在move过程;若此时source还没有完全落地,将会被另一个进程占用(ftp),但此时已经建立了destdir需要删掉;
                if (Directory.Exists(destdir)) Directory.Delete(destdir);
            }
            catch (Exception e)
            {
                log.Error(logPrefix + "Proc File Error:" + e.ToString());
            }
        }
Beispiel #20
0
 public TempletDAL(SqlConnection conn)
 {
     this.conn = conn;
     //this.da = new SqlDataAdapter("select * from person where 1=0", this.conn);
     commonDAL = new CommonDAL(conn);
 }
Beispiel #21
0
 public DriversFiles(SqlConnection conn)
 {
     this.conn = conn;
     commonDAL = new CommonDAL(conn); 
 }