/// <summary> /// 文件保存 /// 2017/6/13(zhuguanjun) /// </summary> /// <param name="entity"></param> /// <returns></returns> public JsonResult SaveFile(SubContractFiles entity) { JsonResult jsonreslut = new JsonResult(); try { string _id; if (string.IsNullOrEmpty(entity.ID)) { new Repository <SubContractFiles>().Insert(entity, true, out _id); } else { new Repository <SubContractFiles>().Update(entity, true, out _id); } jsonreslut.data = _id; jsonreslut.result = true; jsonreslut.msg = "保存成功!"; } catch (Exception ex) { LogHelper.WriteException(ex, LogType.BussinessDLL); jsonreslut.result = false; jsonreslut.msg = ex.Message; } return(jsonreslut); }
/// <summary> /// 其他附件编辑保存 /// 2017/06/13(zhuguanjun) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnFSave_Click(object sender, EventArgs e) { SubContractFiles entity = new SubContractFiles(); entity.ID = txtFName.Tag == null ? "" : txtFName.Tag.ToString(); entity.SubID = SubID; entity.Type = 0; entity.Path = txtFPath.Text; entity.Name = txtFName.Text; #region 填写判断 if (string.IsNullOrEmpty(entity.Path)) { MessageHelper.ShowMsg(MessageID.W000000002, MessageType.Alert, "附件"); return; } if (string.IsNullOrEmpty(entity.Name)) { MessageHelper.ShowMsg(MessageID.W000000002, MessageType.Alert, "附件名称"); return; } #endregion #region 文件上传 //判断是否有选择文件上传 bool ReUpload = txtFPath.Tag != null && txtFPath.Tag.Equals(1); if (ReUpload) { entity.Path = FileHelper.UploadFile(entity.Path, UploadType.ContractQTFJ, ProjectId, null); } #endregion if (string.IsNullOrEmpty(entity.Path)) { MessageHelper.ShowRstMsg(false); } else { JsonResult result = bll.SaveFile(entity, ReUpload); MessageHelper.ShowRstMsg(result.result); if (result.result) { btnFClear_Click(sender, e); LoadFileList(); } } }
/// <summary> /// 文件保存 /// 2017/6/13(zhuguanjun) /// </summary> /// <param name="entity"></param> /// <param name="ReUpload"></param> /// <returns></returns> public JsonResult SaveFile(SubContractFiles entity, bool ReUpload) { JsonResult jsonreslut = new JsonResult(); try { string _id; if (entity.Type != 0) { //不是其他文件 List <SubContractFiles> listOld = GetFiles(entity.SubID, entity.Type); entity.ID = listOld.Count > 0 ? listOld[0].ID : ""; } if (string.IsNullOrEmpty(entity.ID)) { new Repository <SubContractFiles>().Insert(entity, true, out _id); } else { SubContractFiles old = new Repository <SubContractFiles>().Get(entity.ID); old.Name = entity.Name; old.Path = ReUpload ? entity.Path : old.Path; new Repository <SubContractFiles>().Update(old, true, out _id); } jsonreslut.data = _id; jsonreslut.result = true; jsonreslut.msg = "保存成功!"; } catch (Exception ex) { LogHelper.WriteException(ex, LogType.BussinessDLL); jsonreslut.result = false; jsonreslut.msg = ex.Message; } return(jsonreslut); }
/// <summary> /// 保存分包信息 /// 2017/04/13(zhuguanjun) /// </summary> /// <param name="entity">分包信息</param> /// <param name="dicFile">上传文件集合</param> /// <param name="_id"></param> /// <returns></returns> public JsonResult SaveSubContract(SubContract entity, Dictionary <int, string> dicFile, out string _id) { _id = string.Empty; //实际id string SubID = string.Empty; //版本id ISession s = NHHelper.GetCurrentSession(); try { s.BeginTransaction(); #region 保存分包信息 if (string.IsNullOrEmpty(entity.ID)) { if (entity.Status == null) { entity.Status = 1; } entity.ID = Guid.NewGuid().ToString() + "-1"; entity.CREATED = DateTime.Now; SubID = entity.ID; //原始版本id _id = entity.ID; //实际id s.Save(entity); } else { SubContract old = new Repository <SubContract>().Get(entity.ID); old.UPDATED = DateTime.Now; old.Status = 0; s.Update(old); string hisNo = entity.ID.Substring(37); entity.ID = entity.ID.Substring(0, 36) + "-" + (int.Parse(hisNo) + 1).ToString(); _id = entity.ID; //实际id SubID = entity.ID.Substring(0, 36) + "-1"; //原始版本id entity.Status = 1; entity.CREATED = old.CREATED; s.Save(entity); } #endregion #region 保存上传的附件信息 foreach (var item in dicFile) { SubContractFiles file = new SubContractFiles(); switch (item.Key) { case 1: file.Name = "合同扫描件"; break; case 2: file.Name = "合同电子档"; break; case 3: file.Name = "工作说明书扫描件"; break; case 4: file.Name = "工作说明书电子档"; break; case 5: file.Name = "其他"; break; } file.Path = item.Value; file.SubID = SubID; file.Type = item.Key; List <QueryField> qlist = new List <QueryField>(); qlist.Add(new QueryField() { Name = "SubID", Type = QueryFieldType.String, Value = SubID }); //版本id qlist.Add(new QueryField() { Name = "Status", Type = QueryFieldType.Numeric, Value = 1 }); qlist.Add(new QueryField() { Name = "Type", Type = QueryFieldType.Numeric, Value = item.Key }); //附件类型 SubContractFiles old = new Repository <SubContractFiles>().FindSingle(qlist); if (old != null && !string.IsNullOrEmpty(old.ID)) { old.Path = file.Path; old.UPDATED = DateTime.Now; s.Update(old); } else { file.CREATED = DateTime.Now; file.ID = Guid.NewGuid().ToString(); file.Status = 1; s.Save(file); } } #endregion s.Transaction.Commit(); s.Close(); return(new JsonResult { result = true, msg = "保存成功", data = SubID }); } catch (Exception ex) { s.Transaction.Rollback(); s.Close(); throw new Exception("保存实体失败", ex); } }
/// <summary> /// 文件上传事件 /// 2017/04/11(ZhuGuanJun) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void File_Upload(object sender, EventArgs e) { //ButtonX button = (ButtonX)sender; //int Type = int.Parse(button.Name.Substring(3, 1)); //using (OpenFileDialog dialog = new OpenFileDialog()) //{ // dialog.Multiselect = false; // if (dialog.ShowDialog() == DialogResult.OK) // { // string path = string.Empty; // if (!string.IsNullOrEmpty(dialog.FileName)) // path = FileHelper.UploadFile(dialog.FileName, UploadType.SubContract, ProjectId, null); // if (!string.IsNullOrEmpty(path)) // { // if (dicFile.ContainsKey(Type)) // { // dicFile.Remove(Type); // } // dicFile.Add(Type, path); // } // } //} if (string.IsNullOrEmpty(SubID)) { MessageBox.Show("请选择分包合同"); return; } ButtonX button = (ButtonX)sender; int Type = int.Parse(button.Name.Substring(3, 1)); using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Multiselect = false; if (dialog.ShowDialog() == DialogResult.OK) { SubContractFiles entity = new SubContractFiles(); entity.SubID = SubID; switch (Type) { case 1: entity.Path = FileHelper.UploadFile(dialog.FileName, UploadType.SubContract, ProjectId, null); entity.Name = "合同扫描件"; _fileContractHTSMJName = entity.Path; break; case 2: entity.Path = FileHelper.UploadFile(dialog.FileName, UploadType.SubContract, ProjectId, null); entity.Name = "合同电子档"; _fileContractHTDZDName = entity.Path; break; case 3: entity.Path = FileHelper.UploadFile(dialog.FileName, UploadType.SubContract, ProjectId, null); entity.Name = "工作说明书扫描件"; _fileContractGZSMJName = entity.Path; break; case 4: entity.Path = FileHelper.UploadFile(dialog.FileName, UploadType.SubContract, ProjectId, null); entity.Name = "工作说明书电子档"; _fileContractGZDZDName = entity.Path; break; } if (string.IsNullOrEmpty(entity.Path)) { MessageHelper.ShowRstMsg(false); } else { entity.Type = Type; JsonResult result = bll.SaveFile(entity, true); MessageHelper.ShowRstMsg(result.result); LoadFile(); } } } }