public bool SignBook_Update(SignBookEntity entity) { try { string sql = " UPDATE M_SignBook SET Company='{0}',Department='{1}',Position='{2}',Email='{3}' WHERE SignID='{4}' "; sql = string.Format(sql, entity.Company, entity.Department, entity.Position, entity.Email, entity.SignID); return(int.Parse(SQlHelper.ExecuteNonQuery(SQlHelper.MyConnectStr, CommandType.Text, sql).ToString()) > 0); } catch (Exception ex) { LogUtil.WriteLog(ex); return(true); } }
public bool SignBook_Insert(SignBookEntity entity) { bool isSuccess = false; SqlTransaction trans = null; string sql = string.Empty; sql += " INSERT INTO M_SignBook(Customer,Moblie,Company,Department,Position,LuckyNumber,IsSign,Remarks,CustomerKey,SalesName,SignURL,SalesDepartment,CreateTime,Email) "; sql += " VALUES(@Customer,@Moblie,@Company,@Department,@Position,@LuckyNumber,@IsSign,@Remarks,@CustomerKey,@SalesName,@SignURL,@SalesDepartment,@CreateTime,@Email)"; SqlParameter[] prms = { new SqlParameter("@Customer", SqlDbType.NVarChar, 128), new SqlParameter("@Moblie", SqlDbType.NVarChar, 64), new SqlParameter("@Company", SqlDbType.NVarChar, 128), new SqlParameter("@Department", SqlDbType.NVarChar, 64), new SqlParameter("@Position", SqlDbType.NVarChar, 64), new SqlParameter("@LuckyNumber", SqlDbType.NVarChar, 20), new SqlParameter("@IsSign", SqlDbType.Int), new SqlParameter("@Remarks", SqlDbType.NVarChar, 256), new SqlParameter("@CustomerKey", SqlDbType.NVarChar, 128), new SqlParameter("@SalesName", SqlDbType.NVarChar, 64), new SqlParameter("@SignURL", SqlDbType.NVarChar, 256), new SqlParameter("@SalesDepartment", SqlDbType.NVarChar, 64), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@Email", SqlDbType.NVarChar, 256), }; prms[0].Value = entity.Customer; prms[1].Value = entity.Moblie; prms[2].Value = entity.Company; prms[3].Value = entity.Department; prms[4].Value = entity.Position; prms[5].Value = entity.LuckyNumber; prms[6].Value = entity.IsSign; prms[7].Value = entity.Remarks; prms[8].Value = entity.CustomerKey; prms[9].Value = entity.SalesName; prms[10].Value = entity.SignURL; prms[11].Value = entity.SalesDepartment; prms[12].Value = entity.CreateTime; prms[13].Value = entity.Email; try { using (SqlConnection conn = new SqlConnection(SQlHelper.MyConnectStr)) { conn.Open(); trans = conn.BeginTransaction(); SQlHelper.ExecuteScalar(trans, CommandType.Text, sql, prms); isSuccess = true; trans.Commit(); } } catch (Exception ex) { if (trans != null) { trans.Rollback(); } LogUtil.WriteLog(ex); return(false); } return(isSuccess); }
public bool SignBook_Update(SignBookEntity entity) { return(dao.SignBook_Update(entity)); }
public bool SignBook_Insert(SignBookEntity entity) { return(dao.SignBook_Insert(entity)); }
public string Import(HttpContext context)//导入数据 { try { UploadImageHelper uploadBll = new UploadImageHelper(); context.Response.ContentType = "text/plain"; HttpPostedFile file = context.Request.Files["Filedata"]; string fileName = file.FileName; //string tempPath = AppDomain.CurrentDomain.BaseDirectory + "/UploadFile/" + "SignBook/"; //设置二维码临时位置 string tempPath = HttpContext.Current.Server.MapPath("~/UploadFile/SignBook/"); //创建目录 if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } fileName = System.IO.Path.GetFileName(fileName); //获取文件名(不带路径) string currFileExtension = System.IO.Path.GetExtension(fileName); //获取文件的扩展名 string currFilePath = tempPath + fileName; //获取上传后的文件路径 记录到前面声明的全局变量 file.SaveAs(currFilePath); //保存临时文件 DataTable dt = ExcelToDataTable(fileName, currFilePath); for (int r = dt.Rows.Count - 1; r >= 0; r--) { DataRow row = dt.Rows[r]; if (row["姓名"].ToString().Trim() == "") { row.Delete(); } } dt.AcceptChanges(); //查询数据库中电话是否存在 string existMoblie = string.Empty; IList <SignBookEntity> entityList = BCtrl_SignBook.Instance.SignBook_GetALL(); foreach (var item in entityList) { string moblie = item.Moblie; foreach (DataRow item2 in dt.Rows) { string moblie2 = item2["手机"].ToString(); if (moblie.Trim() == moblie2.Trim()) { existMoblie += moblie + ","; } } } if (!string.IsNullOrEmpty(existMoblie)) { if (existMoblie.EndsWith(",")) { existMoblie = existMoblie.Substring(0, existMoblie.Length - 1); return("false_" + existMoblie); } } //入库 foreach (DataRow item in dt.Rows) { SignBookEntity entity = new SignBookEntity(); entity.Customer = item["姓名"].ToString().Trim(); entity.Moblie = item["手机"].ToString().Trim().Replace(Environment.NewLine, ""); entity.Moblie = entity.Moblie.Replace("\n", "").Replace("\r", ""); entity.Company = item["单位"].ToString(); entity.Department = item["部门"].ToString(); entity.Position = item["职位"].ToString(); entity.Email = item["邮箱"].ToString(); entity.SalesName = item["业务对接人"].ToString(); entity.SignURL = item["部门"].ToString(); entity.CustomerKey = MD5.Fun_MD5(entity.Moblie); entity.LuckyNumber = GetLuckyNumber(); entity.CreateTime = DateTime.Now; entity.IsSign = 0; //二维码 string strName = Guid.NewGuid().ToString("N") + ".png"; Bitmap image = Create_ImgCode(entity.CustomerKey, 15); SaveImg(strName, tempPath, image); //七牛 uploadBll.UpLoadImage(tempPath + "/" + strName, out strName, true); entity.SignURL = uploadBll.QiniuDomain + strName; BCtrl_SignBook.Instance.SignBook_Insert(entity); } File.Delete(currFilePath); return("true"); } catch { return("false"); } }