Ejemplo n.º 1
0
        public void ExportProject(int key)
        {
            var projectList = new List <Project>();
            var name        = "";
            var projects    = _projectFactory.GetAllProjects();

            if (projects != null)
            {
                switch (key)
                {
                case 1:
                    projectList = projects;
                    name        = "所有项目";
                    break;

                case 2:
                    projectList = projects.Where(p => p.CurrentStep != null && p.CurrentStep.StepOrder > (int)RouteStep.发货).ToList();
                    name        = "已完成项目";
                    break;

                case 3:
                    projectList = projects.Where(p => p.CurrentStep == null || p.CurrentStep.StepOrder <= (int)RouteStep.发货).ToList();
                    name        = "未完成项目";
                    break;

                case 4:
                    projectList = projects.Where(p => p.CurrentStep != null && p.CurrentStep.StepOrder == (int)RouteStep.设计).ToList();
                    name        = "已设计项目";
                    break;

                case 5:
                    projectList = projects.Where(p => p.CurrentStep != null && p.CurrentStep.StepOrder == (int)RouteStep.生产).ToList();
                    name        = "已生产项目";
                    break;

                case 6:
                    projectList = projects.Where(p => p.CurrentStep != null && p.CurrentStep.StepOrder == (int)RouteStep.入库).ToList();
                    name        = "已入库项目";
                    break;
                }
            }
            var tablename = string.Format("{0}_{1}_Excel", name, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
            var dt        = new System.Data.DataTable();

            dt.TableName = tablename;
            dt.Columns.Add("序号");
            dt.Columns.Add("项目编号");
            dt.Columns.Add("项目名称");
            dt.Columns.Add("所属客户");
            dt.Columns.Add("预计交付日期");
            dt.Columns.Add("项目进度");
            dt.Columns.Add("预计完成时间");
            dt.Columns.Add("剩余天数");
            var i        = 1;
            var customer = new CustomerFactory();

            foreach (var one in projectList)
            {
                dt.Rows.Add(
                    i.ToString(),
                    one.ProjectCode,
                    one.ProjectName,
                    string.IsNullOrEmpty(one.CustomerGuid) ? " " : customer.GetCustomer(one.CustomerGuid).CompanyName,
                    one.EstimatedDeliveryDate == null ? "" : one.EstimatedDeliveryDate.ToString("yyyy-MM-dd"),
                    one.CurrentStep == null ? "" : one.CurrentStep.StepName,
                    one.ProjectCurrentStepEstimatedCompleteDate == null ? "" : one.ProjectCurrentStepEstimatedCompleteDate.Value.ToString("yyyy-MM-dd"),
                    one.ProjectCurrentStepOverduDays
                    );
            }
            ExportExcel(dt);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            try
            {
                // Initialize customer factory
                cf = new CustomerFactory();
                Console.WriteLine("NHibernate test started");

                Console.WriteLine("Loading customers into the cache...");

                cf.GetCustomers();
                cf.SessionDisconnect();
                Console.WriteLine("Customers information loaded in the cache");


                int choice = 0;
                while (choice != 7)
                {
                    choice = GetUserChoice();
                    string id;
                    try
                    {
                        switch (choice)
                        {
                        case 1:
                            PrintCustomerList(cf.GetCustomers());
                            cf.SessionDisconnect();
                            break;

                        case 2:
                            id = GetCustomerId();
                            PrintCustomerDetail(cf.GetCustomer(id));
                            cf.SessionDisconnect();
                            break;

                        case 3:
                            id = GetCustomerId();
                            Customer customer = cf.GetCustomerOrders(id);
                            PrintCustomerOrders(customer);
                            cf.SessionDisconnect();
                            break;

                        case 4:
                            id = GetCustomerId();
                            cf.RemoveCustomer(id);
                            cf.SessionDisconnect();
                            break;

                        case 5:
                            cf.SaveCustomer(AddCustomer(true));
                            cf.SessionDisconnect();
                            break;

                        case 6:
                            Customer tempCust = AddCustomer(false);
                            if (tempCust != null)
                            {
                                cf.UpdateCustomer(tempCust);
                                cf.SessionDisconnect();
                            }
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("\n" + ex + "\n");
                        Console.Read();
                    }
                }
                cf.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:" + e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine(e.InnerException.Message);
                }
                Console.Read();
            }
        }