示例#1
0
        private void accountingTitleBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            if (MyFunction.LockAll)
            {
                MessageBox.Show("鎖定中,不能存檔");
                return;
            }
            // 因為可以只編名稱,沒填代碼,又不能加在RowValidating (在刪除時,index會放在新row會出錯)

/*
 *          string error = "";
 *          DataGridView view = (DataGridView)this.accountingTitleDataGridView;
 *          for(int i=0;i<view.Rows.Count;i++)
 *          {
 *              DataGridViewRow row=view.Rows[i];
 *              if (!ValidateTitleCode(row.Cells["TitleCode"].FormattedValue, out error))
 *              {
 *                  MessageBox.Show("第" + (i+1).ToString() + "行" + error);
 *                  return;
 *              }
 *          }
 */
            DamaiDataSet.AccountingTitleDataTable table = MyFunction.SaveCheck <DamaiDataSet.AccountingTitleDataTable>(
                this, accountingTitleBindingSource, damaiDataSet.AccountingTitle);
            if (table == null)
            {
                return;
            }
            MyFunction.SetGlobalFlag(GlobalFlag.basicDataModified);

            foreach (DamaiDataSet.AccountingTitleRow r in table)
            {
                if (r.RowState != DataRowState.Deleted)
                {
                    r.BeginEdit();
                    r.LastUpdated = DateTime.Now;
                    if (!r.IsNameNull())
                    {
                        r.Name = r.Name.Trim();
                    }
                    r.TitleCode = r.TitleCode.Trim();
                    r.EndEdit();
                }
            }
            damaiDataSet.AccountingTitle.Merge(table);
            this.accountingTitleSQLAdapter.Update(this.damaiDataSet.AccountingTitle);
            damaiDataSet.AccountingTitle.AcceptChanges();
        }
示例#2
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
//            MyFunction.AddNewItem(dataGridView1, "ColumnProductID","ProductID", bakeryOrderSet.Product);
            int max       = (from row in m_DataSet.Product select row.ProductID).Max();
            int productID = MyFunction.SetCellMaxNo("ColumnProductID", dataGridView1, max);

            productIDTextBox.Text = productID.ToString();
            string code = MaxNoInDGView("codeColumn", dataGridView1).ToString();

            codeTextBox.Text            = code;
            nameTextBox.Text            = "产品" + code;
            priceTextBox.Text           = "0";
            classComboBox.SelectedValue = 1;
            menuXTextBox.Text           = "-2";
            menuYTextBox.Text           = "0";
        }
示例#3
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            MyFunction.AddNewItem(this.apartmentDataGridView, "columnApartmentID", "ApartmentID", this.damaiDataSet.Apartment);
            DataGridViewRow row = apartmentDataGridView.CurrentRow;             // 剛被新增那行一定是CurrentRow

            foreach (string s in ColumnsEncryted)
            {
                try
                {
                    row.Cells[s].Value = "";      // 因為在ColumnsEncrypted內的欄位在SQLDB內都被定義成不准NULL,所以必需填值
                }
                catch (Exception ex)
                {
                    MessageBox.Show("DataGridView欄位<" + s + ">設定初值失敗!程式錯誤,請將本訊息通知碼農修正錯誤!");
                }
            }
        }
示例#4
0
        MonthlyReportData CalcRevenue(int month)
        {
            int year = Revenue.Year;

            if (month < 1 || month > 12)
            {
                MessageBox.Show("所選月份不對!");
                return(null);
            }
            Message("計算 " + month.ToString() + "月營業額");
            if (RevenueCache[month - 1] != null)
            {
                return(RevenueCache[month - 1]);
            }
            int count = MyFunction.DayCountOfMonth(month);

            progressBar1.Minimum = 0;
            progressBar1.Maximum = count;
            progressBar1.Value   = 0;
            progressBar1.Visible = true;
            List <MonthlyReportData> list = new List <MonthlyReportData>();

            for (int i = 1; i <= count; i++)
            {
                if (Revenue.LoadData(m_OrderSet, month, i))
                {
                    list.Add(Revenue.Statics(m_OrderSet));
                }
                progressBar1.Value = i;
                Application.DoEvents();
            }
            progressBar1.Visible = false;
            MonthlyReportData total = new MonthlyReportData();

            foreach (MonthlyReportData d in list)
            {
                total.Revenue    += d.Revenue;
                total.OrderCount += d.OrderCount;
                total.Cash       += d.Cash;
                total.CreditCard += d.CreditCard;
            }
            RevenueCache[month - 1] = total;       // 存到Cache裏
            return(total);
        }
示例#5
0
        // RevenueCalc需要Header.Date 己經在FormLoad時給值
        MonthlyReportData CalcRevenue(int month, out List <MonthlyReportData> reportList)
        {
            int year = m_Revenue.Year;

            reportList = null;
            if (month < 1 || month > 12)
            {
                MessageBox.Show("所選月份不對!");
                return(null);
            }
            labelMessage.Text = "計算 " + month.ToString() + "月營業額";
            //if (RevenueCache[month - 1] != null)    // 不能用Cache了
            //    return RevenueCache[month - 1];
            int count = MyFunction.DayCountOfMonth(month);

            progressBar1.Minimum = 0;
            progressBar1.Maximum = count;
            progressBar1.Value   = 0;
            progressBar1.Visible = true;
            List <MonthlyReportData> list = new List <MonthlyReportData>();

            for (int i = 1; i <= count; i++)
            {
                if (m_Revenue.LoadData(damaiDataSet, month, i))
                {
                    list.Add(m_Revenue.Statics(damaiDataSet));
                }
                progressBar1.Value = i;
                Application.DoEvents();
            }
            progressBar1.Visible = false;
            MonthlyReportData total = new MonthlyReportData();

            foreach (MonthlyReportData d in list)
            {
                total.Revenue    += d.Revenue;
                total.OrderCount += d.OrderCount;
                total.Cash       += d.Cash;
                total.CreditCard += d.CreditCard;
                total.Alipay     += d.Alipay;
            }
            reportList = list;
            return(total);
        }
示例#6
0
        private void comboBoxMonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox box = (ComboBox)sender;

            int month = box.SelectedIndex;

            if (month == 0)
            {
                this.accVoucherBindingSource.Filter = null;
                this.accVoucherDataGridView.Focus();
                return;
            }
            if (month < 1 || month > 12)
            {
                return;
            }
            SetDayFilter(month, 1, MyFunction.DayCountOfMonth(month));
            this.accVoucherDataGridView.Focus();
        }
示例#7
0
        private void expenseBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            if (MyFunction.LockAll)
            {
                MessageBox.Show("鎖定中,不能存檔");
                return;
            }
            if (!this.Validate())
            {
                MessageBox.Show("有資料錯誤, 請改好再存!");
                return;
            }
            this.expenseBindingSource.EndEdit();

            var table = (MyExpenseTable)m_DataSet.Expense.GetChanges();

            if (table == null)
            {
                MessageBox.Show("沒有改動任何資料! 不用存");
                return;
            }
            if (checkMode) // 讓Form Expense Reload
            {
                MyFunction.SetGlobalFlag(GlobalFlag.employeeModified);
            }
            else
            {
                foreach (var r in table)
                {
                    if (r.RowState != DataRowState.Deleted)
                    {
                        r.BeginEdit();
                        r.KeyinID     = MyFunction.OperatorID;
                        r.LastUpdated = DateTime.Now;
                        r.EndEdit();
                    }
                }
            }
            m_DataSet.Expense.Merge(table);
            expenseAdapter.Update(m_DataSet.Expense);
            m_DataSet.Expense.AcceptChanges();
        }
示例#8
0
        private void FormOperator_Load(object sender, EventArgs e)
        {
            try
            {
                operatorAdapter.Connection.ConnectionString = DB.SqlConnectString(MyFunction.HardwareCfg);
                authListAdapter.Connection.ConnectionString = DB.SqlConnectString(MyFunction.HardwareCfg);

                operatorAdapter.Fill(m_DataSet.Operator);
                authListAdapter.Fill(m_DataSet.OperatorAuthList);
                var apartment = new DamaiDataSetTableAdapters.ApartmentTableAdapter();
                apartment.Connection.ConnectionString = DB.SqlConnectString(MyFunction.HardwareCfg);
                apartment.Fill(m_DataSet.Apartment);
                this.operatorBindingSource.DataSource = m_DataSet;
                MyFunction.SetFieldLength(operatorDataGridView, m_DataSet.Operator);
            }
            catch (Exception ex)
            {
                MessageBox.Show("載入操作員權限錯誤:" + ex.Message);
            }
        }
示例#9
0
        private void FormHR_Load(object sender, EventArgs e)
        {
            SetupBindingSource();
            dgvHRDetail.DataSource = fKHRDetailHRBindingSource;

            var operatorAdapter  = new VoucherExpense.DamaiDataSetTableAdapters.OperatorTableAdapter();
            var apartmentAdapter = new VoucherExpense.DamaiDataSetTableAdapters.ApartmentTableAdapter();

            operatorAdapter.Connection.ConnectionString  = DB.SqlConnectString(MyFunction.HardwareCfg);
            apartmentAdapter.Connection.ConnectionString = DB.SqlConnectString(MyFunction.HardwareCfg);

            Try(() => operatorAdapter.Fill(m_DataSet.Operator));
            Try(() => apartmentAdapter.Fill(m_DataSet.Apartment));
            Try(() => HRAdapter.Fill(m_DataSet.HR));
            Try(() => HRDetailAdapter.Fill(m_DataSet.HRDetail));
            MyFunction.SetFieldLength(dgvHR, m_DataSet.HR);
            MyFunction.SetFieldLength(dgvHRDetail, m_DataSet.HRDetail);
            MyFunction.SetControlLengthFromDB(this, m_DataSet.HR);
            checkBoxShowAll.Checked = false;
        }
示例#10
0
        private void cbBoxMonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox box   = (ComboBox)sender;
            int      month = box.SelectedIndex;

            if (month < 0 || month >= 12)
            {
                return;
            }

            int count = MyFunction.DayCountOfMonth(month + 1);

            cbBoxDay.Items.Clear();
            int result;

            for (int i = 1; i <= count; i++)
            {
                result = cbBoxDay.Items.Add(i.ToString() + "日");
            }
            cbBoxDay.SelectedIndex = 0;
        }
示例#11
0
 private void FormApartment_Load(object sender, EventArgs e)
 {
     try
     {
         apartmentSQLAdapter.Connection.ConnectionString = DB.SqlConnectString(MyFunction.HardwareCfg);
         this.apartmentSQLAdapter.Fill(this.damaiDataSet.Apartment);
         foreach (var encryptedRow in damaiDataSet.Apartment)
         {
             var decryptedRow = decryptedDataSet.Apartment.NewApartmentRow();
             CopyDecryptApartment(encryptedRow, decryptedRow);
             decryptedDataSet.Apartment.AddApartmentRow(decryptedRow);
         }
         decryptedDataSet.Apartment.AcceptChanges();
         this.apartmentBindingSource.DataSource = decryptedDataSet;
         MyFunction.SetFieldLength(apartmentDataGridView, damaiDataSet.Apartment);
     }
     catch (Exception ex)
     {
         MessageBox.Show("讀取部門資料庫錯誤:" + ex.Message);
     }
 }
示例#12
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            if (MyFunction.LockAll)
            {
                MessageBox.Show("鎖定中,新增無用");
            }
            int m = MyFunction.MaxNoInDB("ID", m_DataSet.AccVoucher);

            MyFunction.SetCellMaxNo("columnID", accVoucherDataGridView, m);
            int month = comboBoxMonth.SelectedIndex;
            int mon;

            if (month >= 1 && month <= 12)
            {
                mon = month;
            }
            else
            {
                mon = DateTime.Now.Month;
            }
            DateTime        t   = new DateTime(DateTime.Now.Year, mon, MyFunction.DayCountOfMonth(mon));
            DataGridViewRow row = accVoucherDataGridView.CurrentRow;

            // DataGridView和textBox都設定, 以免日期是空白,日期排序,會跑到最前面
            row.Cells["columnAccVoucherTime"].Value = accVoucherTimeTextBox.Text = t.ToShortDateString();
            try
            {
                DataRowView rv = row.DataBoundItem as DataRowView;
                var         d  = (MyAccVoucherRow)rv.Row;
                d.IsDebt0 = true;
                d.IsDebt1 = d.IsDebt2 = d.IsDebt3 = false;
                SetAllDebtCreditBtn(d);
                CalcTotal(d);
            }
            catch { }


            MessageBox.Show("日期己暫時設定, 請設成正確日期!");
            lockedCheckBox.Checked = false;
        }
示例#13
0
        private bool addNew(int month, int productClass)
        {
            int ma = MyFunction.MaxNoInDB("ID", damaiDataSet.Shipment);
            int i  = MyFunction.SetCellMaxNo("ColumnID", shipmentDataGridView, ma);

            if (i > 0)
            {
                this.iDLabel1.Text = i.ToString();

                //removedCheckBox.Checked = false;                           // 只有對DateTime的Binding會受影響, bool不會,所以可以放ResetBindings前
                //checkedCheckBox.Checked = false;
                // 這行加了會把stockTimeTextBox.Text和entryTimeTextBox.Text給清成空白,所以放前面
                if (CreateNewShipmentDetailDataTable(i, productClass).Count == 0)
                {
                    return(false);
                }
                foreach (var item in CreateNewShipmentDetailDataTable(i, productClass))
                {
                    DamaiDataSet.ShipmentDetailRow r;
                    r = item;
                    this.damaiDataSet.ShipmentDetail.ImportRow(r);
                }
                this.shipmentBindingSource.ResetBindings(false);
                this.shipmentDetailBindingSource.ResetBindings(false);   // 有id了,可以刷新下面的detail表
                removedCheckBox.Checked   = false;
                checkedCheckBox.Checked   = false;
                this.shipCodeTextBox.Text = GetShipCode(month);
                // 初始時間, 放在ResetBindings後面
                int      year = MyFunction.IntHeaderYear;
                DateTime t    = DateTime.Now;
                disableDateTimePicker      = true;
                this.dateTimePicker1.Value = new DateTime(year, month, 1);     // 代入的是資料庫的年份,選的月份
                disableDateTimePicker      = false;
                // 有選月份時,先強設日期,否則在當月看不到
                DateTime stockTime = new DateTime(year, month, MyFunction.DayCountOfMonth(month));   // 資料月份,設成該月最後一天
                shipTimeTextBox.Text = stockTime.ToShortDateString();
                return(true);
            }
            return(false);
        }
示例#14
0
 private void vendorBindingNavigatorSaveItem_Click(object sender, EventArgs e)
 {
     DamaiDataSet.VendorDataTable table = MyFunction.SaveCheck <DamaiDataSet.VendorDataTable>(
         this, vendorBindingSource, damaiDataSet.Vendor);
     if (table == null)
     {
         return;
     }
     MyFunction.SetGlobalFlag(GlobalFlag.basicDataModified);
     foreach (DamaiDataSet.VendorRow r in table)
     {
         if (r.RowState != DataRowState.Deleted)
         {
             r.BeginEdit();
             r.LastUpdated = DateTime.Now;
             r.EndEdit();
         }
     }
     damaiDataSet.Vendor.Merge(table);
     this.vendorSQLAdapter.Update(damaiDataSet.Vendor);
     damaiDataSet.Vendor.AcceptChanges();
 }
示例#15
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
//            MyFunction.AddNewItem(dgvIngredient, "columnIngredientID","IngredientID", vEDataSet.Ingredient);
            IngredientBindingSource.AddNew();
            int max          = (from ro in m_DataSet.Ingredient select ro.IngredientID).Max();
            int ingredientID = MyFunction.SetCellMaxNo("columnIngredientID", dgvIngredient, max);

            // 因為供應商資料沒有ValueMember啟始值,只Binding了SelectedValue
            // 所以後來 BindingSource.EndEdit時,無法成功==> RowState還是Detached,永遠無法改


            // 測試方案1:硬上,自己加.   EditBakeryProduct.cs的處理方式比較文明, 每個Field都在螢幕上填值
            //DataRowView rowView = (DataRowView)IngredientBindingSource.Current;
            //VEDataSet.IngredientRow row = (VEDataSet.IngredientRow)rowView.Row;
            //if (row.RowState == DataRowState.Detached)
            //    vEDataSet.Ingredient.Rows.Add(row);

            DataRowView rowView = (DataRowView)IngredientBindingSource.Current;
            var         row     = (MyIngredientRow)rowView.Row;

            row.CanPurchase = true;
        }
示例#16
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            if (MyFunction.LockAll)
            {
                MessageBox.Show("鎖定中,新增無用");
            }
            if (checkBoxSort.Checked)
            {
                checkBoxSort.Checked = false;
            }
            MyFunction.AddNewItem(dgvBankDetail, "columnID", "ID", m_DataSet.BankDetail);
            DataGridViewRow  row  = dgvBankDetail.CurrentRow;
            DataGridViewCell cell = row.Cells["columnAccount"];

            if (cbSelectBank.SelectedIndex < 1)   // 第一個是 全部
            {
                MessageBox.Show("未選戶頭! 己預設");
                cell.Value = 2;
                return;
            }
            cell.Value = cbSelectBank.SelectedValue;
        }
示例#17
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            if (MyFunction.LockAll)
            {
                MessageBox.Show("鎖定中,新增無用");
            }
            int month = comboBoxMonth.SelectedIndex;

            if (month < 1 || month > 12)
            {
                month = DateTime.Now.Month;
                MessageBox.Show("你未選擇月份, 電腦設定新增為<" + month.ToString() + "月>單子!");
            }

//            int count=this.voucherBindingNavigator.PositionItem.
            int ma = MyFunction.MaxNoInDB("ID", m_DataSet.Voucher);
            int i  = MyFunction.SetCellMaxNo("columnID", dgvVoucher, ma);

            if (i > 0)
            {
                this.iDTextBox.Text = i.ToString();
                this.voucherBindingSource.ResetBindings(false);                 // 這行加了會把stockTimeTextBox.Text和entryTimeTextBox.Text給清成空白,所以放前面
                this.voucherVoucherDetailSqlBindingSource.ResetBindings(false); // 有id了,可以刷新下面的detail表

                lockedCheckBox.Checked = false;                                 // 只有對DateTime的Binding會受影響, bool不會,所以可以放ResetBindings前
                // 初始時間, 放在ResetBindings後面
                int      year = MyFunction.IntHeaderYear;
                DateTime t    = DateTime.Now;
                entryTimeTextBox.Text      = t.ToString();
                disableDateTimePicker      = true;
                this.dateTimePicker1.Value = new DateTime(year, month, 1);     // 代入的是資料庫的年份,選的月份
                disableDateTimePicker      = false;
                // 有選月份時,先強設日期,否則在當月看不到
                DateTime stockTime = new DateTime(year, month, MyFunction.DayCountOfMonth(month));   // 資料月份,設成該月最後一天
                stockTimeTextBox.Text = stockTime.ToShortDateString();
                MessageBox.Show("進貨日期己暫時設定, 請設成正確日期!");
            }
        }
示例#18
0
        private void cbBoxMonthTo_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox box   = (ComboBox)sender;
            int      month = box.SelectedIndex;

            if (month < 1 || month > 12)
            {
                return;
            }
            int count = MyFunction.DayCountOfMonth(month);

            cbBoxTo.Items.Clear();
            for (int i = 1; i <= count; i++)
            {
                cbBoxTo.Items.Add(i.ToString() + "日");
            }
            cbBoxTo.SelectedIndex = count - 1;
            if (month < cbBoxMonth.SelectedIndex)
            {
                cbBoxMonth.SelectedIndex = month;
            }
            btnPrint.Enabled = false;
        }
示例#19
0
        private void Ingredient_Load(object sender, EventArgs e)
        {
            IngredientBindingSource.DataSource      = m_DataSet;
            vendorBindingSource.DataSource          = m_DataSet;
            accountingTitleBindingSource.DataSource = m_DataSet;
            m_PhotoDirectoryExist   = Directory.Exists(PhotoPath());
            photoPictureBox.Visible = true;
            var vendorAdapter          = new DamaiDataSetTableAdapters.VendorTableAdapter();
            var accountingTitleAdapter = new DamaiDataSetTableAdapters.AccountingTitleTableAdapter();

            IngredientAdapter.Connection.ConnectionString      = DB.SqlConnectString(MyFunction.HardwareCfg);
            vendorAdapter.Connection.ConnectionString          = DB.SqlConnectString(MyFunction.HardwareCfg);
            PhotoAdapter.Connection.ConnectionString           = DB.SqlConnectString(MyFunction.HardwareCfg);
            accountingTitleAdapter.Connection.ConnectionString = DB.SqlConnectString(MyFunction.HardwareCfg);

            try
            {
                vendorAdapter.Fill(m_DataSet.Vendor);
                m_VendorList.Add(new CNameIDForComboBox(0, ""));                                // 提到 .Fill(vEdataSet.Ingredient)之前,要不然第一次 BindingSource.CurrentChanged會先發生
                foreach (var vendor in m_DataSet.Vendor)
                {
                    m_VendorList.Add(new CNameIDForComboBox(vendor.VendorID, vendor.Name));
                }
                vendorIDComboBox.DataSource = m_VendorList;
                //vendorIDComboBox.ValueMember = "ID";
                //vendorIDComboBox.DisplayMember = "Name";
                accountingTitleAdapter.Fill(m_DataSet.AccountingTitle);
                IngredientAdapter.Fill(m_DataSet.Ingredient);
            }
            catch (Exception ex)
            {
                MessageBox.Show("錯誤:" + ex.Message);
            }

            MyFunction.SetFieldLength(dgvIngredient, m_DataSet.Ingredient);
            MyFunction.SetControlLengthFromDB(this, m_DataSet.Ingredient);
        }
示例#20
0
        private void comboBoxMonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox box = (ComboBox)sender;

            int month = box.SelectedIndex;

            if (month == 0)
            {
                DayFilter             = null;
                m_DisableIndexChanged = true;
                SetFilter(DayFilter, BankFilter);
                CalcTotal();
                this.expenseDataGridView.Focus();
                return;
            }
            if (month < 1 || month > 12)
            {
                return;
            }

            int count = MyFunction.DayCountOfMonth(month);

            cbBoxFrom.Items.Clear();
            cbBoxTo.Items.Clear();
            for (int i = 1; i <= count; i++)
            {
                cbBoxFrom.Items.Add(i.ToString() + "日");
                cbBoxTo.Items.Add(i.ToString() + "日");
            }
            m_DisableIndexChanged   = true;
            cbBoxFrom.SelectedIndex = 0;
            cbBoxTo.SelectedIndex   = count - 1;
            m_DisableIndexChanged   = false;
            SetDayFilter(month, 1, count);
            SetAccTitleFilter();
            this.expenseDataGridView.Focus();
        }
示例#21
0
        private MyDataSet.PhotosRow SavePhotoFileToDB(string fileName, int id, short tableID, int width, int height, MyDataSet.PhotosRow photo) // photo==null 就新增
        {
            Cursor = Cursors.WaitCursor;
            MD5 MD5Provider = new MD5CryptoServiceProvider();

            try
            {
                Bitmap       img    = (Bitmap)(Bitmap.FromFile(fileName));
                Bitmap       shrank = MyFunction.ShrinkBitmap(img, width, height); // 使用SQLServer時,只存縮圖以節省網路傳輸時間, 產品統一尺寸 W240 H160
                MemoryStream stream = new MemoryStream();
                shrank.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                if (photo == null)
                {
                    photo             = m_DataSet.Photos.NewPhotosRow();
                    photo.TableID     = tableID;
                    photo.PhotoID     = id;
                    photo.Photo       = stream.ToArray();
                    photo.UpdatedTime = DateTime.Now;
                    photo.MD5         = MD5Provider.ComputeHash(photo.Photo);
                    m_DataSet.Photos.AddPhotosRow(photo);
                }
                else
                {
                    photo.Photo       = stream.ToArray();
                    photo.UpdatedTime = DateTime.Now;
                    photo.MD5         = MD5Provider.ComputeHash(photo.Photo);
                }
                PhotoAdapter.Update(m_DataSet.Photos);
            }
            catch (Exception ex)
            {
                MessageBox.Show("存配方照片<" + id.ToString() + ">時出錯!原因:" + ex.Message);
            }
            Cursor = Cursors.Arrow;
            return(photo);
        }
示例#22
0
        private decimal CalcSaleList(int month)
        {
            if (month < 1 || month > 12)
            {
                MessageBox.Show("所選月份<" + month.ToString() + ">不對!");
                return(0);
            }
            int count = m_SaleList.Count;

            if (count <= 1)
            {
                return(0);
            }
            int year = MyFunction.IntHeaderYear;
            int to   = MyFunction.DayCountOfMonth(month);

            if (month == 2 && DateTime.IsLeapYear(year))
            {
                to = 29;
            }
            LoadData(month, 1, to);    // 一律稅控制
            foreach (CSaleItem m in m_SaleList)
            {
                m.Total  = 0;
                m.Volume = 0;
            }
            bool[] debug = new bool[count];   // items code會重複, 不知為何 ,只好用此辦法
            foreach (var row in m_OrderSet.Order)
            {
                var items = row.GetOrderItemRows();
                for (int i = 0; i < count; i++)
                {
                    debug[i] = false;
                }
                foreach (var it in items)
                {
                    for (int i = 0; i < m_SaleList.Count; i++)
                    {
                        CSaleItem m = m_SaleList[i];
                        if (m.ProductID == it.ProductID)
                        {
                            if (debug[i])
                            {
                                break;                  // 重複算了二次, items存入有bug,只好先跳掉
                            }
                            debug[i]  = true;
                            m.Volume += it.No;
                            if (it.Discount)
                            {
                                m.Total += it.Price * it.No * 0.88m;
                            }
                            else
                            {
                                m.Total += it.Price * it.No;
                            }
                            break;
                        }
                    }
                }
            }
            decimal sum = 0;

            foreach (CSaleItem item in m_SaleList)
            {
                sum += item.Total;
            }
            return(sum);

            //            materialBindingSource.ResetBindings(false);
            //            Text = "物料統計 " + month.ToString() + "月 " + from.ToString() + "日 至 " + to.ToString() + "日";
            //            if (ckBoxUse12.Checked) Text += "  稅控制";
        }
示例#23
0
        private void btnExport2Excel_Click(object sender, EventArgs e)
        {
            if (m_SelectedMonth < 0)
            {
                labelMessage.Text = "請先選擇月份!!";
                return;
            }
            Excel.Application excel;
            Excel.Worksheet   sheet;
            Excel.Workbook    book;
            try
            {
                excel = new Excel.Application();
                book  = excel.Application.Workbooks.Add(true);
                sheet = book.Worksheets[1];
                DataRowView rowView = comboBoxAccTitle.SelectedItem as DataRowView;
                DamaiDataSet.AccountingTitleRow row = rowView.Row as DamaiDataSet.AccountingTitleRow;
                sheet.Name = comboBoxMonth.SelectedItem.ToString() + "  " + row.Name;
            }
            catch (Exception ex)
            {
                MessageBox.Show("開啟Excel出錯,原因:" + ex.Message);
                return;
            }
            excel.Visible = true;
            DataGridView view = dgvCLedgerTable;

            Excel.Range range;
            int         i = 1;
            // 插入Logo圖片
            int imgHeight = 48;

            range           = sheet.Rows[1];
            range.RowHeight = imgHeight + 2;
            Bitmap img = MyFunction.GetThumbnail(global::VoucherExpense.Properties.Resources.LogoVI, imgHeight * 4 / 3);   // 一般圖是96DPI,換算就是4pixels=3單位

            range = sheet.Cells[1, 1];
            Clipboard.SetDataObject(img, true);
            sheet.Paste(range, "LogoVI");

            range = sheet.Cells[1, 3];
            range.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
            sheet.Cells[1, 3]         = sheet.Name + "  分類帳";
            range.Select();

            //欄位表頭
            i++;

            sheet.Cells[i, 1]         = "日期";
            range                     = sheet.Columns[1];
            range.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
            range.ColumnWidth         = 10;

            sheet.Cells[i, 2] = "摘要";
            range             = sheet.Columns[2];
            range.ColumnWidth = 30;

            sheet.Cells[i, 3]         = "借方";
            range                     = sheet.Columns[3];
            range.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
            range.ColumnWidth         = 10;
            range.NumberFormat        = "#,##0.00";

            sheet.Cells[i, 4]         = "貸方";
            range                     = sheet.Columns[4];
            range.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
            range.ColumnWidth         = 10;
            range.NumberFormat        = "#,##0.00"; // "0.00";

            sheet.Cells[i, 5]         = "餘額";
            range                     = sheet.Columns[5];
            range.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
            range.ColumnWidth         = 10;
            range.NumberFormat        = "#,##0.00";

            sheet.Cells[i, 6] = "科目";
            range             = sheet.Columns[6];
            range.ColumnWidth = 10;



            i++;
            foreach (DataGridViewRow vr in view.Rows)
            {
                sheet.Cells[i, 1] = vr.Cells[0].FormattedValue;         // 日期
                sheet.Cells[i, 2] = "'" + vr.Cells[1].FormattedValue;   // 摘要
                sheet.Cells[i, 3] = vr.Cells[2].FormattedValue;         // 借方
                sheet.Cells[i, 4] = vr.Cells[3].FormattedValue;         // 貸方
                sheet.Cells[i, 5] = vr.Cells[4].FormattedValue;         // 餘額
                sheet.Cells[i, 6] = vr.Cells[5].FormattedValue;         // 對沖科目

                //DataRowView rowView = vr.DataBoundItem as DataRowView;
                //VEDataSet.ExpenseRow row =  rowView.Row as VEDataSet.ExpenseRow;
                //if (!row.IsInnerIDNull())   sheet.Cells[i, 1] = row.InnerID;
                //                            sheet.Cells[i, 2] = row.ApplyTime;
                //if (!row.IsNoteNull())      sheet.Cells[i, 3] = row.Note;
                //if (!row.IsTitleCodeNull()) sheet.Cells[i, 4] = "'"+row.TitleCode.ToString();
                //if (!row.IsMoneyNull())     sheet.Cells[i, 5] = row.Money;
                //if (!row.IsApplierIDNull())
                //{
                //    sheet.Cells[i, 6] = row.ApplierID;
                //}
                i++;
            }
            sheet.Cells[i++, 2] = "'================================================";
            excel.Quit();
        }
示例#24
0
 private void priceTextBox_Validating(object sender, CancelEventArgs e)
 {
     e.Cancel = !MyFunction.UintValidate(((TextBox)sender).Text);
 }
示例#25
0
 private void unitVolumeTextBox_Validating(object sender, CancelEventArgs e)
 {
     e.Cancel = !MyFunction.DecimalValidate(((TextBox)sender).Text);
 }
示例#26
0
 private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
 {
     MyFunction.AddNewItem(vendorDataGridView, "columnVendorID", "VendorID", damaiDataSet.Vendor);
 }
示例#27
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            DateTime       maxDate   = new DateTime(MyFunction.IntHeaderYear, 1, 1);
            MyInventoryRow rowIsnull = null;

            foreach (var r in m_DataSet.Inventory)
            {
                rowIsnull = r;
                if (r.RowState == DataRowState.Deleted)
                {
                    continue;
                }
                if (!r.IsCheckDayNull())
                {
                    if (r.CheckDay >= maxDate)
                    {
                        maxDate = r.CheckDay.AddDays(1);                        // 設定盤點日為最大那張的加一天
                    }
                }
                if (r.Locked)
                {
                    continue;
                }
                MessageBox.Show("有尚未核可的單子,無法新增盤點表!");
                return;
            }
            if (rowIsnull == null)
            {
                MessageBox.Show("初值,请输入食材的盘点、金额和产品的本期");
                prevVolumeColumn.Visible         = false;
                dgvColumnCurrentIn.Visible       = false;
                dgvColumnPrevStockVolume.Visible = false;
                StockMoneyColumn.ReadOnly        = false;
                dgvColumnLostMoney.Visible       = false;
                isFrist = true;
            }
            else
            {
                prevVolumeColumn.Visible         = true;
                dgvColumnCurrentIn.Visible       = true;
                dgvColumnPrevStockVolume.Visible = true;
                StockMoneyColumn.ReadOnly        = true;
                dgvColumnLostMoney.Visible       = true;
                isFrist = false;
            }
            if (maxDate.Year != MyFunction.IntHeaderYear)
            {
                MessageBox.Show("預計的盤點日超過資料年<" + MyFunction.HeaderYear + ">");
                return;
            }
            this.inventoryBindingSource.AddNew();
            DataGridViewRow  row  = dgvInventories.CurrentRow;
            DataGridViewCell cell = row.Cells["ColumnInventoryID"];

            if (cell == null)
            {
                MessageBox.Show("程式或資料庫版本錯誤, <dgvInventories>沒有<ColumnInventoryID>!");
                return;
            }
            if (Convert.IsDBNull(cell.Value))
            {
                try
                {
                    MyFunction.AddNewItem(dgvInventories, "ColumnInventoryID", "InventoryID", m_DataSet.Inventory);
                    bindingNavigatorAddNewItem.Enabled = false;
                    DataRowView rowView = row.DataBoundItem as DataRowView;
                    var         data    = rowView.Row as MyInventoryRow;
                    data.CheckDay = maxDate;       // 盤點日
                    int inventoryID = data.InventoryID;

                    // 從食材表中有Code的,加入vEDataSet.InventoryDetail
                    foreach (var ingredient in m_DataSet.Ingredient)
                    {
                        if (ingredient.IsCodeNull())
                        {
                            continue;
                        }
                        if (ingredient.Code <= 0)
                        {
                            continue;                              // 無代号食材不納入盤點
                        }
                        var detail = m_DataSet.InventoryDetail.NewInventoryDetailRow();
                        detail.ID           = Guid.NewGuid();
                        detail.IngredientID = ingredient.IngredientID;
                        detail.InventoryID  = inventoryID;
                        m_DataSet.InventoryDetail.AddInventoryDetailRow(detail);
                    }
                    // 產品表中有Code的,加入vEDataSet.InventoryProducts
                    foreach (var product in m_OrderSet.Product)
                    {
                        if (product.IsClassNull())
                        {
                            continue;
                        }
                        if (product.Code <= 0)
                        {
                            continue;
                        }
                        var inventoryProducts = m_DataSet.InventoryProducts.NewInventoryProductsRow();
                        inventoryProducts.ID          = Guid.NewGuid();
                        inventoryProducts.ProductID   = product.ProductID;
                        inventoryProducts.InventoryID = inventoryID;
                        m_DataSet.InventoryProducts.AddInventoryProductsRow(inventoryProducts);
                    }

                    inventoryBindingSource.ResetBindings(false);  // inventoryDetailBindingSource 會連動,不用自己呼叫
                    chBoxHide.Checked = false;                    // 初創立,要看到所有有產品碼的
                }
                catch (Exception ex)
                {
                    MessageBox.Show("新增時錯誤,原因<" + ex.Message + ">");
                    return;
                }
            }
        }
示例#28
0
        private void btnExportExcel_Click(object sender, EventArgs e)
        {
            Excel.Application excel;
            Excel.Worksheet   sheet;
            Excel.Workbook    book;
            try
            {
                excel      = new Excel.Application();
                book       = excel.Application.Workbooks.Add(true);
                sheet      = book.Worksheets[1];
                sheet.Name = comboBoxMonth.SelectedItem.ToString() + "費用";
            }
            catch (Exception ex)
            {
                MessageBox.Show("開啟Excel出錯,原因:" + ex.Message);
                return;
            }
            excel.Visible = true;
            DataGridView view = expenseDataGridView;

            Excel.Range range;
            int         i = 1;
            // 插入Logo圖片
            int imgHeight = 48;

            range           = sheet.Rows[1];
            range.RowHeight = imgHeight + 2;
            Bitmap img = MyFunction.GetThumbnail(global::VoucherExpense.Properties.Resources.LogoVI, imgHeight * 4 / 3);   // 一般圖是96DPI,換算就是4pixels=3單位

            range = sheet.Cells[1, 1];
            Clipboard.SetDataObject(img, true);
            sheet.Paste(range, "LogoVI");

            range = sheet.Cells[1, 3];
            range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            sheet.Cells[1, 3]         = sheet.Name;
            range.Select();


            //欄位表頭
            i++;
            sheet.Cells[i, 1] = "编号";

            sheet.Cells[i, 2]         = "日期";
            range                     = sheet.Columns[2];
            range.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
            range.ColumnWidth         = 10;

            sheet.Cells[i, 3] = "摘要";
            range             = sheet.Columns[3];
            range.ColumnWidth = 30;

            sheet.Cells[i, 4]         = "金额";
            range                     = sheet.Columns[4];
            range.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
            range.NumberFormat        = "0.0";

            sheet.Cells[i, 5] = "科目";

            sheet.Cells[i, 6] = "申請人";

            i++;
            int n = 3;

            try
            {
                n = view.Columns["ApplyTime"].Index;
            }
            catch (Exception ex)
            {
                MessageBox.Show("程式被改錯了,DataGridView內找不到ApplyTime! 錯誤:" + ex.Message);
                excel.Quit();
                return;
            }
            foreach (DataGridViewRow vr in view.Rows)
            {
                sheet.Cells[i, 1] = vr.Cells[n + 2].FormattedValue;         // 編号
                sheet.Cells[i, 2] = vr.Cells[n].FormattedValue;             // 日期
                sheet.Cells[i, 3] = "'" + vr.Cells[n + 3].FormattedValue;   // 摘要
                sheet.Cells[i, 4] = vr.Cells[n + 4].FormattedValue;         // 金額
                sheet.Cells[i, 5] = vr.Cells[n + 5].FormattedValue;         // 科目
                sheet.Cells[i, 6] = vr.Cells[n + 1].FormattedValue;         // 申請人

                //DataRowView rowView = vr.DataBoundItem as DataRowView;
                //VEDataSet.ExpenseRow row =  rowView.Row as VEDataSet.ExpenseRow;
                //if (!row.IsInnerIDNull())   sheet.Cells[i, 1] = row.InnerID;
                //                            sheet.Cells[i, 2] = row.ApplyTime;
                //if (!row.IsNoteNull())      sheet.Cells[i, 3] = row.Note;
                //if (!row.IsTitleCodeNull()) sheet.Cells[i, 4] = "'"+row.TitleCode.ToString();
                //if (!row.IsMoneyNull())     sheet.Cells[i, 5] = row.Money;
                //if (!row.IsApplierIDNull())
                //{
                //    sheet.Cells[i, 6] = row.ApplierID;
                //}
                i++;
            }
            sheet.Cells[i++, 3] = "'================================================";
            sheet.Cells[i, 3]   = "小計";
            range             = sheet.Cells[i, 3];
            sheet.Cells[i, 4] = "=Sum(d3:d" + (i - 2).ToString() + ")";
            excel.Quit();
        }
示例#29
0
        private void Expense_Load(object sender, EventArgs e)
        {
            SetupBindingSource();
            var bankAccountAdapter = new VoucherExpense.DamaiDataSetTableAdapters.BankAccountTableAdapter();
            var operatorAdapter    = new VoucherExpense.DamaiDataSetTableAdapters.OperatorTableAdapter();
            var accTitleAdapter    = new VoucherExpense.DamaiDataSetTableAdapters.AccountingTitleTableAdapter();
            var HRAdapter          = new VoucherExpense.DamaiDataSetTableAdapters.HRTableAdapter();

            operatorAdapter.Connection.ConnectionString = DB.SqlConnectString(MyFunction.HardwareCfg);
            accTitleAdapter.Connection.ConnectionString = DB.SqlConnectString(MyFunction.HardwareCfg);

            bankAccountAdapter.Fill(m_DataSet.BankAccount);
            operatorAdapter.Fill(m_DataSet.Operator);
            accTitleAdapter.Fill(m_DataSet.AccountingTitle);
            HRAdapter.Fill(m_DataSet.HR);
            expenseAdapter.Fill(m_DataSet.Expense);
            MyFunction.SetControlLengthFromDB(this, m_DataSet.Expense);
            if (checkMode)
            {
                this.Text = "查核費用";
                blockEdit();
                expenseDataGridView.Columns["columnCheck"].ReadOnly = false;
                ckBoxAllowEdit.Visible = true;
            }
            else
            {
                ckBoxAllowEdit.Visible = false;
            }

            if (!零用金mode)
            {
                bankAccountIDComboBox.Visible = true;
                labelBank.Visible             = true;
                cbSelectBank.Enabled          = true;
            }

            cbSelectBank.Items.Clear();
            cbSelectBank.Items.Add("全部");
            foreach (var r in m_DataSet.BankAccount)
            {
                cbSelectBank.Items.Add(r.ShowName);
            }

            // 資料準備好,再加上EventHandler
            this.cbSelectBank.SelectedIndexChanged += new System.EventHandler(this.cbSelectBank_SelectedIndexChanged);

            if (cbSelectBank.Items.Count > 1)
            {
                cbSelectBank.SelectedIndex = 1;
            }

            comboBoxMonth.SelectedIndex = DateTime.Now.Month;

            if (MyFunction.LockAll)
            {
                blockEdit();
                ckBoxAllowEdit.Visible = false;
            }
//            comboBoxMonth.SelectedIndex = DateTime.Now.Month;
            dateTimePicker1.MaxDate = new DateTime(MyFunction.IntHeaderYear, 12, 31);
            dateTimePicker1.MinDate = new DateTime(MyFunction.IntHeaderYear, 1, 1);
        }
示例#30
0
        //List<CNameIDForComboBox> GetApartmentList()
        //{
        //    List<CNameIDForComboBox> list = new List<CNameIDForComboBox>();
        //    if (m_DataSet.Apartment.Rows.Count > 1)               // 多於一個才有全部這個選項
        //    {
        //        list.Add(new CNameIDForComboBox(0, " "));
        //        comboBoxApartment.Enabled = true;
        //    }
        //    else
        //        comboBoxApartment.Enabled = false;
        //    foreach (var row in m_DataSet.Apartment)
        //    {
        //        if (row.IsApartmentNameNull()) continue;
        //        list.Add(new CNameIDForComboBox(row.ApartmentID, row.ApartmentName));
        //    }
        //    return list;
        //}

        private void dgvOnDutyEmployee_SelectionChanged(object sender, EventArgs e)
        {
            DataGridView view = sender as DataGridView;
            MyHRRow      hRRow;

            try
            {
                DataRowView rv = view.CurrentRow.DataBoundItem as DataRowView;
                hRRow = rv.Row as MyHRRow;
            }
            catch
            {
                return;
            }
            if (hRRow == null)
            {
                return;
            }
            if (hRRow.IsFingerPintNoNull())
            {
                return;
            }
            if (hRRow.IsEmployeeNameNull())
            {
                return;
            }
//            if (hRRow.IsFingerprintmachineNull()) return;

            labelName.Text = hRRow.EmployeeName;
            int dutyCode = hRRow.FingerPintNo;
            int month    = comboBoxMonth.SelectedIndex + 1;
            int count    = MyFunction.DayCountOfMonth(month);

            string[] str = new string[count];
            for (int i = 0; i < count; i++)
            {
                str[i] = (i + 1).ToString("d2") + "日";
            }

            int d, h;

            EnumerableRowCollection <DamaiDataSet.OnDutyDataRow> rows;

            if (hRRow.IsFingerprintmachineNull())
            {
                rows = from r in m_DataSet.OnDutyData
                       where (r.OnDutyCode == hRRow.FingerPintNo)
                       select r;
            }
            else
            {
                rows = from r in m_DataSet.OnDutyData
                       where (r.Fingerprintmachine == hRRow.Fingerprintmachine) && (r.OnDutyCode == hRRow.FingerPintNo)
                       select r;
            }
            foreach (var row in rows)
            {
                try
                {
                    DateTime t = row.TimeMark;
                    if (t.Month == month)
                    {
                        d = t.Day - 1;
                        h = t.Hour;
                        if (h < 4)
                        {
                            d--;
                        }
                        if (d < 0)
                        {
                            continue;
                        }
                    }
                    else if (t.Month == (month + 1))    // 下個月4點前的算到上個月去
                    {
                        d = t.Day - 1;
                        if (d != 0)
                        {
                            continue;
                        }
                        h = t.Hour;
                        if (h < 4)
                        {
                            continue;
                        }
                        d = count - 1;
                    }
                    else
                    {
                        continue;
                    }
                    str[d] += " " + h.ToString("d2") + ":" + t.Minute.ToString("d2") + " ";
                }
                catch { }
            }
            checkedListBox1.Items.Clear();
            foreach (string s in str)
            {
                checkedListBox1.Items.Add(s);
            }
        }