/// <summary> /// 在INI文件中,删除指定节点中的所有内容。 /// </summary> /// <param name="iniFile">INI文件</param> /// <param name="section">节点</param> /// <returns>操作是否成功</returns> public static bool INIEmptySection(string iniFile, string section) { if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } return(INIOperationClass.WritePrivateProfileSection(section, string.Empty, iniFile)); }
/// <summary> /// 在INI文件中,将指定的键值对写到指定的节点,如果已经存在则替换 /// </summary> /// <param name="iniFile">INI文件</param> /// <param name="section">节点,如果不存在此节点,则创建此节点</param> /// <param name="items">键值对,多个用\0分隔,形如key1=value1\0key2=value2</param> /// <returns></returns> public static bool INIWriteItems(string iniFile, string section, string items) { if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } if (string.IsNullOrEmpty(items)) { throw new ArgumentException("必须指定键值对", "items"); } return(INIOperationClass.WritePrivateProfileSection(section, items, iniFile)); }
/// <summary> /// 在INI文件中,删除指定节点中的指定的键。 /// </summary> /// <param name="iniFile">INI文件</param> /// <param name="section">节点</param> /// <param name="key">键</param> /// <returns>操作是否成功</returns> public static bool INIDeleteKey(string iniFile, string section, string key) { if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentException("必须指定键名称", "key"); } return(INIOperationClass.WritePrivateProfileString(section, key, null, iniFile)); }
/// <summary> /// 在INI文件中,指定节点写入指定的键及值。如果已经存在,则替换。如果没有则创建。 /// </summary> /// <param name="iniFile">INI文件</param> /// <param name="section">节点</param> /// <param name="key">键</param> /// <param name="value">值</param> /// <returns>操作是否成功</returns> public static bool INIWriteValue(string iniFile, string section, string key, string value) { if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentException("必须指定键名称", "key"); } if (value == null) { throw new ArgumentException("值不能为null", "value"); } return(INIOperationClass.WritePrivateProfileString(section, key, value, iniFile)); }
public Form1() { this.WindowState = FormWindowState.Maximized; NELog.logPath = @".\log"; InitializeComponent(); view1.MdiParent = this; view2.MdiParent = this; view3.MdiParent = this; view4.MdiParent = this; Config.G_READER_TIMER = int.Parse(INIOperationClass.INIGetStringValue(".\\config.ini", "params", "readtimer", "3000")); Config.G_DB_IP_STR = INIOperationClass.INIGetStringValue(".\\config.ini", "params", "databaseip", "127.0.0.1"); Config.G_DB_DATABASE_STR = INIOperationClass.INIGetStringValue(".\\config.ini", "params", "databasename", "hkcdb2"); Config.G_DB_USER_STR = INIOperationClass.INIGetStringValue(".\\config.ini", "params", "databaseuser", "root"); Config.G_DB_PWD_STR = INIOperationClass.INIGetStringValue(".\\config.ini", "params", "databasepwd", "qq1223"); //MessageBox.Show(); view1.Show(); }
/// <summary> /// 获取INI文件中指定节点(Section)中的所有条目的Key列表 /// </summary> /// <param name="iniFile">Ini文件</param> /// <param name="section">节点名称</param> /// <returns>如果没有内容,反回string[0]</returns> public static string[] INIGetAllItemKeys(string iniFile, string section) { string[] value = new string[0]; const int SIZE = 1024 * 10; if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } char[] chars = new char[SIZE]; uint bytesReturned = INIOperationClass.GetPrivateProfileString(section, null, null, chars, SIZE, iniFile); if (bytesReturned != 0) { value = new string(chars).Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); } chars = null; return(value); }
/// <summary> /// 获取INI文件中指定节点(Section)中的所有条目(key=value形式) /// </summary> /// <param name="iniFile">Ini文件</param> /// <param name="section">节点名称</param> /// <returns>指定节点中的所有项目,没有内容返回string[0]</returns> public static string[] INIGetAllItems(string iniFile, string section) { //返回值形式为 key=value,例如 Color=Red uint MAX_BUFFER = 32767; //默认为32767 string[] items = new string[0]; //返回值 //分配内存 IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char)); uint bytesReturned = INIOperationClass.GetPrivateProfileSection(section, pReturnedString, MAX_BUFFER, iniFile); if (!(bytesReturned == MAX_BUFFER - 2) || (bytesReturned == 0)) { string returnedString = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned); items = returnedString.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); } Marshal.FreeCoTaskMem(pReturnedString); //释放内存 return(items); }
private void FormView2_Load(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; this.listView1.GridLines = true; //显示表格线 this.listView1.View = View.Details; //显示表格细节 this.listView1.FullRowSelect = true; //是否可以选择行 ImageList image = new ImageList(); image.ImageSize = new Size(1, 25); this.listView1.SmallImageList = image; //添加表头 this.listView1.Columns.Add("处理序号", 200, HorizontalAlignment.Center); this.listView1.Columns.Add("患者编号", 200, HorizontalAlignment.Center); this.listView1.Columns.Add("姓名", 180, HorizontalAlignment.Center); this.listView1.Columns.Add("处方号", 250, HorizontalAlignment.Center); this.listView1.Columns.Add("日期", 250, HorizontalAlignment.Center); this.listView1.Columns.Add("窗口号", 120, HorizontalAlignment.Center); this.listView2.GridLines = true; //显示表格线 this.listView2.View = View.Details; //显示表格细节 this.listView2.FullRowSelect = true; //是否可以选择行 this.listView2.SmallImageList = image; //添加表头 this.listView2.Columns.Add("序号", 70, HorizontalAlignment.Center); this.listView2.Columns.Add("药品编码", 200, HorizontalAlignment.Left); this.listView2.Columns.Add("药品名称", 250, HorizontalAlignment.Left); this.listView2.Columns.Add("规格", 200, HorizontalAlignment.Left); this.listView2.Columns.Add("厂家", 200, HorizontalAlignment.Left); this.listView2.Columns.Add("数量", 100, HorizontalAlignment.Center); this.listView2.Columns.Add("库位", 180, HorizontalAlignment.Center); if (!INIOperationClass.INIGetStringValue(".\\config.ini", "params", "printername", "").Equals("")) { // Report.Printer.PrinterName = INIOperationClass.INIGetStringValue(".\\config.ini", "params", "printername", ""); } // Report.LoadFromFile(".\\op.grf"); }
/// <summary> /// 读取INI文件中指定INI文件中的所有节点名称(Section) /// </summary> /// <param name="iniFile">Ini文件</param> /// <returns>所有节点,没有内容返回string[0]</returns> public static string[] INIGetAllSectionNames(string iniFile) { uint MAX_BUFFER = 32767; //默认为32767 string[] sections = new string[0]; //返回值 //申请内存 IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char)); uint bytesReturned = INIOperationClass.GetPrivateProfileSectionNames(pReturnedString, MAX_BUFFER, iniFile); if (bytesReturned != 0) { //读取指定内存的内容 string local = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned).ToString(); //每个节点之间用\0分隔,末尾有一个\0 sections = local.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); } //释放内存 Marshal.FreeCoTaskMem(pReturnedString); return(sections); }
void pd_PrintPage(object sender, PrintPageEventArgs e) { if (watitingDealCdoe == null || watitingDealCdoe.Equals("")) { return; } // $Q701 00 00 Nn xxxxxx xxxx* 出药口/窗口/2位长/条码 //MessageBox.Show(watitingDealCdoe.Substring(8, 2)); string barCode = watitingDealCdoe.Substring(11, int.Parse(watitingDealCdoe.Substring(9, 2))); //中国人民解放军第一五九中心医院 String hospital = INIOperationClass.INIGetStringValue(".\\config.ini", "cfg", "hospital", ""); Font font = new Font("宋体", 12); Brush bru = Brushes.Black; e.Graphics.DrawString(hospital, font, bru, 10, 0); BarCode_EAN13.Paint_EAN13(barCode, e.Graphics, new Rectangle(10, 20, 150, 60)); Font font2 = new Font("宋体", 30); Patient patient = getPrescription(barCode); e.Graphics.DrawString(patient.FetchWindow, font2, bru, 210, 30); try { Font fonts = new Font("宋体", 22); if ("X".Equals(watitingDealCdoe.Substring(6, 1))) { e.Graphics.DrawString("下", fonts, bru, 245, 40); } else if ("S".Equals(watitingDealCdoe.Substring(6, 1))) { e.Graphics.DrawString("上", fonts, bru, 245, 40); } } catch (System.Exception ex) { // } e.Graphics.DrawString(patient.PName, font, bru, 0, 90); e.Graphics.DrawString(patient.Sex, font, bru, 60, 90); e.Graphics.DrawString(patient.Age, font, bru, 120, 90); e.Graphics.DrawString("=======================================", font, bru, 0, 105); Font font3 = new Font("宋体", 10); int yPosition = 120; int ocount = patient.PrescInfo.Count; foreach (PrescriptionInfo prescInfo in patient.PrescInfo) { e.Graphics.DrawString("※处方号:" + prescInfo.PrescriptionNO, font3, bru, 0, yPosition); int i = 1; foreach (PrescriptionDetl prescDetl in prescInfo.DetlList) { //e.Graphics.DrawString((i++) + "/" + prescInfo.DetlList.Count + " " + prescDetl.DrugName, font3, bru, 0, yPosition + 20); //去掉编号 if (prescDetl.DrugName.Length < 16) { string kg = ""; int total = 15; for (int k = 1; k < total - prescDetl.DrugName.Length; k++) { kg += " "; } e.Graphics.DrawString(" " + prescDetl.DrugName + kg + prescDetl.PrescriptionQty + prescDetl.PrescriptionUnit, font3, bru, 0, yPosition + 20); e.Graphics.DrawString(" " + prescDetl.DrugSpec + "(" + prescDetl.Manufactory + ")", font3, bru, 0, yPosition + 35); } else { string kg = ""; int total = 15; for (int j = 1; j < total - prescDetl.DrugSpec.Length - prescDetl.Manufactory.Length - 2; j++) { kg += " "; } e.Graphics.DrawString(" " + prescDetl.DrugName, font3, bru, 0, yPosition + 20); e.Graphics.DrawString(" " + prescDetl.DrugSpec + "(" + prescDetl.Manufactory + ")" + " " + prescDetl.PrescriptionQty + prescDetl.PrescriptionUnit, font3, bru, 0, yPosition + 35); } //e.Graphics.DrawString(" " + prescDetl.StorageLoc, font, bru, 0, yPosition + 50); e.Graphics.DrawString(" " + prescDetl.UseFrequency + " " + prescDetl.UseDosage + " " + prescDetl.UseRoute, font, bru, 0, yPosition + 55); //e.Graphics.DrawString(" " + prescDetl.UseRoute + " " + prescDetl.Num_1, font, bru, 0, yPosition + 70); //e.Graphics.DrawString(" " + prescDetl.UseFrequency + " " + prescDetl.UseDosage, font3, bru, 0, yPosition + 80); //e.Graphics.DrawString(" " + prescDetl.UseRoute + " " + prescDetl.Notes, font3, bru, 0, yPosition + 95); //e.Graphics.DrawString(" " + "单价 "+prescDetl.Price, font, bru, 0, yPosition + 110); yPosition += 60; } ocount--; if (ocount > 0) { e.Graphics.DrawString("---------------------------------------", font, bru, 0, yPosition + 15); yPosition += 30; } } // //e.Graphics.DrawString("---------------------------------------", font, bru, 0, 235); //e.Graphics.DrawString("※处方号:200000102103", font3, bru, 0, 250); //e.Graphics.DrawString("1/2 复方磺胺甲噁唑片", font3, bru, 0, 270); //e.Graphics.DrawString(" 150mgx10粒/盒(天津金耀氨基酸有限公司)", font3, bru, 0, 285); //e.Graphics.DrawString(" 22-1-1", font, bru, 0, 300); //e.Graphics.DrawString(" 22盒", font, bru, 150, 300); //e.Graphics.DrawString("2/2 复方磺胺甲噁唑片", font3, bru, 0, 320); //e.Graphics.DrawString(" 150mgx10粒/盒(天津金耀氨基酸有限公司)", font3, bru, 0, 335); //e.Graphics.DrawString(" 22-1-1", font, bru, 0, 350); //e.Graphics.DrawString(" 22盒", font, bru, 150, 350); e.Graphics.DrawString("=======================================", font, bru, 0, yPosition + 15); e.Graphics.DrawString(" 祝您早日康复", font3, bru, 0, yPosition + 30); e.Graphics.Dispose(); }