public string print(string printListJson) { string error = "NULL"; if (CheckTools.isNull(printListJson)) { return(error); } PrinterList printerList = JsonConvert.DeserializeObject <PrinterList>(printListJson); if (printerList == null) { return(error); } if (printerList.command == null) { printerList.command = "print"; } if (string.Equals("print", printerList.command, StringComparison.CurrentCultureIgnoreCase)) { print(true, printerList); error = printerList.errorMsg; } else { error = printListJson; } //StringBuilder sb = new StringBuilder(printerList.listId == null ? "" : printerList.listId.ToString()).Append("ACK".Equals(error) ? "打印成功!" : error); //error = sb.ToString(); //sb.Clear(); return(error); }
private ExcelTemplateBean CellValueRegex(string cellValue) { if (CheckTools.isNull(cellValue)) { return(new ExcelTemplateBean(-1)); } cellValue = cellValue.Trim(); string fieldId = null; string fieldName = null; Match match = fieldRegex.Match(cellValue); if (match.Success) { fieldName = match.Groups[1].Value; //Console.WriteLine(fieldName); return(new ExcelTemplateBean(1, fieldName)); } match = ListRegex.Match(cellValue); if (match.Success) { fieldId = match.Groups[1].Value; fieldName = match.Groups[2].Value; return(new ExcelTemplateBean(2, fieldId, fieldName)); } return(new ExcelTemplateBean(0)); }
private void readIni() { Ini ini = new Ini(Application.StartupPath + Path.DirectorySeparatorChar + "user.ini"); string address = ini.Read("user", "address", 256); if (CheckTools.isUrl(address)) { this.txt_print_address.Text = address; } string company = ini.Read("user", "company", 256); if (!CheckTools.isNull(company)) { this.txt_company_code_port.Text = FingerUtil.Decrypt(company, key); } else { txt_company_code_port.Text = ""; } string name = ini.Read("user", "name", 256); if (!CheckTools.isNull(name)) { this.txt_login_name.Text = FingerUtil.Decrypt(name, key); } string password = ini.Read("user", "password", 256); if (!CheckTools.isNull(password)) { this.txt_login_password.Text = FingerUtil.Decrypt(password, key); } }
public static int?ToInt(object obj) { if (obj == null || obj == DBNull.Value || !CheckTools.isNumber(obj.ToString())) { return(null); } int result = default(int); int.TryParse(obj.ToString(), out result); return(result); }
public void OnOpened(object sender, DocumentOpenedEventArgs args) { try { Document doc = args.Document; if (!CheckTools.AllWorksetsAreOpened(doc)) { return; } if (doc.IsWorkshared && !doc.IsDetached) { string path = ModelPathUtils.ConvertModelPathToUserVisiblePath(doc.GetWorksharingCentralModelPath()); FileInfo centralPath = new FileInfo(path); foreach (DbDocument dbDoc in KPLNDataBase.DbControll.Documents) { FileInfo metaCentralPath = new FileInfo(dbDoc.Path); if (dbDoc.Code == "NONE") { continue; } if (centralPath.FullName == metaCentralPath.FullName) { if (File.Exists(string.Format(@"Z:\Отдел BIM\03_Скрипты\09_Модули_KPLN_Loader\DB\BatchModelCheck\doc_id_{0}.sqlite", dbDoc.Id.ToString()))) { List <DbRowData> rows = DbController.GetRows(dbDoc.Id.ToString()); if (rows.Count != 0) { if ((DateTime.Now.Day - rows.Last().DateTime.Day > 7 && rows.Last().DateTime.Day != DateTime.Now.Day) || rows.Last().DateTime.Month != DateTime.Now.Month || rows.Last().DateTime.Year != DateTime.Now.Year) { CheckDocument(doc, dbDoc); } } else { CheckDocument(doc, dbDoc); } } else { CheckDocument(doc, dbDoc); } } } } } catch (Exception) { } }
private void CheckDocument(Document doc, DbDocument dbDoc) { try { DbRowData rowData = new DbRowData(); rowData.Errors.Add(new DbError("Ошибка привязки к уровню", CheckTools.CheckLevels(doc))); rowData.Errors.Add(new DbError("Зеркальные элементы", CheckTools.CheckMirrored(doc))); rowData.Errors.Add(new DbError("Ошибка мониторинга осей", CheckTools.CheckMonitorGrids(doc))); rowData.Errors.Add(new DbError("Ошибка мониторинга уровней", CheckTools.CheckMonitorLevels(doc))); rowData.Errors.Add(new DbError("Дубликаты имен", CheckTools.CheckNames(doc))); rowData.Errors.Add(new DbError("Ошибки подгруженных связей", CheckTools.CheckSharedLocations(doc) + CheckTools.CheckLinkWorkSets(doc))); rowData.Errors.Add(new DbError("Предупреждения Revit", CheckTools.CheckErrors(doc))); rowData.Errors.Add(new DbError("Размер файла", CheckTools.CheckFileSize(dbDoc.Path))); DbController.WriteValue(dbDoc.Id.ToString(), rowData.ToString()); //BotActions.SendRegularMessage(string.Format("👌 @{0}_{1} завершил проверку документа #{3} #{2}", NormalizeString(KPLN_Loader.Preferences.User.Family), NormalizeString(KPLN_Loader.Preferences.User.Name), NormalizeString(dbDoc.Project.Name), NormalizeString(dbDoc.Name)), Bot.Target.Process); } catch (Exception) { } }
private void UpdateForm_Load(object sender, EventArgs e) { string file = Application.StartupPath + Path.DirectorySeparatorChar + "version.ini"; if (File.Exists(file)) { Ini ini = new Ini(file); app = new AutoVersionInfo(); app.SoftName = ini.Read("version", "name", 256); app.Version = ini.Read("version", "version", 256); app.Description = ini.Read("version", "description", 256); app.Forced = StaticUtil.ToInt(ini.Read("version", "forced", 256)); app.Url = ini.Read("version", "url", 256); app.Md5 = ini.Read("version", "md5", 256); app.Size = StaticUtil.ToInt(ini.Read("version", "size", 256)); if (!CheckTools.isPoint(StaticUtil.VERSION)) { throw new Exception("系统版本号设置有误!"); } if (!CheckTools.isPoint(app.Version)) { throw new Exception("远程版本号设置有误!"); } if (float.Parse(app.Version) > float.Parse(StaticUtil.VERSION)) { app.IsUpdate = true; } } else { this.progress_file.Text = "正在检测版本号..."; app = AutoVersionInfo.CheckIsUpdate(StaticUtil.VERSION); } UpdateApp(); }
//:TODO 询盘写入数据 public static void EnquirySave(string ipString, string email, string content, string productUrl, string productName, string yourName, string company, string tel, string msn, string language, string country, string recievedId) { if (string.IsNullOrWhiteSpace(content)) { return; } if (string.IsNullOrWhiteSpace(email)) { return; } if (string.IsNullOrWhiteSpace(productUrl)) { return; } if (string.IsNullOrWhiteSpace(tel)) { //return; tel = ""; } if (string.IsNullOrWhiteSpace(yourName)) { //return; yourName = ""; } if (string.IsNullOrWhiteSpace(company)) { company = ""; } if (string.IsNullOrWhiteSpace(msn)) { //return; msn = ""; } if (!CheckTools.IsValidEmail(email)) { return; } //if (!CheckTools.IsAllNumber(tel)) //{ // return; //} //add by luoyaqi 20140712 Manager manger = managerRepository.GetManagerByUserName(recievedId.Trim()); if (manger == null) { return; } long languageId = 0; BaseDictionary baseDictionary = baseDictionaryRepository.GetDictionaryByValue(language); if (baseDictionary != null) { Enquiry enquiry = EnquiryFactory.Create(ipString, email, content, productUrl, productName, yourName, company, tel, msn, language, baseDictionary.Id, country, manger.Id, manger.UserName); enquiry.EnquiryTimes = enquiryRepository.GetEnquiryTimesByEmail(email) + 1; enquiry.ReceiverEmail = manger.UserName; enquiryRepository.Save(enquiry); SendEmail("YiSearch 邮件询盘提醒", "YiSearch 邮件询盘提醒", manger.BindEmail); } }
public PrinterList print(bool isPrint, PrinterList printerList) { string error = null; if (printerList == null) { error = "无可用打印数据"; printerList.printResult = 2; printerList.errorMsg = error; return(printerList); } if (CheckTools.isNull(printerList.templateFileName)) { error = "打印模板名称不允许为空"; printerList.printResult = 2; printerList.errorMsg = error; return(printerList); } IDictionary <string, string> fixedField = null; if (!CheckTools.isNull(printerList.printerJson)) { try { fixedField = JsonConvert.DeserializeObject <IDictionary <string, string> >(printerList.printerJson); } catch (Exception e) { //Console.WriteLine("CallServiceThread序列化异常:" + e.Message); error = e.Message; } } IDictionary <string, DataTable> listField = null; if (!CheckTools.isNull(printerList.printerListJson)) { try { listField = JsonConvert.DeserializeObject <IDictionary <string, DataTable> >(printerList.printerListJson); } catch (Exception e) { //Console.WriteLine("CallServiceThread序列化异常:" + e.Message); error = e.Message; } } //序列化出错 if (error != null) { printerList.printResult = 2; printerList.errorMsg = error; return(printerList); } if ((fixedField == null || fixedField.Count == 0) && (listField == null || listField.Count == 0)) { error = "打印模板内容参数printerJson或printerListJson不允许同时为空"; printerList.printResult = 2; printerList.errorMsg = error; return(printerList); } string filename; int dot = printerList.templateFileName.IndexOf("."); if (dot == -1) { filename = printerList.templateFileName; printerList.templateFileName += ".xlsx"; } else { filename = printerList.templateFileName.Substring(0, dot); } string exportOutFileName = filename + "_"; if (printerList.listId == null) { exportOutFileName += StaticUtil.ConvertDateTimeToTimestamp(printerList.requestTime); } else { exportOutFileName += printerList.listId; } try { string excelFileName = new ExcelUtil().TemplateExport(printerList.templateFileName, exportOutFileName, fixedField, listField); if (printerList.command == null) { printerList.command = "print"; } if (string.Equals("print", printerList.command, StringComparison.CurrentCultureIgnoreCase)) { StaticUtil.Print(excelFileName); } //打印结果0待打印1打印成功2打印失败 printerList.printResult = 1; printerList.errorMsg = "ACK"; } catch (Exception e) { Console.WriteLine("CallServiceThread.ExcelUtil.TemplateExport异常" + e); error = e.Message; printerList.printResult = 2; printerList.errorMsg = error; } return(printerList); }
public Result Execute(UIApplication app) { if (ModuleData.up_send_enter) { Thread thread = new Thread(() => { var autoEvent = new AutoResetEvent(true); _Timer = new System.Threading.Timer(UiInput.KeyEnter, autoEvent, 20000, 20000); }); thread.Start(); } try { string assemblyPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName; Print(string.Format("[{0}] Запуск...", DateTime.Now.ToString("T")), KPLN_Loader.Preferences.MessageType.Header); ModuleData.AutoConfirmEnabled = true; if (app.Application.Documents.IsEmpty) { Print("Создание [placeholder] документа...", KPLN_Loader.Preferences.MessageType.Regular); app.Application.NewProjectDocument(UnitSystem.Metric); } int max = Documents.Count; int step = 0; foreach (DbDocument doc in Documents) { step++; string step_info = string.Format("[{0}/{1}]", step.ToString(), max.ToString()); try { Print(string.Format("[{0}] Открытие {1}...", DateTime.Now.ToString("T"), doc.Path), KPLN_Loader.Preferences.MessageType.Header); ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath(doc.Path); OpenOptions options = new OpenOptions() { DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets, Audit = false }; WorksetConfiguration config = new WorksetConfiguration(WorksetConfigurationOption.OpenAllWorksets); options.SetOpenWorksetsConfiguration(config); Document docu = app.Application.OpenDocumentFile(path, options); try { DbRowData rowData = new DbRowData(); rowData.Errors.Add(new DbError("Ошибка привязки к уровню", CheckTools.CheckLevels(docu))); rowData.Errors.Add(new DbError("Зеркальные элементы", CheckTools.CheckMirrored(docu))); rowData.Errors.Add(new DbError("Ошибка мониторинга осей", CheckTools.CheckMonitorGrids(docu))); rowData.Errors.Add(new DbError("Ошибка мониторинга уровней", CheckTools.CheckMonitorLevels(docu))); rowData.Errors.Add(new DbError("Дубликаты имен", CheckTools.CheckNames(docu))); rowData.Errors.Add(new DbError("Ошибки подгруженных связей", CheckTools.CheckSharedLocations(docu) + CheckTools.CheckLinkWorkSets(docu))); rowData.Errors.Add(new DbError("Предупреждения Revit", CheckTools.CheckErrors(docu))); rowData.Errors.Add(new DbError("Размер файла", CheckTools.CheckFileSize(doc.Path))); rowData.Errors.Add(new DbError("Элементы в наборах подгруженных связей", CheckTools.CheckElementsWorksets(docu))); DbController.WriteValue(doc.Id.ToString(), rowData.ToString()); Print(string.Format("[{0}] Закрытие документа...", DateTime.Now.ToString("T")), KPLN_Loader.Preferences.MessageType.Header); } catch (Exception e) { PrintError(e); } docu.Close(false); } catch (Exception e) { PrintError(e); } } ModuleData.AutoConfirmEnabled = false; _Timer.Dispose(); return(Result.Succeeded); } catch (Exception e) { ModuleData.AutoConfirmEnabled = false; PrintError(e); _Timer.Dispose(); return(Result.Failed); } }
public string TemplateExport(string templateFileNameAndExtension, string exportOutFileName, IDictionary <string, string> fixedField, IDictionary <string, DataTable> listField) { IWorkbook workbook = null; FileStream inFileStream = null; FileStream outFileStream = null; try { if ((fixedField != null && fixedField.Count > 0)) { fieldList = new List <ExcelTemplateBean>(fixedField.Count); } if ((listField != null && listField.Count > 0)) { dicList = new Dictionary <string, List <ExcelTemplateBean> >(listField.Count); } if (fieldList == null && dicList == null) { return(null); } string fileDir = Application.StartupPath; string fileName = fileDir + Path.DirectorySeparatorChar + "resource" + Path.DirectorySeparatorChar + "template" + Path.DirectorySeparatorChar + templateFileNameAndExtension; //Console.WriteLine("模板文件路径:"+fileName); inFileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); string extension = Path.GetExtension(fileName); //if (".xlsx".Equals(extension)) //{ // workbook = new XSSFWorkbook(inFileStream); //} //else if (".xls".Equals(extension)) //{ // workbook = new HSSFWorkbook(inFileStream); //} //else //{ // return null; //} if (!".xls".Equals(extension) && !".xlsx".Equals(extension)) { return(null); } workbook = WorkbookFactory.Create(inFileStream); ScanField(workbook); ISheet sheet = workbook.GetSheetAt(0); IRow row = null; ICell cell = null; string cellValue = null; string regex = null; string fieldValue = null; //写固定字段 if (fieldList != null) { foreach (ExcelTemplateBean bean in fieldList) { row = sheet.GetRow(bean.RowIndex); cell = row.GetCell(bean.ColumnIndex); if (cell == null) { continue; } cellValue = cell.ToString(); regex = "f{" + bean.FieldName + "}"; if (CheckTools.isNull(cellValue)) { cellValue = regex; } if (fixedField.ContainsKey(bean.FieldName)) { fieldValue = fixedField[bean.FieldName]; } else { fieldValue = null; } if (fieldValue == null) { fieldValue = ""; } cell.SetCellValue(cellValue.Replace(regex, fieldValue)); } } //写列表字段 if (dicList != null) { int realInsertedRows = 0; string listId; DataTable dataTable = null; List <ExcelTemplateBean> beanList; foreach (KeyValuePair <string, List <ExcelTemplateBean> > pair in dicList) { listId = pair.Key; beanList = pair.Value; //List<ExcelTemplateBean>属于同一行数据 if (listField.ContainsKey(listId)) { dataTable = listField[listId]; } else { dataTable = new DataTable(); //创建空行 DataRow dr = dataTable.NewRow(); dataTable.Rows.Add(dr); foreach (ExcelTemplateBean bean in beanList) { //动态添加列 dataTable.Columns.Add(bean.FieldName, typeof(string)); //通过列名赋值 dr[bean.FieldName] = ""; } } int minRowIndex = MinRowIndex(beanList); if (minRowIndex == -1 || minRowIndex == int.MaxValue) { continue; } int templateStartRowIndex = minRowIndex + realInsertedRows; //计算变化后的起码索引号 int NumInsertedRows = dataTable.Rows.Count - 1; //少插入一行,模板自身占了一行 int realInsertingRows = InsertRows(sheet, templateStartRowIndex, NumInsertedRows); //本次插入的实际行数 int multipleInserted = NumInsertedRows == 0 ? 0 : (realInsertingRows / NumInsertedRows); for (int i = 0; i < dataTable.Rows.Count; i++) { DataRow dr = dataTable.Rows[i]; foreach (ExcelTemplateBean bean in beanList) { row = sheet.GetRow(bean.RowIndex + realInsertedRows + i * multipleInserted); cell = row.GetCell(bean.ColumnIndex);//列不变 if (cell == null) { continue; } cellValue = cell.ToString(); regex = "f{" + bean.FieldId + "}{" + bean.FieldName + "}"; if (CheckTools.isNull(cellValue)) { cellValue = regex; } if (dr.Table.Columns.Contains(bean.FieldName) && dr[bean.FieldName] != null) { fieldValue = dr[bean.FieldName].ToString(); } else { fieldValue = null; } if (fieldValue == null) { fieldValue = ""; } cell.SetCellValue(cellValue.Replace(regex, fieldValue)); } } realInsertedRows += realInsertingRows;//多数据模板行时累加插入的实际行数 } } string outFileName = fileDir + Path.DirectorySeparatorChar + "resource" + Path.DirectorySeparatorChar + "export" + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd") + Path.DirectorySeparatorChar + exportOutFileName + extension; string parentPath = Path.GetDirectoryName(outFileName); if (false == Directory.Exists(parentPath)) { //创建pic文件夹 Directory.CreateDirectory(parentPath); } outFileStream = new FileStream(outFileName, FileMode.Create, FileAccess.Write); workbook.Write(outFileStream); outFileStream.Flush(); return(outFileName); } finally { if (inFileStream != null) { inFileStream.Close(); } if (outFileStream != null) { outFileStream.Close(); } if (workbook != null) { workbook.Close(); } } }
private void btn_login_Click(object sender, EventArgs e) { if (reqireLogin) { string print_address = txt_print_address.Text.Trim(); if (!CheckTools.isUrl(print_address)) { MessageBoxEx.Show(this, "服务地址须为有效域名或IP", "提示", MessageBoxButtons.OK); return; } if (print_address.EndsWith("/")) { print_address = print_address.Substring(0, print_address.Length - 1); } string company_code = txt_company_code_port.Text.Trim(); if (company_code.Length < 3) { MessageBoxEx.Show(this, "公司代码不允许为空", "提示", MessageBoxButtons.OK); return; } string login_name = txt_login_name.Text.Trim(); if (login_name.Length < 3) { MessageBoxEx.Show(this, "登录账号不允许为空", "提示", MessageBoxButtons.OK); return; } string login_password = txt_login_password.Text.Trim(); if (login_password.Length < 3) { MessageBoxEx.Show(this, "账号密码不允许为空", "提示", MessageBoxButtons.OK); return; } StaticUtil.PRINT_ADDRESS = print_address; Dictionary <string, string> parameters = new Dictionary <string, string>(3); parameters.Add("companyCode", company_code); parameters.Add("loginName", login_name); parameters.Add("loginPassword", login_password); string result = null; result = HttpRequestClientUtil.doPost(StaticUtil.PRINT_ADDRESS + "/user/login", StaticUtil.DEFAULT_CHARSET, 60000, null, parameters, null); if (null == result) { MessageBoxEx.Show(this, "登录超时,请检查网络", "提示", MessageBoxButtons.OK); } else { Result <UserCookieBean> data = JsonConvert.DeserializeObject <Result <UserCookieBean> >(result); if (data.success && data.bizErrCode == 20000) { StaticUtil.USER_COOKIE_BEAN = data.data; string domain = StaticUtil.getDomainByPrintAddress(StaticUtil.PRINT_ADDRESS); Encoding encoding = Encoding.GetEncoding(StaticUtil.DEFAULT_CHARSET); Cookie userIdCookie = new Cookie("user_id", HttpUtility.UrlEncode(StaticUtil.USER_COOKIE_BEAN.userId.ToString(), encoding), "/", domain); StaticUtil.USER_COOKIE_BEAN.Cookies.Add(userIdCookie); Cookie companyCodeCookie = new Cookie("company_code", HttpUtility.UrlEncode(StaticUtil.USER_COOKIE_BEAN.companyCode, encoding), "/", domain); StaticUtil.USER_COOKIE_BEAN.Cookies.Add(companyCodeCookie); Cookie loginNameCookie = new Cookie("login_name", HttpUtility.UrlEncode(StaticUtil.USER_COOKIE_BEAN.loginName, encoding), "/", domain); StaticUtil.USER_COOKIE_BEAN.Cookies.Add(loginNameCookie); Cookie userNameCookie = new Cookie("user_name", HttpUtility.UrlEncode(StaticUtil.USER_COOKIE_BEAN.userName, encoding), "/", domain); StaticUtil.USER_COOKIE_BEAN.Cookies.Add(userNameCookie); Cookie cookie_sessionCookie = new Cookie("cookie_session", HttpUtility.UrlEncode(StaticUtil.USER_COOKIE_BEAN.cookie_session, encoding), "/", domain); StaticUtil.USER_COOKIE_BEAN.Cookies.Add(cookie_sessionCookie); Ini ini = new Ini(Application.StartupPath + Path.DirectorySeparatorChar + "user.ini"); ini.Write("user", "address", StaticUtil.PRINT_ADDRESS); ini.Write("user", "company", FingerUtil.Encrypt(company_code, key)); ini.Write("user", "name", FingerUtil.Encrypt(login_name, key)); ini.Write("user", "password", FingerUtil.Encrypt(login_password, key)); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBoxEx.Show(this, data.defaultRequestFailShow(), "提示", MessageBoxButtons.OK); } } } else { string address = txt_print_address.Text.Trim(); if (!CheckTools.isIp(address)) { MessageBoxEx.Show(this, "请输入本地打印服务器地址且必须为IP格式", "提示", MessageBoxButtons.OK); return; } string ports = txt_company_code_port.Text.Trim(); if (!CheckTools.isPositiveNumber(ports)) { ports = "27027"; } int port = int.Parse(ports); if (port <= 1024 || port > 65535) { MessageBoxEx.Show(this, "请输入手机打印服务器端口号,有效范围1025~65535", "提示", MessageBoxButtons.OK); return; } } }