protected void DoUpload() { try { HttpPostedFile file = file1.PostedFile; DateTime dateTime = DateTime.Now; string fileName = dateTime.ToString("yyyyMMddhhmmssffff"); if (!Directory.Exists(WebHelper.GetAttachmentTempPath())) { Directory.CreateDirectory(WebHelper.GetAttachmentTempPath()); } string fullName = WebHelper.GetAttachmentTempPath() + "/" + fileName; string strNewPath = fullName + WebHelper.GetExtension(file.FileName); string savepath = fileName + WebHelper.GetExtension(file.FileName); file.SaveAs(strNewPath); BasAttachmentInfo att = new BasAttachmentInfo(); att.PhysicalPath = strNewPath; att.FileNo = fileName; att.OriginalName = Path.GetFileName(file.FileName); att.FriendlyKey = "N/A"; att.ExtensionName = WebHelper.GetExtension(file.FileName); att.FileName = fileName + att.ExtensionName; att.FullPath = "../../Uploads" + "/" + fileName + WebHelper.GetExtension(file.FileName); att.FileType = 0; att.UpdatedDate = DateTime.Now; att.UpdatedBy = WebHelper.GetUserInfo().UserCode; PubHelper.GetHelper(WebHelper.GetDB(WebHelper.GetUserInfo())).SaveAttachment(att); if (SaveToDB(strNewPath, savepath)) { Label1.Text = "上传完毕"; } WriteJs("uploadsuccess('" + att.FileNo + "','" + att.OriginalName + "','" + att.FullPath + "'); "); } catch { WriteJs("uploaderror();"); } }
protected bool SaveToDB(string path, string tablename) { try { DataTable dt = ExcelManage.InputFromExcel(path, tablename); if (dt != null && dt.Rows.Count > 0) { WsSystem wbi = new WsSystem(); for (int i = 0; i < dt.Rows.Count; i++) { if (!string.IsNullOrEmpty(dt.Rows[i][0].ToString())) { PartsdrawingCode bb = new PartsdrawingCode(); bb.ID = PubHelper.GetHelper().GetNextID("MES_MASTER.SEQ_ALL_ID").ToString(); bb.PartsCode = dt.Rows[i][0].ToString(); bb.CustName = dt.Rows[i][1].ToString(); bb.CustCode = dt.Rows[i][2].ToString(); bb.ProductName = dt.Rows[i][3].ToString(); bb.ProductCode = dt.Rows[i][4].ToString(); bb.PlanQuantity = Convert.ToDecimal(dt.Rows[i][5].ToString()); bb.QualityCode = dt.Rows[i][6].ToString(); bb.AskQuantity = Convert.ToDecimal(dt.Rows[i][7].ToString()); bb.BatchNumber = dt.Rows[i][8].ToString(); bb.AskDate = Convert.ToDateTime(dt.Rows[i][9].ToString()); bb.ACTIVE = "1"; wbi.SavePartsDrawing(bb); } } return(true); } else { Label1.Text = "上传完毕,但数据为空,保存失败"; } return(true); } catch (Exception ex) { Label1.Text = ex.ToString(); return(false); } }
public string Login(string userCode, string pwd, bool isRemember) { try { UserInfo userInfo = new UserInfo(); userInfo.UserCode = userCode; // userInfo.UserCode = userCode.ToUpper(); userInfo.Password = pwd; userInfo.IP = WebHelper.GetClientIPv4Address(); PubHelper.GetHelper(WebHelper.GetDB(userInfo)).DoLogin(userInfo); //userInfo.SiteName = PubHelper.GetHelper(WebHelper.GetDB(userInfo)).GetSiteName(userInfo.SiteCode); //userInfo.BUName = PubHelper.GetHelper(WebHelper.GetDB(userInfo)).GetBUName(userInfo.BUCode); //設置Session Session[WebConstants.S_SESS_USER] = userInfo; //寫入Cookie HttpCookie cookie = new HttpCookie("lang"); cookie.Expires = DateTime.Now.AddDays(1); // cookie.Value = userInfo.Lang; HttpContext.Current.Response.Cookies.Add(cookie); //设置Cookies if (isRemember) { System.Collections.Specialized.NameValueCollection myCol = new System.Collections.Specialized.NameValueCollection(); myCol.Add("name", userCode); myCol.Add("pwd", pwd); myCol.Add("ip", userInfo.IP); MES.Cookie.SetObj("mes_user", 60 * 60 * 15 * 1, myCol, "", "/"); } else { MES.Cookie.Del("mes_user"); } return("Main.aspx"); // 记录其IP地址,下次登录时验证,IP为空则记录,IP不为空则验证 //string uname = userCode; //string upwd = pwd; //if (uname.Equals("") || upwd.Equals("")) //{ // lblTip.Visible = true; // lblTip.Text = "请输入用户名或密码"; // return; //} //Response.Redirect("index.aspx"); //設置Session //Session["UserName"] = uname; //寫入Cookie //HttpCookie cookie = new HttpCookie("lang"); //cookie.Expires = DateTime.Now.AddDays(1); //cookie.Value = userInfo.Lang; //HttpContext.Current.Response.Cookies.Add(cookie); } catch (Exception ex) { throw ex; } }