Exemplo n.º 1
0
 private int compare(Shipmentdetailprint student1, Shipmentdetailprint student2)
 {
     return(student1.ProductCode - student2.ProductCode);
 }
Exemplo n.º 2
0
        private void tsbtPrint_Click(object sender, EventArgs e)
        {
            string apartmentName = "";

            if (!m_DefaultApartment.IsApartmentAllNameNull())
            {
                apartmentName = m_DefaultApartment.ApartmentAllName;
            }
            else
            {
                apartmentName = "該部門全名未設定,請找IT";
            }
            //if (this.damaiDataSet.Apartment.Rows.Count != 0)
            //{
            //    var a0 = this.damaiDataSet.Apartment[0];
            //    foreach (var a in this.damaiDataSet.Apartment)
            //    {
            //        if (!a.IsIsCurrentNull() && a.IsCurrent)
            //        {
            //            a0 = a;
            //            break;
            //        }
            //    }
            //    if (a0.IsApartmentNameNull())
            //        apartmentName = a0.ApartmentAllName;
            //    else
            //        apartmentName = a0.ApartmentAllName;
            //}
            DataRowView rowview = shipmentBindingSource.Current as DataRowView;

            DamaiDataSet.ShipmentRow row = rowview.Row as DamaiDataSet.ShipmentRow;
            if (row.IsCustomerNull())
            {
                MessageBox.Show("客户不能为空!");
                return;
            }
            if (row.IsCostNull())
            {
                MessageBox.Show("总金额为空!");
                return;
            }
            var customerrows = from ro in damaiDataSet.Customer where (ro.CustomerID == row.Customer) select ro;
            var customerrow  = customerrows.First();

            smp.ApartmentName  = apartmentName;
            smp.ShipmentNumber = row.ShipCode.ToString();
            smp.ContactPeople  = customerrow.ContactPeople;
            smp.CustomerName   = customerrow.Name;
            smp.ShipAddress    = customerrow.Address;
            smp.ContactPhone   = customerrow.Telephone;
            smp.EntryTime      = row.LastUpdated.ToString("yyyyMMdd");
            smp.ShipTime       = row.ShipTime.ToString("yyyyMMdd");
            smp.CostAllCount   = row.Cost;
            var shipmetdetailrows = row.GetShipmentDetailRows();

            if (shipmetdetailrows.Count() == 0)
            {
                return;
            }
            List <List <Shipmentdetailprint> > lists = new List <List <Shipmentdetailprint> >();
            //  int inttemp = shipmetdetailrows.Count() / 1000;
            //  for (int j = 0; j <= inttemp; j++)
            //{

            List <Shipmentdetailprint> listshipmentdetail = new List <Shipmentdetailprint>();

            //for (int i = j*999; i < shipmetdetailrows.Count(); i++)
            for (int i = 0; i < shipmetdetailrows.Count(); i++)
            {
                //if (i < (j + 1) * 999)
                // if (i < (j + 1) * 999)
                // {
                var temrow               = shipmetdetailrows[i];
                var productrow           = from r in damaiDataSet.Product where (r.ProductID == temrow.ProductID) select r;
                var productfirst         = productrow.First();
                Shipmentdetailprint smdp = new Shipmentdetailprint();
                // smdp.PageNumCount = inttemp + 1;
                //smdp.Num = i+1;
                smdp.ProductName = productrow.First().Name;
                smdp.ProductCode = productrow.First().Code;
                if (productfirst.IsUnitNull())
                {
                    smdp.Unit = "";
                }
                else
                {
                    smdp.Unit = productrow.First().Unit;
                }
                if (productfirst.IsPriceNull())
                {
                    MessageBox.Show("产品" + productfirst.Name + "所在行资料不全无法打印");
                    return;
                }
                else
                {
                    smdp.Cost = productrow.First().Price;
                }
                smdp.Volum = temrow.Volume;
                if (temrow.IsCostNull())
                {
                    MessageBox.Show("产品" + productfirst.Name + "所在行资料不全无法打印");
                    return;
                }
                else
                {
                    smdp.AllCost = temrow.Cost;
                }
                listshipmentdetail.Add(smdp);

                // }
            }
            listshipmentdetail.Sort(compare);
            lists.Add(listshipmentdetail);
            // }
            smp.ShipmentDetileProduct = lists;
            printPageHeight           = lists[0].Count * 14 + 110 + 552;

            try
            {
                Config = MyFunction.HardwareCfg;
                PrinterSettings ps = new PrinterSettings();
                ps.PrinterName = Config.DotPrinterName;
                var ss = ps.PaperSizes;

                System.Drawing.Printing.PageSettings df = ps.DefaultPageSettings;
                printDocument1.PrinterSettings = ps;
                printDocument1.Print();
            }
            catch
            { }
            //FormShipmentPrint form = new FormShipmentPrint(smp);
            //form.Show();
        }