数据库备份
WEB备份方法
WEB客户端备份
/// <summary> /// 备份数据库 /// </summary> /// <param name="context"></param> void BackupDb(HttpContext context) { string []dbnames = ConfigHelper.GetValue("backupDB").Split(','); string backupName = StringHelper.CreateIDCode(); string savePath = context.Server.MapPath("~/App_Data/DBBAK/"); foreach (string dbname in dbnames) { backupName = dbname +"_"+ DateTime.Now.ToString().Replace(":", "").Replace(" ", "").Replace("-", "").Replace("/", ""); string backupSql = " BACKUP DATABASE {0} to DISK ='{1}' ";//DUMP TRANSACTION {0} WITH NO_LOG; backupSql = string.Format(backupSql, dbname, savePath + backupName + ".bak"); try { //执行备份 Acesoft.Common.Data.DbUtils.ExecuteNonQuery(backupSql, null); //addZipEntry(backupName, savePath);//压缩备份?有问题 //写入操作日志 LogBll<object> log = new LogBll<object>(); log.AddLog("备份数据库", "数据库备份成功,文件名:" + backupName + ".bak"); context.Response.Write(new JsonMessage { Data = "1", Message = "数据库备份成功。", Success = true }.ToString()); } catch (Exception ex) { context.Response.Write(new JsonMessage { Data = "1", Message = ex.StackTrace, Success = false }.ToString()); } } }
web客户端删除备份
1 //删除备份文件 2 void DeleteFile(HttpContext context) 3 { 4 string basepath = context.Server.MapPath("~/App_Data/DBBAK/"); 5 string filename = context.Request["n"].ToString(); 6 string downpath = basepath + filename; 7 File.Delete(downpath); 8 9 //写入操作日志 10 LogBll<object> log = new LogBll<object>(); 11 log.AddLog("删除备份文件", "数据库备份文件删除成功,文件名:" + filename); 12 13 context.Response.Write(new JsonMessage { Data = "1", Message = "删除成功。", Success = true }.ToString()); 14 context.Response.End(); 15 }
还原数据库文件
1 /// <summary> 2 /// 还原数据库 3 /// </summary> 4 /// <param name="context"></param> 5 void BackDb(HttpContext context) 6 { 7 string databasefile = context.Request["n"]; 8 string dbname = databasefile.Split('_')[0]; 9 string savePath = context.Server.MapPath("~/App_Data/DBBAK/"); 10 string RefreshDBsql = "use master;ALTER DATABASE " + dbname + " SET OFFLINE WITH ROLLBACK IMMEDIATE;"; 11 string BackSql = "RESTORE DATABASE {0} FROM DISK ='{1}' WITH REPLACE;";//还原指定的数据库文件 12 13 BackSql = string.Format(BackSql, dbname, savePath + databasefile); 14 try 15 { 16 string con = "Data Source=.;Integrated Security=true;DataBase=master"; 17 //执行关闭 18 Acesoft.Common.Data.DbUtils.ExecuteNonQuery(con,RefreshDBsql, null); 19 //执行还原 20 Acesoft.Common.Data.DbUtils.ExecuteNonQuery(con,BackSql, null); 21 22 //写入操作日志 23 LogBll<object> log = new LogBll<object>(); 24 try 25 { 26 log.AddLog("还原数据库", "数据库还原成功,文件名:" + databasefile); 27 } 28 catch { } 29 context.Response.Write(new JsonMessage { Data = "1", Message = "数据库还原成功。", Success = true }.ToString()); 30 } 31 catch (Exception ex) 32 { 33 context.Response.Write(new JsonMessage { Data = "1", Message = ex.StackTrace, Success = false }.ToString()); 34 } 35 }
下载备份文件
1 //下载备份文件 2 void DownloadFile(HttpContext context) 3 { 4 string basepath = context.Server.MapPath("~/App_Data/DBBAK/"); 5 string filename = context.Request["n"]; 6 string downpath = basepath + filename; 7 MemoryStream ms = null; 8 context.Response.ContentType = "application/octet-stream"; 9 10 context.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); 11 ms = new MemoryStream(File.ReadAllBytes(downpath)); 12 13 //写入操作日志 14 LogBll<object> log = new LogBll<object>(); 15 log.AddLog("下载备份数据库", "数据库备份文件下载,文件名:" + filename); 16 17 context.Response.Clear(); 18 context.Response.BinaryWrite(ms.ToArray()); 19 context.Response.End(); 20 }
获取备份文件列表
1 IEnumerable DbFiles() 2 { 3 string path = HttpContext.Current.Server.MapPath("~/App_Data/DBBAK/"); 4 DirectoryInfo di = new DirectoryInfo(path); 5 return from n in di.GetFiles() 6 orderby n.CreationTime descending 7 select 8 new 9 { 10 FileName = n.Name, 11 FileSize = ((float)n.Length / 1024 /1024).ToString("N3")+" M", 12 CreateDate = n.CreationTime.ToString("yyyy-MM-dd HH:mm:ss") 13 }; 14 }
压缩文件
1 /// <summary> 2 /// 压缩文件 3 /// </summary> 4 /// <param name="newZipFileName">新文件名</param> 5 /// <param name="savePath">保存路径</param> 6 public void addZipEntry(string newZipFileName,string savePath) 7 { 8 var newZipFullpath = savePath + newZipFileName; 9 10 FileStream zipfs = File.Create(newZipFullpath+".zip"); 11 ZipOutputStream zos = new ZipOutputStream(zipfs); 12 FileInfo fi = new FileInfo(newZipFullpath+".bak" ); 13 FileStream fs = File.OpenRead(fi.FullName); 14 byte[] buffer = new byte[fs.Length]; 15 fs.Read(buffer, 0, buffer.Length); 16 17 ZipEntry entry = new ZipEntry(newZipFileName+".zip"); 18 zos.PutNextEntry(entry); 19 zos.Write(buffer, 0, buffer.Length); 20 fs.Close(); 21 zos.Finish(); 22 zos.Close(); 23 }
服务端和客户端备份有点不一样,因为服务端的地址有些变化
服务端都采用的是自动备份的方法
1 using Acesoft.Common; 2 using System; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Timers; 6 using System.Web.Routing; 7 using System.Data; 8 using System.Web; 9 using System.IO; 10 using Acesoft.Core; 11 using Acesoft.Core.Bll; 12 using Acesoft.Core.Model; 13 using Acesoft.Common; 14 using System.Transactions; 15 namespace Web 16 { 17 public class MvcApplication : System.Web.HttpApplication 18 { 19 private System.Timers.Timer myTimer = null; 20 private System.Timers.Timer backTime = null; //数据库备份 21 private System.Timers.Timer wageTime = null; //工资自动扣款 22 23 24 protected void Application_Start() 25 { 26 //自动化任务,每天执行一次,提醒要扣工资了 27 myTimer = new System.Timers.Timer(24 * 60 * 60 * 1000); 28 myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed); 29 myTimer.Enabled = true; 30 myTimer.AutoReset = true; 31 32 //备份数据库 33 backTime = new System.Timers.Timer(1 * 60 * 1000); 34 backTime.Elapsed += new ElapsedEventHandler(BackupDb); 35 backTime.Enabled = true; 36 backTime.AutoReset = true; 37 //自动扣工资 38 wageTime = new System.Timers.Timer(24 * 60 * 60 * 1000); 39 wageTime.Elapsed += new ElapsedEventHandler(WageKou); 40 wageTime.Enabled = true; 41 wageTime.AutoReset = true; 42 43 } 44 45 private void myTimer_Elapsed(object source, ElapsedEventArgs e) 46 { 47 myTimer.Enabled = false; 48 try 49 { 50 if (DateTime.Now.Day != 15) 51 { 52 return; 53 } 54 BlueVacation.BLL.RetailSalesManager retailBll = new BlueVacation.BLL.RetailSalesManager(); 55 BlueVacation.BLL.BusinessManManager businessBll = new BlueVacation.BLL.BusinessManManager(); 56 BlueVacation.BLL.EmployeeManager empBll = new BlueVacation.BLL.EmployeeManager(); 57 BlueVacation.BLL.SalaryManager salaryBll = new BlueVacation.BLL.SalaryManager(); 58 BlueVacation.BLL.OnlineChatManager chatBll = new BlueVacation.BLL.OnlineChatManager(); 59 60 //DataSet ds = retailBll.GetModelList(" RetailSalesStatus = 1");//.GetAllList();//得到正在使用的每个自有门市 61 var modellist = retailBll.GetModelList(" State='启用'"); 62 string retailIdsNo = ""; 63 string retailIdsYes = ""; 64 65 for (int i = 0; i < modellist.Count; i++) //查询每个门市下面的员工ds.Tables[0].Rows.Count 66 { 67 68 var rid = modellist[i].RetailSalesId; //ds.Tables[0].Rows[i]["RetailSalesId"]; 69 DataSet empDs = empBll.GetList("RetailSalesId = " + modellist[i].RetailSalesId + " and AuditStatus=1");//查询出每个门市下面的在职员工 70 //再查询出每个员工是不是已经扣过最近三个月的工资 71 string empids = ""; 72 for (int j = 0; j < empDs.Tables[0].Rows.Count; j++) 73 { 74 //查询该员工最后一个月的工资情况, 75 BlueVacation.Model.Salary salary = salaryBll.GetModel("EmployeeId=" + empDs.Tables[0].Rows[j]["EmployeeId"] 76 + " and GrantDate =(select MAX(GrantDate) from salary where EmployeeId=" + empDs.Tables[0].Rows[j]["EmployeeId"] + ")"); 77 if (salary != null) //表示以前扣过 78 { 79 //如果最后一个月的月份小于当前月的月份就证明该名员工还没有扣这个月的工资 80 if (salary.GrantDate < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM"))) 81 { 82 empids += empDs.Tables[0].Rows[j]["EmployeeId"] + ","; 83 } 84 } 85 else //表示以前都没有扣过工资 86 { 87 empids += empDs.Tables[0].Rows[j]["EmployeeId"] + ","; 88 } 89 } 90 if (!string.IsNullOrEmpty(empids)) //证明这个门市下面有员工还没有发这最近几个月的工资 91 { 92 //记录这个门市的ID号,这个是这个门市还有没有发本月工资的员工 93 retailIdsYes += modellist[i].RetailSalesId + ","; 94 //给这个门市发送消息 95 BlueVacation.Model.OnlineChat messageModel = new BlueVacation.Model.OnlineChat(); 96 BlueVacation.Model.BusinessMan bussinessMan = businessBll.GetModel(" Role='经理' and RetailSalesId=" + modellist[i].RetailSalesId); 97 if (bussinessMan != null) 98 { 99 messageModel.BusinessManId = bussinessMan.BusinessManId; 100 messageModel.MessageTitle = DateTime.Now.ToString("yyyy年MM月") + "工资扣款提醒"; 101 messageModel.MessageType = 2; 102 messageModel.IsRead = false; 103 messageModel.PostDate = DateTime.Now; 104 messageModel.ExchangeInfo = "亲,您好!总社将在本月20日预扣您门市的员工工资,请留意您门市的余额,及时充值!<br/>如有任何问题您可以随时联系我们网站客服人员,或者拨打我们的客服电话:" + ConfigHelper.GetValue("servicephone") + "。"; 105 chatBll.Add(messageModel);//发给门市 106 } 107 } 108 else 109 { 110 //记录已经发过了这个月工资的门市id号 111 retailIdsNo += modellist[i].RetailSalesId + ","; 112 } 113 } 114 //if (!string.IsNullOrEmpty(retailIdsYes)) //要给这些门市发送消息 115 //{ 116 117 //} 118 119 120 } 121 catch { 122 myTimer.Enabled = true; 123 } 124 myTimer.Enabled = true; 125 } 126 127 private void BackupDb(object source,ElapsedEventArgs e) // (HttpContext context) 128 { 129 backTime.Enabled = false; 130 try 131 { 132 string[] dbnames = ConfigHelper.GetValue("backupDB").Split(','); 133 string backupName = StringHelper.CreateIDCode(); 134 //string savePath = Directory.GetDirectoryRoot("~/App_Data/DBBAK/");//Server.MapPath("~/App_Data/DBBAK/"); 135 string savePath = MapPath("/App_Data/DBBAK/"); 136 bool flag = Directory.Exists(savePath); 137 if (!flag) 138 { 139 Directory.CreateDirectory(savePath); 140 } 141 142 foreach (string dbname in dbnames) 143 { 144 backupName = dbname + "_" + DateTime.Now.ToString().Replace(":", "").Replace(" ", "").Replace("-", "").Replace("/", ""); 145 string backupSql = " BACKUP DATABASE {0} to DISK ='{1}' ";//DUMP TRANSACTION {0} WITH NO_LOG; 146 backupSql = string.Format(backupSql, dbname, savePath + backupName + ".bak"); 147 try 148 { 149 //执行备份 150 Acesoft.Common.Data.DbUtils.ExecuteNonQuery(backupSql, null); 151 //addZipEntry(backupName, savePath);//压缩备份?有问题 152 153 //写入操作日志 154 LogBll<object> log = new LogBll<object>(); 155 log.AddLog("备份数据库", "数据库备份成功,文件名:" + backupName + ".bak"); 156 157 //Context.Response.Write(new JsonMessage { Data = "1", Message = "数据库备份成功。", Success = true }.ToString()); 158 } 159 catch (Exception ex) 160 { 161 //Context.Response.Write(new JsonMessage { Data = "1", Message = ex.StackTrace, Success = false }.ToString()); 162 } 163 } 164 } 165 catch 166 { 167 backTime.Enabled = true; 168 } 169 backTime.Enabled = true; 170 } 171 172 /// <summary> 173 /// 每月20号自动扣工资,如果20号没有扣款成功的,于23号再扣一次 174 /// </summary> 175 /// <param name="source"></param> 176 /// <param name="e"></param> 177 private void WageKou(object source, ElapsedEventArgs e) 178 { 179 wageTime.Enabled = false; 180 try 181 { 182 if (DateTime.Now.Day != 20 || DateTime.Now.Day != 23) 183 { 184 return; 185 } 186 publicStoreDaiKou(); 187 } 188 catch 189 { 190 wageTime.Enabled = true; 191 } 192 wageTime.Enabled = true; 193 } 194 195 /// <summary> 196 /// 自动扣工资的方法 197 /// 以当前月为开始月份,向后扣3个月的工资, 198 /// </summary> 199 void publicStoreDaiKou() 200 { 201 DateTime temp = DateTime.Now; 202 string start = temp.Year.ToString() + "-" + temp.Month.ToString(); 203 string end = temp.Year.ToString() + "-" + (temp.Month + 3).ToString(); 204 DateTime startDate = Convert.ToDateTime(start + "-1"); //转换为时间 205 DateTime endDate = Convert.ToDateTime(end + "-1"); //转换为时间 206 207 int totalMonth = 3; // 设置月份差为3个月 208 209 /* 210 *1.根据所选门市查询出门市的信息 211 *2.根据门市的编号查询出这个门市下面的所有员工 212 * a.看每个员工是不是已经扣除了设置的这几个月的工资 213 * 1)如果已经扣除就跳过,查看下一个员工 214 * 2)如果没有扣除,记录该员工ID号,累加该员工的三个月工资总和 215 * b.把该门市的余额拿出来和记录的该门市员工工资的总和进行比较 216 * 1)如果余额不够,记录该门市ID号和门市名称,跳过比较下一门市 217 * 2)如果余额足够,也要记录门市ID号和门市名称,同时开始插入扣款数据 218 * 219 */ 220 BlueVacation.BLL.RetailSalesManager rsBll = new BlueVacation.BLL.RetailSalesManager(); 221 BlueVacation.BLL.EmployeeManager empBll = new BlueVacation.BLL.EmployeeManager(); 222 BlueVacation.BLL.SetEmployeeSalaryManager setSalaryBll = new BlueVacation.BLL.SetEmployeeSalaryManager(); 223 BlueVacation.BLL.SalaryManager salaryBll = new BlueVacation.BLL.SalaryManager(); 224 BlueVacation.BLL.BalanceOfWaterManager waterBll = new BlueVacation.BLL.BalanceOfWaterManager(); 225 BlueVacation.BLL.TimeBucketRecordManager trmBll = new BlueVacation.BLL.TimeBucketRecordManager(); 226 BlueVacation.BLL.PaymentManager payBll = new BlueVacation.BLL.PaymentManager(); 227 BlueVacation.BLL.OnlineChatManager chatbll = new BlueVacation.BLL.OnlineChatManager(); 228 BlueVacation.BLL.BusinessManManager bman = new BlueVacation.BLL.BusinessManManager(); 229 230 string suss_salesIds = "";//记录扣款成功门市的ID号 231 string suss_salesNames = null;//记录扣款成功门市的名称 232 string fail_salesIds = "";//记录扣款失败门市的ID号 233 string fail_salesNames = null;//记录扣款失败门市的名称 234 string null_salesNames = null; 235 using (TransactionScope scope = new TransactionScope()) 236 { 237 List<BlueVacation.Model.RetailSales> salesList = rsBll.GetModelList(" State='启用'");//查询所有门市的信息 238 foreach (var sales in salesList) //遍历查询出来的门市 239 { 240 string remark = null; 241 decimal tatolSalary = 0; //记录这个门市下面所有符合要求的员工的工资总和(三个月工资) 242 string empIds = null; 243 string succemplist = ""; 244 string failemplist = ""; 245 //查询这个门市下面的所有在职,并且已经通过审核,审核日期为开始设定日期月份的20号之前的员工 246 //查询这个门市下面的所有在当月20日之前通过审核离职的员工 247 List<BlueVacation.Model.Employee> empList = empBll.GetModelList(" RetailSalesId = " + sales.RetailSalesId + " and EmployeeStatus=1 and EntryAuditDate < convert(date,'" + start + "-20') and auditstatus=1 or LeaveAuditDate<convert(date,'" + start + "-20') and RetailSalesId = " + sales.RetailSalesId + " and EmployeeStatus=1 and auditstatus=0"); 248 249 //empBll.GetModelList(" AuditStatus=1 and EmployeeStatus=1 and RetailSalesId = " + sales.RetailSalesId + " and EntryAuditDate< convert(datetime,'" + start + "-20') and LeaveDate is null and LeaveAuditDate is null"); 250 251 foreach (var emp in empList) 252 { 253 string salaryWhere = " EmployeeId = " + emp.EmployeeId + " and GrantDate =(select MAX(GrantDate) from salary where EmployeeId=" + emp.EmployeeId + ")"; 254 BlueVacation.Model.Salary salary = salaryBll.GetModel(salaryWhere); //用员工ID号查询日期为最新日期的数据 255 BlueVacation.Model.SetEmployeeSalary setSalary = setSalaryBll.GetModel(" isuse=1 and SetEmployeeSalaryStatus=1 and EmployeeId=" + emp.EmployeeId);//得到这个员工所设置的工资数据 256 257 if (salary != null) //表示以前有过工资 258 { 259 DateTime grant = Convert.ToDateTime(salary.GrantDate); 260 //这里是看查到的最大月份是不是在这个设定时间内,如果是就跳到下一个,如果不是就插入数据 261 if (grant < startDate) 262 { 263 tatolSalary += setSalary.SalarySum * totalMonth; //累加工资(三个月的工资) 264 empIds += emp.EmployeeId + ","; //记录这个员工的ID号 265 succemplist += emp.FullName + ","; 266 }//end if 267 else 268 { 269 continue; 270 }//end else 271 }//end if (salary != null) 272 else //为空表示以还没有设置过这个员工的工资 273 { 274 if (setSalary != null) 275 { 276 //setSalary.SalarySum因在前面这个计算为实发工资,也就是员工正真拿到手的钱, 277 //而这里应发工资,也就是要扣除门市的钱,所以应该用setSalary.BaseWage 278 tatolSalary += setSalary.BaseWage * totalMonth; //累加工资(三个月的工资) 279 empIds += emp.EmployeeId + ","; //记录这个员工的ID号 280 succemplist += emp.FullName + ","; 281 } 282 }//end if (salary != null) else 283 }//end foreach (var emp in empList) 284 285 286 if (empIds != null && tatolSalary != 0) 287 { 288 //看这个门市的余额够不够发工资,够就开始扣款 289 if (sales.AmountAccounts >= tatolSalary) 290 { 291 BlueVacation.Model.BalanceOfWater zswater = new BlueVacation.Model.BalanceOfWater(); //用于总社收款记录流水 292 BlueVacation.Model.Payment payment = new BlueVacation.Model.Payment(); //用于记录流水帐 只记录一条数据 293 empIds = empIds.TrimEnd(',');//移除最后面的逗号 294 List<BlueVacation.Model.Employee> suss_empList = empBll.GetModelList(" EmployeeId in(" + empIds + ")");//得到这个门市下面所有可以扣款的员工 295 //Model.SetEmployeeSalary setSalary = setSalaryBll.GetModelByCache("isuse=1 and SetEmployeeSalaryStatus=1 and EmployeeId=" + employee.EmployeeId); 296 string empSalay = ""; 297 string paymentNumber = BlueVacation.BLL.PaymentManager.GetSerialNumber(false, 5); //流水号 298 foreach (var employee in suss_empList) 299 { 300 //1.减去这个员工所在门市的余额 操作表RetailSales 301 //2.记录这个流水账(门市为支出) 操作表BalanceOfWater 302 //3.向salary添加这个时间段的记录,一共要添加totalMonth这么多条,日期从startDate 到 endDate 303 //4.向TimeBucketRecord添加记录, 304 BlueVacation.Model.SetEmployeeSalary setSalary = setSalaryBll.GetModel("isuse=1 and SetEmployeeSalaryStatus=1 and EmployeeId=" + employee.EmployeeId); 305 for (int i = 0; i < totalMonth; i++) 306 { 307 //向salary插入新的数据,从开始日期到结束日期,有几个月就插入几条数据 308 BlueVacation.Model.Salary newSalary = new BlueVacation.Model.Salary(); 309 newSalary.EmployeeId = setSalary.EmployeeId; 310 newSalary.GrantDate = startDate.AddMonths(i); //这里记录是哪个月的工资 311 newSalary.BaseWage = setSalary.BaseWage; 312 newSalary.Deduction = setSalary.Deduction; 313 newSalary.Other = setSalary.Other; 314 newSalary.DaikouShebo = setSalary.DaikouShebao; 315 newSalary.DaikouYiBao = setSalary.DaikouYiBao; 316 newSalary.PersonalIncomeTax = setSalary.PersonalIncomeTax; 317 newSalary.AccruedWages = setSalary.BaseWage; 318 newSalary.RealWages = setSalary.SalarySum; 319 320 //以下部分可以不用 321 newSalary.FullAttendence = setSalary.FullAttendance; 322 newSalary.seniorityPay = setSalary.SeniorityPay; 323 newSalary.PensionInsurance = setSalary.PensionInsurance; 324 newSalary.TaxRate = setSalary.TaxRate; 325 newSalary.Subsidies = setSalary.Subsidies; 326 newSalary.PostAllowance = setSalary.PostAllowance; 327 newSalary.CommunicationAllowance = setSalary.CommunicationAllowance; 328 newSalary.TransportationAllowance = setSalary.TransportationAllowance; 329 newSalary.MealSupplement = setSalary.MealSupplement; 330 newSalary.TravelAllowance = setSalary.TravelAllowance; 331 newSalary.Performance = setSalary.Performance; 332 newSalary.DaikouGongjijin = setSalary.DaikouGongjijin; 333 newSalary.DaikouWuxian = setSalary.DaikouWuxian; 334 newSalary.DaikouShengyu = setSalary.DaikouShengyu; 335 newSalary.DaikouGongshang = setSalary.DaikouGongshang; 336 newSalary.DaikouShiye = setSalary.DaikouShiye; 337 338 salaryBll.Add(newSalary); 339 340 }//end for (int i = 0; i < totalMonth; i++) 341 //记录TimeBucketRecord工资代扣记录,第条记录都是三个月的 342 BlueVacation.Model.TimeBucketRecord tbr = new BlueVacation.Model.TimeBucketRecord(); 343 tbr.EmployeeId = setSalary.EmployeeId; 344 tbr.RetailSalesId = sales.RetailSalesId; 345 tbr.TimeBucket = start + "到" + end; 346 tbr.BaseWage = setSalary.BaseWage * totalMonth; 347 tbr.Deduction = setSalary.Deduction * totalMonth; 348 tbr.Other = setSalary.Other * totalMonth; 349 tbr.DaikouShebao = setSalary.DaikouShebao * totalMonth; 350 tbr.DaikouYibao = setSalary.DaikouYiBao * totalMonth; 351 tbr.PersonalIncomeTax = setSalary.PersonalIncomeTax * totalMonth; 352 tbr.SalarySum = setSalary.SalarySum * totalMonth; 353 //公式为:缴费金额-行政扣款-其它代付项-代扣养老失业-代扣医保-代扣个人所得税=实发工资 354 tbr.AccruedWages = tbr.BaseWage; 355 tbr.RealWages = tbr.SalarySum; 356 tbr.Bingding = paymentNumber; 357 //以下部分可以不用 358 tbr.FullAttendance = setSalary.FullAttendance * totalMonth; 359 tbr.PensionInsurance = setSalary.PensionInsurance * totalMonth; 360 tbr.TaxRate = setSalary.TaxRate * totalMonth; 361 tbr.Subsidies = setSalary.Subsidies * totalMonth; 362 tbr.SeniorityPay = setSalary.SeniorityPay * totalMonth; 363 tbr.PostAllowance = setSalary.PostAllowance * totalMonth; 364 tbr.CommunicationAllowance = setSalary.CommunicationAllowance * totalMonth; 365 tbr.TransportationAllowance = setSalary.TransportationAllowance * totalMonth; 366 tbr.MealSupplement = setSalary.MealSupplement * totalMonth; 367 tbr.TravelAllowance = setSalary.TravelAllowance * totalMonth; 368 tbr.Performance = setSalary.Performance * totalMonth; 369 tbr.DaikouWuxian = setSalary.DaikouWuxian * totalMonth; 370 tbr.DaikouShiye = setSalary.DaikouShiye * totalMonth; 371 tbr.DaikouShengyu = setSalary.DaikouShengyu * totalMonth; 372 tbr.DaikouGongshang = setSalary.DaikouGongshang * totalMonth; 373 tbr.DaikouGongjijin = setSalary.DaikouGongjijin * totalMonth; 374 375 //tbr.AccruedWages = tbr.BaseWage + tbr.FullAttendance + tbr.Subsidies + tbr.SeniorityPay 376 // + tbr.PostAllowance + tbr.CommunicationAllowance + tbr.TransportationAllowance + tbr.MealSupplement + tbr.TravelAllowance + tbr.Performance;//这里是应发totalMonth个月工资 377 //tbr.RealWages = tbr.AccruedWages - tbr.Deduction - tbr.PersonalIncomeTax - tbr.Other 378 // - tbr.DaikouGongjijin - tbr.DaikouGongshang - tbr.DaikouShebao - tbr.DaikouShengyu 379 // - tbr.DaikouShiye - tbr.DaikouWuxian - tbr.DaikouYibao - tbr.PensionInsurance;//这里是实发totalMonth个月工资 380 tbr.Department = setSalary.Department; 381 trmBll.Add(tbr); 382 383 remark += employee.FullName + ":" + start + "~" + end + ",工资" + (setSalary.BaseWage * totalMonth).ToString("C") + "元;"; 384 385 empSalay += employee.FullName + ":" + start + "~" + end + ",工资" + (setSalary.BaseWage * totalMonth).ToString("C") + "元;<br/>"; 386 387 }//end foreach (var employee in suss_empList) 388 sales.AmountAccounts = sales.AmountAccounts - tatolSalary; //修改所在门市的余额 389 rsBll.Update(sales);//门市余额修改 390 391 //记录流水账 392 BlueVacation.Model.BalanceOfWater bwater = new BlueVacation.Model.BalanceOfWater(); 393 //得到该门市流水帐上的余额 394 //BlueVacation.Model.BalanceOfWater oldwater = waterBll.GetModel(" ForNumber='" + sales.StoreNumber + "' order by BalanceOfWaterId desc"); 395 396 //门市支出流水账 397 bwater.BalanceDate = DateTime.Now; //收支日期 398 bwater.Spending = tatolSalary;//记录支出金额 399 //if (oldwater != null) 400 // bwater.Balance = oldwater.Balance - tatolSalary;//门市余额 401 //else 402 // bwater.Balance = tatolSalary * (-1); 403 bwater.Balance = sales.AmountAccounts; 404 bwater.BalanceNumber = paymentNumber; //流水号 405 bwater.Remark = remark + "总共" + tatolSalary.ToString("C") + "元," + DateTime.Now + "扣除";//备注信息 406 bwater.ForNumber = sales.StoreNumber;//门市编号 407 bwater.ForType = "门市"; 408 bwater.PayInfo = "员工工资"; 409 bwater.Budget = "工资"; 410 bwater.DocumentNumber = "员工工资"; 411 bwater.Approval = "系统";// SysVisitor.Instance.CurrentUser.TrueName;//得到操作人的名字 412 bwater.Operator = "系统";// SysVisitor.Instance.CurrentUser.TrueName;//得到操作人的名字 413 bwater.Banding = "0";// bwater.BalanceNumber;//这个我暂时不知道记录的是什么东西,所以把流水号拿过来了 414 bwater.BalanceOfWaterStatus = true; 415 waterBll.Add(bwater); //记录门市流水账 416 417 payment.LineId = 0; 418 payment.PeopleNumber = 0; 419 payment.PayDate = DateTime.Now; 420 payment.PayTime = DateTime.Now; 421 payment.ApplyDate = DateTime.Now; 422 payment.PayAmount = tatolSalary; 423 payment.StoreNumber = sales.StoreNumber; 424 payment.PayNumber = paymentNumber; 425 payment.Status = "总社";// "总社"; 426 payment.PayType = "收入";// "收入"; 427 payment.Company = sales.StoreName; 428 payment.PayObject = "总社行政人事部"; 429 payment.PayMethod = "银行转账"; 430 payment.Currency = "人民币"; 431 payment.AmountCapital = BlueVacation.Common.Rmb.CmycurD(tatolSalary); 432 payment.PayInfo = remark; //"门市账户转到总社账户"; 433 payment.PaySubject = "员工工资"; 434 payment.PaymentRemark = sales.StoreName + "的员工工资,具体如下:" + remark + "总计" + tatolSalary.ToString("C") + "元"; 435 payBll.Add(payment); 436 437 suss_salesIds += sales.RetailSalesId + ","; //记录扣款成功门市的ID号 438 suss_salesNames += sales.StoreName + ",";//记录扣款成功门市的NAME 439 440 441 BlueVacation.Model.BusinessMan man = bman.GetModel(" RetailSalesId=" + sales.RetailSalesId + " and Role='经理'"); 442 //发信息 443 BlueVacation.Model.OnlineChat nmodel = new BlueVacation.Model.OnlineChat(); 444 nmodel.MessageTitle = "成功预扣" + start + "~" + end + "工资"; 445 nmodel.BusinessManId = man.BusinessManId; 446 nmodel.ExchangeInfo = "您好,总社已经从门市余额中扣取" + tatolSalary.ToString("C") + "元,将为您门市员工发工资。本次扣款是预扣" + start + "~" + end + "的工资款。具体如下:<br/>" + empSalay + "<br/>请注意核实!您可以在<a href='/RetailSalesManage/TransactionQuery' target=_blank>交易查询</a>中查看相关记录。<br/>如有任何问题您可以随时联系我们网站客服人员,或者拨打我们的客服电话:" + ConfigHelper.GetValue("servicephone") + "。"; 447 nmodel.MessageType = 2; 448 nmodel.PostDate = DateTime.Now; 449 chatbll.Add(nmodel); 450 //发信息end 451 452 }//end if (sales.AmountAccounts >= tatolSalary) 453 else //门市余额不够,不能发员工的工资 454 { 455 fail_salesIds += sales.RetailSalesId + ",";//记录扣款失败门市的ID号 456 fail_salesNames += sales.StoreName + ",";//记录扣款失败门市的Name 457 458 459 BlueVacation.Model.BusinessMan man = bman.GetModel(" RetailSalesId=" + sales.RetailSalesId + " and Role='经理'"); 460 //发信息 461 BlueVacation.Model.OnlineChat nmodel = new BlueVacation.Model.OnlineChat(); 462 nmodel.MessageTitle = "预扣" + start + "~" + end + "工资失败"; 463 nmodel.BusinessManId = man.BusinessManId; 464 nmodel.ExchangeInfo = "您好,由于您门市<a href='/RetailSalesManage/Account' target=_blank>余额</a>不足,本次不能给员工" + succemplist.TrimEnd(',') + "预扣工资款。本次工资是从" + start + "~" + end + ",总额为:" + tatolSalary.ToString("C") + "元。为不影响员工的工资发放,请尽快<a href='/RetailSalesManage/DeltaIndex' target=_blank>充值</a>!<br/>如有任何问题您可以随时联系我们网站客服人员,或者拨打我们的客服电话:" + ConfigHelper.GetValue("servicephone") + "。"; 465 if (temp.Day == 20) 466 { 467 nmodel.ExchangeInfo = "您好,由于您门市<a href='/RetailSalesManage/Account' target=_blank>余额</a>不足,本次不能给员工" + succemplist.TrimEnd(',') + "预扣工资款。本次工资是从" + start + "~" + end + ",总额为:" + tatolSalary.ToString("C") + "元。为不影响员工的工资发放,请尽快<a href='/RetailSalesManage/DeltaIndex' target=_blank>充值</a>!<br/>将在本月23号再扣一次!<br/>如有任何问题您可以随时联系我们网站客服人员,或者拨打我们的客服电话:" + ConfigHelper.GetValue("servicephone") + "。"; 468 } 469 if (temp.Day == 23) 470 { 471 nmodel.ExchangeInfo = "您好,由于您门市<a href='/RetailSalesManage/Account' target=_blank>余额</a>不足,本次不能给员工" + succemplist.TrimEnd(',') + "预扣工资款。本次工资是从" + start + "~" + end + ",总额为:" + tatolSalary.ToString("C") + "元。本月的两次默认扣款时间已经过了, 为不影响员工的工资发放,请尽快<a href='/RetailSalesManage/DeltaIndex' target=_blank>充值</a>,请与总社联系!<br/>如有任何问题您可以随时联系我们网站客服人员,或者拨打我们的客服电话:" + ConfigHelper.GetValue("servicephone") + "。"; 472 } 473 nmodel.MessageType = 2; 474 nmodel.PostDate = DateTime.Now; 475 chatbll.Add(nmodel); 476 //发信息end 477 478 479 }// end if (sales.AmountAccounts >= tatolSalary) else 480 }//end if (empIds != null && totalMonth != 0) 481 else 482 { 483 //没有找到这个门市下面的员工 484 null_salesNames += sales.StoreName + ","; 485 } 486 487 }//end foreach (var sales in salesList) 488 scope.Complete(); 489 }//end using (TransactionScope scope = new TransactionScope()) 490 //string mesg = null; 491 492 //if (suss_salesNames != null) 493 // mesg = suss_salesNames.TrimEnd(',') + "扣款成功;\n"; 494 //if (fail_salesNames != null) 495 // mesg += fail_salesNames.TrimEnd(',') + "余额不足,扣款失败"; 496 //if (null_salesNames != null) 497 // mesg += null_salesNames.TrimEnd(',') + "下面没有找到要扣款的员工"; 498 499 //return mesg; 500 } 501 502 public static string MapPath(string strPath) 503 { 504 if (HttpContext.Current != null) 505 { 506 return HttpContext.Current.Server.MapPath(strPath); 507 } 508 else //非web程序引用 509 { 510 strPath = strPath.Replace("/", "\\"); 511 if (strPath.StartsWith("\\")) 512 { 513 //strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\'); 514 strPath = strPath.TrimStart('\\'); 515 } 516 return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath); 517 } 518 } 519 520 521 } 522 }