예제 #1
0
        // 輸出的Label[,] 放到tabPage.Tag去
        private void InitFoodMenu(TabPage tabPage, int menuId, out Label[,] FoodName)
        {
            SuspendLayout();
            string mark    = "F" + menuId.ToString() + DateTime.Now.Ticks.ToString(); //避免多次進入,label重名了
            int    WidthX  = (tabPage.Width - MyLayout.OffsetX) / MyLayout.NoX;
            int    HeightY = (tabPage.Height - MyLayout.OffsetY) / MyLayout.NoY;

            FoodName = new Label[MyLayout.NoX, MyLayout.NoY];
            int x, y;

            for (x = 0; x < MyLayout.NoX; x++)
            {
                for (y = 0; y < MyLayout.NoY; y++)
                {
                    int xx, yy;
                    xx = MyLayout.OffsetX + x * WidthX;
                    yy = MyLayout.OffsetY + y * HeightY;
                    Label l = new Label();
                    // Create Name Label
                    l = new Label();
                    FoodName[x, y] = l;
                    l.AutoSize     = false;
                    l.Location     = new System.Drawing.Point(xx, yy);
                    l.Name         = mark + "X" + x.ToString() + "Y" + y.ToString();
                    l.Size         = new System.Drawing.Size(WidthX - MyLayout.NoWidth - 2, HeightY - 2);
                    l.TabIndex     = 0;
                    MyProductRow Row = GetFoodMenuItem(menuId, x, y);
                    if (Row != null)
                    {
                        l.Tag = Row;
                        if (Row.IsNameNull())
                        {
                            l.Text = "";
                        }
                        else
                        {
                            l.Text = Row.Name.ToString();
                        }
                    }
                    else
                    {
                        l.Tag  = null;
                        l.Text = "";
                    }
                    l.DragEnter  += new DragEventHandler(this.LabelDragEnter);
                    l.DragLeave  += new EventHandler(this.LabelDragLeave);
                    l.DragDrop   += new DragEventHandler(LabelDragDrop);
                    l.MouseDown  += new MouseEventHandler(LabelMouseDown);
                    l.TextAlign   = System.Drawing.ContentAlignment.MiddleCenter;
                    l.BorderStyle = BorderStyle.Fixed3D;
                    l.AllowDrop   = true;
                    tabPage.Controls.Add(l);
                }
            }

            ResumeLayout();
            PerformLayout();
        }
예제 #2
0
        private void LabelDragDrop(object sender, DragEventArgs e)
        {
            Label label = sender as Label;

            label.BorderStyle = BorderStyle.Fixed3D;
            DragItem     item = e.Data.GetData(typeof(DragItem)) as DragItem;
            MyProductRow row  = item.row;

            if (label.Tag == row)
            {
                return;
            }
            label.Text      = item.ToString();
            label.BackColor = Color.SeaShell;
            label.Tag       = row;
            m_Modified      = true;
            if (item.label != null)
            {
                item.label.Text      = "";
                item.label.BackColor = Color.SeaShell;
                item.label.Tag       = null;
            }
            if (row == null)
            {
                return;
            }
            // Check duplicate
            int code = row.Code;

            Label[,] currentFoodTable = tabControl1.SelectedTab.Tag as Label[, ];    // FoodTable放到TabPage.Tag去
            foreach (Label l in currentFoodTable)
            {
                var ro = l.Tag as MyProductRow;      // Label[,]內的label.Tag放著ProductRow
                if (ro == null)
                {
                    continue;
                }
                if (l == label)
                {
                    continue;
                }
                if (ro.Code == code)
                {
                    l.Text      = "";
                    l.BackColor = Color.SeaShell;
                    l.Tag       = null;
                }
            }
        }
예제 #3
0
        private void LoadTabControlItem()
        {
            // 小於0的是菜單名負一排最前面
            var rows = from row in m_DataSet.Product
                       where row.Code < SpeicalRowCodeForMenu
                       orderby row.Code descending
                       select row;

            tabControl1.TabPages.Clear();
            if (rows.Count() == 0)   // 都沒有的話留下預設的
            {
                tabControl1.TabPages.Add("面包");

                int maxID = (from ro in m_DataSet.Product
                             select ro.ProductID).Max();
                MyProductRow row = m_DataSet.Product.NewProductRow();
                row.ProductID = ++maxID;
                row.Name      = SystemMenuName("面包", 1);
                row.Code      = -1;
                row.MenuX     = -1;
                row.MenuY     = -1;
                m_DataSet.Product.AddProductRow(row);
                SaveProduct();
            }
            else
            {
                String str;
                int    i;
                foreach (var row in rows)
                {
                    str = row.Name;
                    i   = str.IndexOf('_');  // 以底線做分割, 前面是菜單名
                    if (i > 1)
                    {
                        str = str.Substring(0, i);
                    }
                    tabControl1.TabPages.Add(str);
                }
            }
            foreach (TabPage page in tabControl1.TabPages)
            {
                page.BackColor = Color.Azure;
                page.Font      = new Font("標楷體", 14.25f);
            }
        }
예제 #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (m_Modified)
            {
                UpdateDataSet(tabControl1.SelectedIndex, tabControl1.SelectedTab.Tag as Label[, ]);
            }
            // <0的程式內用的,以Code比對
            var rows = from row in m_DataSet.Product
                       where row.Code == SpeicalRowCodeForMenu
                       select row;
            string reserved = "菜單寬高_勿動_程式用";

            if (rows.Count() == 0)
            {
                MyProductRow row = m_DataSet.Product.NewProductRow();
                row.MenuX = (short)-MyLayout.NoX;
                row.MenuY = (short)-MyLayout.NoY;
                row.Code  = SpeicalRowCodeForMenu;
                row.Name  = reserved;
                m_DataSet.Product.AddProductRow(row);
            }
            else
            {
                MyProductRow row = rows.First();
                short        x   = (short)-MyLayout.NoX;
                short        y   = (short)-MyLayout.NoY;
                if ((x != row.MenuX) || (y != row.MenuY))
                {
                    row.Name  = reserved;
                    row.MenuX = x;
                    row.MenuY = y;
                }
            }
            try
            {
                int i = productAdapter.Update(m_DataSet.Product);
                MessageBox.Show("存檔成功! 共更新 " + i.ToString() + "筆");
                UpdateAllFoodMenu();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + ex.Message);
            }
        }
예제 #5
0
        void RenewMenuSaveInProduct()
        {
            var rows = from row in m_DataSet.Product
                       where (row.RowState != DataRowState.Deleted) && (row.Code < SpeicalRowCodeForMenu)
                       select row;
            int i = 0;

            foreach (MyProductRow row in rows)
            {
                if (i >= tabControl1.TabCount)
                {
                    row.Delete();
                    continue;
                }
                TabPage page = tabControl1.TabPages[i];
                i++;
                row.Name  = SystemMenuName(page.Text, i);
                row.Code  = -i;
                row.MenuX = -1;
                row.MenuY = -1;
            }
            if (i < tabControl1.TabCount)
            {
                int maxID = (from row in m_DataSet.Product
                             where row.RowState != DataRowState.Deleted
                             select row.ProductID).Max();
                for (; i < tabControl1.TabCount;)
                {
                    MyProductRow row  = m_DataSet.Product.NewProductRow();
                    TabPage      page = tabControl1.TabPages[i];
                    row.ProductID = ++maxID;
                    i++;
                    row.Name  = SystemMenuName(page.Text, i);
                    row.Code  = -i;
                    row.MenuX = -1;
                    row.MenuY = -1;
                    m_DataSet.Product.AddProductRow(row);
                }
            }
            SaveProduct();
            LoadTabControlItem();
            UpdateAllFoodMenu();
        }
예제 #6
0
 public DragItem(Label l, MyProductRow r)
 {
     label = l;
     row   = r;
     X     = Y = -1;
 }