private void 新建NToolStripButton_Click(object sender, EventArgs e) { var result = MessageBox.Show("是否保存当前的方案?", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == System.Windows.Forms.DialogResult.Yes) { if (string.IsNullOrEmpty(this.CurrentPartyProject.Fullname)) { if (this.saveProjectDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.CurrentPartyProject.Fullname = this.saveProjectDlg.FileName; } else { return; } } this.CurrentPartyProject.Save(); this.UpdateTitle(this.CurrentPartyProject.Fullname); MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (result == System.Windows.Forms.DialogResult.Cancel) { return; } else { // nothing to do. } this.CurrentPartyProject = new PartyProject(); }
private void ReloadImage(PartyProject partyProject, int tableCount) { Bitmap image = partyProject.DumpBitmap(tableCount, this.CurrentFont, this.CurrentPen, this.CurrentBrush, this.showRectangle); Rectangle destRect = new Rectangle(0, 0, image.Width, image.Height); this.pictureBox1.BackgroundImage = image; }
public static PartyProject Parse(XElement xml) { if (xml == null || xml.Name != typeof(PartyProject).Name) { throw new ArgumentException(); } var result = new PartyProject(); int count = int.Parse(xml.Attribute(strCount).Value); result.Count = count; XElement leftDishList = xml.Element(strLeftDishes); foreach (var item in leftDishList.Elements(typeof(WeightedDish).Name)) { WeightedDish dish = WeightedDish.Parse(item); result.LeftDishList.Add(dish); } XElement rightDishList = xml.Element(strRightDishes); foreach (var item in rightDishList.Elements(typeof(WeightedDish).Name)) { WeightedDish dish = WeightedDish.Parse(item); result.RightDishList.Add(dish); } return(result); }
/// <summary> /// /// </summary> /// <param name="fullname"></param> /// <returns></returns> public static PartyProject Load(string fullname) { XElement xml = XElement.Load(fullname); PartyProject project = PartyProject.Parse(xml); project.Fullname = fullname; return(project); }
private void 另存为AToolStripMenuItem_Click(object sender, EventArgs e) { if (this.saveProjectDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string filename = this.saveProjectDlg.FileName; this.CurrentPartyProject.SaveAs(filename); this.CurrentPartyProject = PartyProject.Load(filename); MessageBox.Show("另存为成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PartyProject project = this.CurrentProject; if (project != null) { Bitmap image = project.DumpBitmap(this.TableCount, this.CurrentFont, this.CurrentPen, this.CurrentBrush, this.showRectangle); Rectangle destRect = new Rectangle(0, 0, image.Width, image.Height); e.Graphics.DrawImage(image, destRect, destRect, GraphicsUnit.Pixel); } }
private void 打开OToolStripButton_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { this.CurrentPartyProject = PartyProject.Load(this.openFileDialog1.FileName); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误"); } } }
private static void DrawDishes(PartyProject project, Font font, Pen pen, Brush brush, int x, int y, Graphics graphics, out float maxWidth, out float maxHeight) { string leftDishes = GetDishesString(project.LeftDishList); SizeF leftSize = graphics.MeasureString(leftDishes, font); string rightDishes = GetDishesString(project.RightDishList); SizeF rightSize = graphics.MeasureString(rightDishes, font); maxWidth = leftSize.Width > rightSize.Width ? leftSize.Width : rightSize.Width; maxHeight = leftSize.Height > rightSize.Height ? leftSize.Height : rightSize.Height; graphics.DrawString(leftDishes, font, brush, x * 2, y * 2); graphics.DrawRectangle(pen, x * 2, y * 2, maxWidth, maxHeight); graphics.DrawString(rightDishes, font, brush, x * 2 + maxWidth, y * 2); graphics.DrawRectangle(pen, x * 2 + maxWidth, y * 2, maxWidth, maxHeight); }
private void UpdateMenu(PartyProject partyProject) { this.numTableCount.Value = partyProject.Count; this.lstLeftDishes.Items.Clear(); this.lstRightDishes.Items.Clear(); for (int i = 0; i < partyProject.LeftDishList.Count; i++) { this.lstLeftDishes.Items.Add(partyProject.LeftDishList[i]); } for (int i = 0; i < partyProject.RightDishList.Count; i++) { this.lstRightDishes.Items.Add(partyProject.RightDishList[i]); } }
private void btnSavePicture_Click(object sender, EventArgs e) { PartyProject project = this.CurrentProject; if (project != null) { if (this.saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Bitmap image = project.DumpBitmap(this.TableCount, this.CurrentFont, this.CurrentPen, this.CurrentBrush, this.showRectangle); image.Save(this.saveFileDialog1.FileName); Process.Start("explorer", "/select," + this.saveFileDialog1.FileName); } } else { MessageBox.Show("没有指定方案,无法生成统计结果!"); } }
private static List <WeightedIngredient> GetIngredientList(PartyProject project) { var ingredientDict = new Dictionary <string, WeightedIngredient>(); foreach (var weightedDish in project.LeftDishList) { Calculate(ingredientDict, weightedDish); } foreach (var weightedDish in project.RightDishList) { Calculate(ingredientDict, weightedDish); } var list = (from item in ingredientDict.Values orderby item.Ingredient.Category.Priority ascending select item).ToList(); return(list); }
/// <summary> /// /// </summary> /// <param name="partyProject"></param> public FormPrintPreview(PartyProject partyProject, int tableCount) { InitializeComponent(); this.TableCount = tableCount; this.CurrentProject = partyProject; this.CurrentFont = new Font("仿宋", 22, GraphicsUnit.Pixel); this.CurrentBrush = new SolidBrush(Color.Black); this.CurrentPen = new Pen(this.CurrentBrush); foreach (PaperSize item in this.printDocument1.PrinterSettings.PaperSizes) { if (item.PaperName.Equals("A4")) { this.printDocument1.DefaultPageSettings.PaperSize = item; break; } } this.ReloadImage(this.CurrentProject, this.TableCount); }
/// <summary> /// /// </summary> /// <param name="project"></param> /// <param name="font"></param> /// <param name="brush"></param> /// <returns></returns> public static Bitmap DumpBitmap(this PartyProject project, int tableCount, Font font, Pen pen, Brush brush, bool showRectangle) { if (project == null) { return(null); } const int width = 827, height = 1169;// A4 const int x = 10, y = 10; var bitmap = new Bitmap(width, height); using (var graphics = Graphics.FromImage(bitmap)) { graphics.PageUnit = GraphicsUnit.Pixel; // 边线 DrawBounds(pen, width, height, x, y, graphics); // 左右两列菜品 float maxWidth, maxHeight; DrawDishes(project, font, pen, brush, x, y, graphics, out maxWidth, out maxHeight); // 所有的食材 List <WeightedIngredient> list = GetIngredientList(project); // 转化为待处理的Chunk List <ChunkBase> chunkList = GetChunkList(list, tableCount, font); // 页集合的上下文。 PagesContext context = GetPagesContext(width, height, x, y, maxWidth, maxHeight); // 处理:将Chunk放到正确的位置。 foreach (var item in chunkList) { item.Put(context); } // 根据Chunk记录的位置信息,画图。 Draw(chunkList, context, graphics, brush, showRectangle); } return(bitmap); }
public FormMain() { InitializeComponent(); this.CurrentPartyProject = new PartyProject(); this.grayBrush = new SolidBrush(Color.LightGray); this.CurrentFont = new Font("宋体", 32, GraphicsUnit.Pixel); this.CurrentBrush = new SolidBrush(Color.Black); this.CurrentPen = new Pen(this.CurrentBrush); foreach (PaperSize item in this.printDocument1.PrinterSettings.PaperSizes) { if (item.PaperName.Equals("A4")) { this.printDocument1.DefaultPageSettings.PaperSize = item; break; } } IngredientCategory.LoadDatabase(typeof(IngredientCategory).Name + ".xml"); IngredientUnit.LoadDatabase(typeof(IngredientUnit).Name + ".xml"); Ingredient.LoadDatabase(typeof(Ingredient).Name + ".xml"); Dish.LoadDatabase(typeof(Dish).Name + ".xml"); }