Ejemplo n.º 1
0
        private void inventoryLoadData(int pageNum)
        {
            int importTotal = 0, exportTotal = 0, itemTotal = 0, netTotal = 0, returnTotal = 0;

            dgvInventory.Rows.Clear();
            DataGridViewRowCollection rows = dgvInventory.Rows;
            InventroyRPTInfo          view = new InventroyRPTInfo(APConfig.Conn);

            view.Conditions = " 1=1 ";
            if (!string.IsNullOrEmpty(txtInventoryName.Text))
            {
                view.Conditions += " AND " + view.getCondition(InventroyRPTInfo.ncConditions.name.ToString(), txtInventoryName.Text);
            }
            if (!string.IsNullOrEmpty(dpkInventoryINSDTTM.Value.ToString()) && ckbInventoryINDTTM.Checked)
            {
                view.Conditions += " AND " + view.getCondition(InventroyRPTInfo.ncConditions.importSDTTM.ToString(), dpkInventoryINSDTTM.Value.ToString("yyyy/MM/dd"));
            }
            if (!string.IsNullOrEmpty(dpkInventoryINEDTTM.Value.ToString()) && ckbInventoryINDTTM.Checked)
            {
                view.Conditions += " AND " + view.getCondition(InventroyRPTInfo.ncConditions.importEDTTM.ToString(), dpkInventoryINEDTTM.Value.ToString("yyyy/MM/dd"));
            }
            if (!string.IsNullOrEmpty(dpkInventoryOUTSDTTM.Value.ToString()) && ckbInventoryOUTDTTM.Checked)
            {
                view.Conditions += " AND " + view.getCondition(InventroyRPTInfo.ncConditions.exportSDTTM.ToString(), dpkInventoryOUTSDTTM.Value.ToString("yyyy/MM/dd"));
            }
            if (!string.IsNullOrEmpty(dpkInventoryOUTEDTTM.Value.ToString()) && ckbInventoryOUTDTTM.Checked)
            {
                view.Conditions += " AND " + view.getCondition(InventroyRPTInfo.ncConditions.exportEDTTM.ToString(), dpkInventoryOUTEDTTM.Value.ToString("yyyy/MM/dd"));
            }
            if (!string.IsNullOrEmpty(dpkInventoryRETURNSDTTM.Value.ToString()) && ckbInventoryRETURNDTTM.Checked)
            {
                view.Conditions += " AND " + view.getCondition(InventroyRPTInfo.ncConditions.returnSDTTM.ToString(), dpkInventoryRETURNSDTTM.Value.ToString("yyyy/MM/dd"));
            }
            if (!string.IsNullOrEmpty(dpkInventoryRETURNEDTTM.Value.ToString()) && ckbInventoryRETURNDTTM.Checked)
            {
                view.Conditions += " AND " + view.getCondition(InventroyRPTInfo.ncConditions.returnEDTTM.ToString(), dpkInventoryRETURNEDTTM.Value.ToString("yyyy/MM/dd"));
            }
            if (ddlInventoryVendor.SelectedIndex != 0)
            {
                view.Conditions += " AND " + view.getCondition(InventroyRPTInfo.ncConditions.vendor.ToString(), ddlInventoryVendor.SelectedItem.ToString());
            }
            if (ddlInventoryDealer.SelectedIndex != 0)
            {
                view.Conditions += " AND " + view.getCondition(InventroyRPTInfo.ncConditions.dealer.ToString(), ddlInventoryDealer.SelectedItem.ToString());
            }
            if (ddlInventoryStatus.SelectedIndex != 0)
            {
                view.Conditions += " AND " + view.getCondition(InventroyRPTInfo.ncConditions.status.ToString(), ddlInventoryStatus.SelectedItem.ToString());
            }

            view.condFormat(string.Format(" AND {0} ", view.Conditions));



            //組排序指令
            if (dgvInventory.SortedColumn is null)
            {
                view.OrderBy = view.getOptionOrderBy(RosterDial_RInfo.ncSort.Default.ToString());
            }
            else
            {
                string sortname = dgvInventory.SortedColumn.Name;
                string sortmode = APConfig.GetValueFromDescription <SortMode>(dgvInventory.SortOrder.ToString()).ToString();
                view.OrderBy = string.Format("{0} {1}", view.getOptionOrderBy(sortname), sortmode);
            }
            //查詢頁數初始化且自動跳轉至第一頁
            if (pageNum == 0)
            {
                APConfig.loadPage(ddlInventoryPage, view.calculatePage(APConfig.PageCount));
                return;
            }
            //塞入資料
            DataSet ds = APConfig.GoPage(view.SQLStatement, pageNum);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                rows.Add(new Object[] { dr.ItemArray[4], dr.ItemArray[0], dr.ItemArray[1], dr.ItemArray[2], dr.ItemArray[3], dr.ItemArray[5], dr.ItemArray[6], dr.ItemArray[7], dr.ItemArray[8], dr.ItemArray[9], dr.ItemArray[10], dr.ItemArray[11], dr.ItemArray[12] });
            }
            //計算總合
            if (view.load())
            {
                while (!view.IsEof)
                {
                    importTotal += view.INTOTAL;
                    exportTotal += view.OUTTOTAL;
                    netTotal    += view.NET;
                    returnTotal += view.RETURNTOTAL;
                    itemTotal   += Convert.ToInt32(view.STOCK);
                    view.next();
                }
            }
            lblInventoryTotal.Text     = string.Format("{0}", itemTotal.ToString());
            lblInventoryINAMT.Text     = string.Format("{0:n0} 元", importTotal);
            lblInventoryOUTAMT.Text    = string.Format("{0:n0} 元", exportTotal);
            lblInventoryRETURNAMT.Text = string.Format("{0:n0} 元", returnTotal);
            lblInventoryNETTotal.Text  = string.Format("{0:n0} 元", netTotal);
        }