/// <summary> /// 生成表單號 /// </summary> /// <param name="CodeName"></param> /// <param name="CodeFix"></param> /// <returns></returns> public static string GetFormNO(string CodeFix) { string Prefix = CodeFix + DateTime.Today.ToString("yyyyMM"); SqlDB sdb = new SqlDB(DataPara.GetDbConnectionString("NPI_REPORT")); ArrayList opc = new ArrayList(); opc.Add(DataPara.CreateDataParameter("@CODE1", DbType.String, Prefix, ParameterDirection.Input, 50)); opc.Add(DataPara.CreateDataParameter("@CODE2", DbType.Int32, null, ParameterDirection.Output, 50)); string no = string.Empty; try { no = sdb.ExecuteProcScalar("[p_GetNumber]", opc, "@CODE2"); } catch (Exception) { throw; } return(Prefix + "-" + int.Parse(no).ToString("0000#")); }
protected void btnConfirm_Click(object sender, DirectEventArgs e) { SpmMaster _Master = (SpmMaster)Master; if (string.IsNullOrEmpty(cmbAttachmentType.SelectedItem.Text)) { Alert("請先選擇上傳的文件類型!"); return; } else { string MFILE_PATH = string.Empty; string MFILE_NAME = string.Empty; SqlDB sdb = new SqlDB(DataPara.GetDbConnectionString("NPI_REPORT")); string File_Type = cmbAttachmentType.SelectedItem.Text.ToString().Trim(); if (string.IsNullOrEmpty(File_Type)) { Alert("請選擇附件類別"); return; } if (!fileMeeting.HasFile) { Alert("請選擇上傳附件!"); return; } int indexMeeting = fileMeeting.FileName.LastIndexOf('.'); string extMeeting = fileMeeting.FileName.Substring(indexMeeting + 1); string fileName = fileMeeting.FileName.Substring(fileMeeting.FileName.LastIndexOf("\\") + 1); if (extMeeting != "pdf") { Alert("附件類型只能為pdf類型!"); return; } //創建保存的目錄 根據主單號與子單號 string type = cmbAttachmentType.SelectedItem.Text.Trim(); string CaseID = _Master.IFormURLPara.CaseId.ToString(); string docNoPath = Server.MapPath("~/Attachment/" + CaseID + "/" + type); string filepath = (docNoPath + "/" + MFILE_NAME); bool IsDocNoExist = Directory.Exists(docNoPath); bool IsSubDocNoExist = Directory.Exists(docNoPath); if (!IsSubDocNoExist) { Directory.CreateDirectory(docNoPath); } #region 文件上傳操作 try { MFILE_PATH = "Attachment/" + CaseID + "/" + type + "/" + fileName; MFILE_NAME = fileName; fileMeeting.PostedFile.SaveAs(docNoPath + "/" + fileName); opc.Clear(); opc.Add(DataPara.CreateDataParameter("@DOC_NO", DbType.String, txtFormNo.Text, ParameterDirection.Input, 30)); opc.Add(DataPara.CreateDataParameter("@CASE_ID", DbType.Int32, _Master.IFormURLPara.CaseId, ParameterDirection.Input, 8)); opc.Add(DataPara.CreateDataParameter("@MFILE_PATH", DbType.String, MFILE_PATH, ParameterDirection.Input, 255)); opc.Add(DataPara.CreateDataParameter("@MFILE_TYPE", DbType.String, File_Type, ParameterDirection.Input, 30)); opc.Add(DataPara.CreateDataParameter("@MFILE_NAME", DbType.String, MFILE_NAME, ParameterDirection.Input, 50)); opc.Add(DataPara.CreateDataParameter("@UPDATE_TIME", DbType.DateTime, DateTime.Now, ParameterDirection.Input, 8)); opc.Add(DataPara.CreateDataParameter("@UPDATE_USERID", DbType.String, lblLogonId.Text, ParameterDirection.Input, 20)); opc.Add(DataPara.CreateDataParameter("@Result", DbType.String, null, ParameterDirection.Output, 1000)); //SP執行結果返回固定格式 //1 OK; //2 NG;ERR MSG string tmp = sdb.ExecuteProcScalar("[P_Upload_NPI_Files]", opc, "@Result"); if (tmp.Length >= 3) { if (tmp.Substring(0, 2) == "NG") { Alert("文件上傳失敗!" + tmp.Substring(3, tmp.Length - 3)); return; } } else { DeleteExistFiles(docNoPath); Alert("文件上傳失敗!DB ERROR,Pls contact IT"); } } catch (Exception ex) { DeleteExistFiles(docNoPath); Alert("文件上傳失敗!DB ERROR:" + ex.Message); } #endregion BindAttachmentList(CaseID); } }
protected void btnUploadP_Click(object sender, DirectEventArgs e) { string Product = cmbProduct.SelectedItem.Text; string ID = txtID.Text; string Item = txtItem.Text; string MFILE_PATH = string.Empty; string MFILE_NAME = string.Empty; string errorMsg = ""; if (!UploadFile.HasFile) { Alert("請選擇上傳附件!"); return; } if (txtItem.Text.Length == 0) { errorMsg += "Item,"; } if (errorMsg.Length > 0) { Alert(errorMsg.Substring(0, errorMsg.Length - 1) + "不能為空"); return; } int indexMeeting = UploadFile.FileName.LastIndexOf('.'); string extMeeting = UploadFile.FileName.Substring(indexMeeting + 1); string fileName = UploadFile.FileName.Substring(UploadFile.FileName.LastIndexOf("\\") + 1); string[] arraryFile; arraryFile = fileName.Split('.'); string ItemName = arraryFile[0]; if (extMeeting.ToLower() != "jpg") { Alert("圖片類型只能是JPG格式!"); return; } if (ItemName != Item) { Alert("圖片名必須和編碼一致!"); return; } //檢查是否存在存放當前專案上傳的文件夾 string docNoPath = Server.MapPath("~/Web/E-Report/DFXPicture/"); string filepath = (docNoPath + "/" + MFILE_NAME); bool IsDocNoExist = Directory.Exists(docNoPath); bool IsSubDocNoExist = Directory.Exists(docNoPath); if (!IsSubDocNoExist) { Directory.CreateDirectory(docNoPath); } DataTable dt = CheckItem2(Item); if (dt.Rows.Count == 0) { #region 文件上傳操作 ADD try { MFILE_PATH = Helper.ConvertChinese("DFXPicture/" + fileName, "Big5"); MFILE_NAME = fileName; string oldfilepath = (docNoPath + "/" + MFILE_NAME); UploadFile.PostedFile.SaveAs(docNoPath + "/" + fileName); opc.Clear(); opc.Add(DataPara.CreateDataParameter("@P_Type", DbType.String, "ADD", ParameterDirection.Input, 50)); opc.Add(DataPara.CreateDataParameter("@Item", DbType.String, Item, ParameterDirection.Input, 50)); opc.Add(DataPara.CreateDataParameter("@MFILE_PATH", DbType.String, Helper.ConvertChinese(MFILE_PATH, "Big5"), ParameterDirection.Input, 255)); opc.Add(DataPara.CreateDataParameter("@MFILE_NAME", DbType.String, Helper.ConvertChinese(MFILE_NAME, "Big5"), ParameterDirection.Input, 50)); opc.Add(DataPara.CreateDataParameter("@UPDATE_TIME", DbType.DateTime, DateTime.Now, ParameterDirection.Input, 8)); opc.Add(DataPara.CreateDataParameter("@UPDATE_USERID", DbType.String, lblLogonId.Text, ParameterDirection.Input, 20)); opc.Add(DataPara.CreateDataParameter("@Result", DbType.String, null, ParameterDirection.Output, 1000)); //SP執行結果返回固定格式 //1 OK; //2 NG;ERR MSG try { string tmp = sdb.ExecuteProcScalar("[P_Upload_DFXPicture]", opc, "@Result"); if (tmp.Length >= 3) { if (tmp.Substring(0, 2) == "NG") { Alert("文件上傳失敗!" + tmp.Substring(3, tmp.Length - 3)); return; } else if (tmp.Substring(0, 2) == "OK") { Alert("文件上傳成功!"); } } else { Alert("文件上傳成功!"); } } catch (Exception ex) { File.Delete(@oldfilepath);; //刪除已存在的文件 Alert("文件上傳失敗!" + ex.Message); } } catch (Exception ex) { DeleteExistFiles(docNoPath); Alert("文件上傳失敗!DB ERROR:" + ex.Message); return; } #endregion } else { #region 文件上傳操作 Updates try { DataRow dr = dt.Rows[0]; MFILE_PATH = Helper.ConvertChinese("DFXPicture/" + fileName, "Big5"); MFILE_NAME = fileName; string oldfilepath = (docNoPath + "/" + dr["FILE_NAME"].ToString()); string FilePath1 = (docNoPath + "/" + fileName); UploadFile.PostedFile.SaveAs(docNoPath + "/" + fileName); opc.Clear(); opc.Add(DataPara.CreateDataParameter("@P_Type", DbType.String, "Update", ParameterDirection.Input, 50)); opc.Add(DataPara.CreateDataParameter("@Item", DbType.String, Item, ParameterDirection.Input, 50)); opc.Add(DataPara.CreateDataParameter("@MFILE_PATH", DbType.String, Helper.ConvertChinese(MFILE_PATH, "Big5"), ParameterDirection.Input, 255)); opc.Add(DataPara.CreateDataParameter("@MFILE_NAME", DbType.String, Helper.ConvertChinese(MFILE_NAME, "Big5"), ParameterDirection.Input, 50)); opc.Add(DataPara.CreateDataParameter("@UPDATE_TIME", DbType.DateTime, DateTime.Now, ParameterDirection.Input, 8)); opc.Add(DataPara.CreateDataParameter("@UPDATE_USERID", DbType.String, lblLogonId.Text, ParameterDirection.Input, 20)); opc.Add(DataPara.CreateDataParameter("@Result", DbType.String, null, ParameterDirection.Output, 1000)); //SP執行結果返回固定格式 //1 OK; //2 NG;ERR MSG try { string tmp = sdb.ExecuteProcScalar("[P_Upload_DFXPicture]", opc, "@Result"); if (tmp.Length >= 3) { if (tmp.Substring(0, 2) == "NG") { Alert("文件上傳失敗!" + tmp.Substring(3, tmp.Length - 3)); File.Delete(@FilePath1); return; } else if (tmp.Substring(0, 2) == "OK") { Alert("文件上傳成功!"); File.Delete(@oldfilepath); } } else { Alert("文件上傳成功!"); } } catch (Exception ex) { Alert("文件上傳失敗!" + ex.Message); } } catch (Exception ex) { Alert("文件上傳失敗!DB ERROR:" + ex.Message); //File.Delete(@FilePath1); return; } #endregion } BindDFX(Product); }