Example #1
0
        public bool add(PrintOrder order, DbTransaction transaction)
        {
            IFPObjectDAO fpObjectDAO = DAOFactory.getInstance().createFPObjectDAO();
            fpObjectDAO.add(order, transaction);

            SqlTransaction trans = (SqlTransaction)transaction;
            String sql = "insert into Print_Order(ObjectId, pid, received_date, order_deadline, invoice_no, contact_id, received_by, sales_person, remarks, status) values " +
                "(@ObjectId, @pid, @received_date, @order_deadline, @invoice_no, @contact_id, @received_by, @sales_person, @remarks, @status)";
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = sql;
            cmd.Connection = trans.Connection;
            cmd.Transaction = trans;

            cmd.Parameters.Add(genSqlParameter("ObjectId", SqlDbType.Int, 10, order.objectId));
            cmd.Parameters.Add(genSqlParameter("pid", SqlDbType.NVarChar, 50, order.pid));
            cmd.Parameters.Add(genSqlParameter("received_date", SqlDbType.DateTime, 0, order.received_date));
            cmd.Parameters.Add(genSqlParameter("order_deadline", SqlDbType.NVarChar, 50, order.order_deadline));
            cmd.Parameters.Add(genSqlParameter("invoice_no", SqlDbType.NVarChar, 50, order.invoice_no));

            if(order.received_by == null)
                cmd.Parameters.Add(genSqlParameter("received_by", SqlDbType.Int, 10, null));
            else
                cmd.Parameters.Add(genSqlParameter("received_by", SqlDbType.Int, 10, order.received_by.objectId));
            if(order.sales_person == null)
                cmd.Parameters.Add(genSqlParameter("sales_person", SqlDbType.Int, 10, null));
            else
                cmd.Parameters.Add(genSqlParameter("sales_person", SqlDbType.Int, 10, order.sales_person.objectId));

            cmd.Parameters.Add(genSqlParameter("remarks", SqlDbType.NVarChar, 2000, order.remarks));

            cmd.Parameters.Add(genSqlParameter("status", SqlDbType.NVarChar, 50, order.status));

            if(order.customer_contact != null)
                cmd.Parameters.Add(genSqlParameter("contact_id", SqlDbType.Int, 10, order.customer_contact.objectId));
            else
                cmd.Parameters.Add(genSqlParameter("contact_id", SqlDbType.Int, 10, null));
            cmd.ExecuteNonQuery();

            cmd.Dispose();

            return true;
        }
Example #2
0
 public static String getJobJson(PrintItem job, PrintOrder order)
 {
     String customername = "";
     if (order != null)
     {
         if (order.customer_contact != null)
         {
             if (order.customer_contact.company_name != null)
             {
                 customername = order.customer_contact.company_name;
             }
         }
     }
     StringBuilder jobJson = new StringBuilder();
     jobJson.Append("{").Append("jobid:'").Append(job.jobid).Append("',")
         .Append("job_type:'").Append(job.job_type == null ? "" : job.job_type.category_name).Append("',")
         .Append("handled_by:'").Append(job.handled_by == null ? "" : job.handled_by.eng_name).Append("',")
         .Append("customer_name:'").Append(filter(customername)).Append("',")
         .Append("job_deadline:'").Append(job.job_deadline).Append("',")
         .Append("notes:'").Append(filter(job.notes)).Append("',")
         .Append("job_status:'").Append(job.job_status).Append("'}");
     return jobJson.ToString();
 }
Example #3
0
 public ActionResult order()
 {
     Session["newOrder"] = new PrintOrder();
     return View("order");
 }
Example #4
0
 public bool delete(PrintOrder order, DbTransaction transaction)
 {
     IFPObjectDAO fpObjectDAO = DAOFactory.getInstance().createFPObjectDAO();
     return fpObjectDAO.delete(order, transaction);
 }
Example #5
0
        private List<PrintOrder> getQueryResult(SqlCommand cmd)
        {
            DbDataReader reader = cmd.ExecuteReader();
            DataTable dt = new DataTable();

            IPrintItemDAO printItemDAO = DAOFactory.getInstance().createPrintJobDAO();
            IUserDAO userDAO = DAOFactory.getInstance().createUserDAO();
            ICustomerContactDAO contactDAO = DAOFactory.getInstance().createCustomerContactDAO();

            List<PrintOrder> orders = new List<PrintOrder>();
            PrintOrder order = null;

            dt.Load(reader);
            reader.Close();

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    order = new PrintOrder();

                    order.objectId = getInt(dt.Rows[i]["ObjectId"]);
                    order.createDate = getDateTime(dt.Rows[i]["CreateDate"]);
                    order.updateDate = getDateTime(dt.Rows[i]["UpdateDate"]);
                    order.updateBy = getString(dt.Rows[i]["UpdateBy"]);
                    order.isDeleted = (getInt(dt.Rows[i]["IsDeleted"]) == 1);
                    order.invoice_no = getString(dt.Rows[i]["invoice_no"]);
                    order.order_deadline = getString(dt.Rows[i]["order_deadline"]);
                    order.pid = getString(dt.Rows[i]["pid"]);
                    order.received_by = userDAO.get(getInt(dt.Rows[i]["received_by"]),cmd.Transaction);
                    order.received_date = getDateTime(dt.Rows[i]["received_date"]);
                    order.remarks = getString(dt.Rows[i]["remarks"]);
                    order.sales_person = userDAO.get(getInt(dt.Rows[i]["sales_person"]),cmd.Transaction);
                    order.status = getString(dt.Rows[i]["status"]);
                    order.print_job_list = printItemDAO.search(" where pid = '" + order.pid + "'", 1000, 0, "", false, cmd.Transaction);
                    order.customer_contact = contactDAO.get(getInt(dt.Rows[i]["contact_id"]), cmd.Transaction);
                    orders.Add(order);
                }
            }
            return orders;
        }
Example #6
0
        public List<PrintItem> getPrintJobByOrder(PrintOrder order, UserAC user)
        {
            if (order == null)
                return new List<PrintItem>();

            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                IPrintItemDAO printJobDAO = DAOFactory.getInstance().createPrintJobDAO();
                List<PrintItem> jobs = printJobDAO.search("where pid='" + order.pid + "' and isdeleted = 0 ", 1000, 0, "jobid", true, transaction);
                transaction.Commit();
                return jobs;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Example #7
0
        public bool newOrder(PrintOrder order, UserAC user)
        {
            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                //[yy][mm][dd][3digits]
                IPrintOrderDAO printOrderDAO = DAOFactory.getInstance().createPrintOrderDAO();
                IPrintItemDAO printJobDAO = DAOFactory.getInstance().createPrintJobDAO();
                ISequenceDAO seqDAO = DAOFactory.getInstance().createSequenceDAO();
                ICustomerContactDAO contactDAO = DAOFactory.getInstance().createCustomerContactDAO();
                int seqNo = 0;
                String pid = DateTime.Now.ToString("yyMMdd");
                do
                {
                    seqNo++;
                    seqNo = 1000 + seqNo;

                } while (printOrderDAO.get(pid + ("" + seqNo).Substring(1),transaction) != null);

                order.pid = pid + ("" + seqNo).Substring(1);
                order.objectId = seqDAO.getNextObjectId(transaction);
                order.updateBy = user.eng_name;

                order.customer_contact.objectId = seqDAO.getNextObjectId(transaction);
                order.customer_contact.updateBy = user.eng_name;
                contactDAO.add(order.customer_contact, transaction);
                printOrderDAO.add(order, transaction);



                if (order.print_job_list != null)
                {
                    String jobid = "";
                    for (int i = 0; i < order.print_job_list.Count; i++)
                    {
                        order.print_job_list[i].job_deadline = order.order_deadline;
                        order.print_job_list[i].pid = order.pid;

                        seqNo = 0;
                        //do
                        //{
                        //    seqNo++;
                        //    seqNo = 100 + seqNo;
                        //    jobid = order.pid + "-" + order.print_job_list[i].job_type.category_code + ("" + seqNo).Substring(1);
                            
                        //} while (printJobDAO.get(jobid, transaction) != null);

                        int c = 1;
                        jobid = order.pid + "-" + order.print_job_list[i].job_type.category_code + c;
                        while (printJobDAO.get(jobid, transaction) != null)
                        {
                            c++;
                            jobid = order.pid + "-" + order.print_job_list[i].job_type.category_code + c;
                        }

                        order.print_job_list[i].jobid = jobid;

                        order.print_job_list[i].objectId = seqDAO.getNextObjectId(transaction);
                        order.print_job_list[i].updateBy = user.eng_name;
                        printJobDAO.add(order.print_job_list[i], transaction);
                    }
                }
                transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Example #8
0
        public bool deleteOrder(PrintOrder order, UserAC user)
        {
            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                //[yy][mm][dd][3digits]
                IPrintOrderDAO printOrderDAO = DAOFactory.getInstance().createPrintOrderDAO();
                order.updateBy = user.eng_name;
                printOrderDAO.delete(order, transaction);
                IPrintItemDAO printJobDAO = DAOFactory.getInstance().createPrintJobDAO();

                if (order.print_job_list != null)
                {
                    for (int i = 0; i < order.print_job_list.Count; i++)
                    {
                        order.print_job_list[i].updateBy = user.eng_name;
                        printJobDAO.delete(order.print_job_list[i], transaction);
                    }
                }

                transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Example #9
0
        public bool updateOrder(PrintOrder order, UserAC user)
        {
            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                //[yy][mm][dd][3digits]
                IPrintOrderDAO printOrderDAO = DAOFactory.getInstance().createPrintOrderDAO();

                if (order.customer_contact.objectId == 0)
                {
                    ISequenceDAO seqDAO = DAOFactory.getInstance().createSequenceDAO();
                    ICustomerContactDAO contactDAO = DAOFactory.getInstance().createCustomerContactDAO();
                    order.customer_contact.objectId = seqDAO.getNextObjectId(transaction);
                    order.customer_contact.updateBy = user.eng_name;
                    contactDAO.add(order.customer_contact, transaction);
                }

                order.updateBy = user.eng_name;
                printOrderDAO.update(order, transaction);

                transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Example #10
0
        public bool addNewJob(PrintOrder order, PrintItem job, UserAC user)
        {
            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                IPrintItemDAO printJobDAO = DAOFactory.getInstance().createPrintJobDAO();
                ISequenceDAO seqDAO = DAOFactory.getInstance().createSequenceDAO();
                int seqNo = 0;

                String jobid = "";
                //do
                //{
                //    seqNo++;
                //    seqNo = 1000 + seqNo;
                //    jobid = order.pid + job.job_type.category_code + ("" + seqNo).Substring(1);
                //} while (printJobDAO.get(jobid, transaction) != null);

                int c = 1;
                jobid = order.pid + "-" + job.job_type.category_code + c;
                while (printJobDAO.get(jobid, transaction) != null)
                {
                    c++;
                    jobid = order.pid + "-" + job.job_type.category_code + c;
                }

                job.jobid = jobid;
                job.job_deadline = order.order_deadline;
                job.pid = order.pid;
                job.objectId = seqDAO.getNextObjectId(transaction);
                job.updateBy = user.eng_name;

                printJobDAO.add(job, transaction);

                transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Example #11
0
        public static String getOrderJson(PrintOrder order)
        {
            StringBuilder orderJson = new StringBuilder();
            orderJson.Append("{").Append("pid:'").Append(order.pid).Append("',")
                .Append("received_date:'").Append(order.received_date == null ? "" : order.received_date.Value.ToString("yyyy-MM-dd")).Append("',")
                .Append("update_date:'").Append(order.updateDate == null ? "" : order.updateDate.Value.ToString("yyyy-MM-dd")).Append("',")
                .Append("order_deadline:'").Append(("" + order.order_deadline).Replace("'", "`")).Append("',")
                .Append("invoice_no:'").Append(order.invoice_no).Append("',");

            if (order.customer_contact != null)
            {
                if (order.customer_contact.customer != null)
                {
                    orderJson.Append("cid:'").Append(order.customer_contact.customer.company_code).Append("',");
                }
                else
                {
                    orderJson.Append("cid:'").Append("").Append("',");
                }
            }
            else
            {
                orderJson.Append("cid:'").Append("").Append("',");
            }

            orderJson.Append("received_by:'").Append(order.received_by == null ? "" : order.received_by.eng_name).Append("',")
                .Append("sales_person:'").Append(order.sales_person == null ? "" : order.sales_person.eng_name).Append("',")
                .Append("update_by:'").Append(order.updateBy == null ? "" : order.updateBy).Append("',")
                .Append("remarks:'").Append(filter(order.remarks)).Append("',");
            if (order.customer_contact != null)
            {
                if (order.customer_contact.company_name != null)
                {
                    orderJson.Append("customer_name:'").Append(filter(order.customer_contact.company_name)).Append("',");
                }
                else
                {
                    orderJson.Append("customer_name:'").Append("").Append("',");
                }
            }
            else
            {
                orderJson.Append("customer_name:'").Append("").Append("',");
            }

            orderJson.Append("status:'").Append(order.status).Append("',")
                .Append("customer_tel:'").Append((order.customer_contact == null ? "" : filter(order.customer_contact.tel))).Append("',");

            if (order.customer_contact != null)
            {
                if (order.customer_contact.customer != null)
                {
                    orderJson.Append("customer:'").Append(order.customer_contact.customer.company_code).Append("',");
                }
                else
                {
                    orderJson.Append("customer:'").Append("").Append("',");
                }
            }
            else
            {
                orderJson.Append("customer:'").Append("").Append("',");
            }

            orderJson.Append("customer_contact_person:'").Append(order.customer_contact == null ? "" : filter(order.customer_contact.contact_person)).Append("'}");
            return orderJson.ToString();

        }
Example #12
0
        public static String getJobOfOrderJson(PrintOrder order, PrintItem job)
        {
            StringBuilder jobJson = new StringBuilder();
            jobJson.Append("{").Append("pid:'").Append(job.pid).Append("',")
                .Append("received_date:'").Append(order.received_date == null ? "" : order.received_date.Value.ToString("yyyy-MM-dd")).Append("',")
                .Append("received_by:'").Append(order.received_by == null ? "" : order.received_by.eng_name).Append("',")
                .Append("order_deadline:'").Append(order.order_deadline).Append("',")
                .Append("customer_name:'").Append(filter(order.customer_contact.company_name)).Append("',")
                .Append("customer_tel:'").Append(order.customer_contact.tel).Append("',")

                .Append("customer_contact_person:'").Append(order.customer_contact.contact_person).Append("',")
                .Append("remarks:'").Append(filter(order.remarks)).Append("',")
                .Append("section:'").Append(job.job_type == null ? "" : job.job_type.category_name).Append("',")
                .Append("jobid:'").Append(job.jobid).Append("',")
                .Append("filename:'").Append(job.file_name).Append("',")
                .Append("request:'");

            bool addRequest = false;
            if (job.newjob)
            {
                addRequest = true;
                jobJson.Append("New Job");
            }
            if (job.em)
            {
                if (addRequest)
                    jobJson.Append(",EM");
                else
                    jobJson.Append("EM");

                addRequest = true;
            }
            if (job.ftp)
            {
                if (addRequest)
                    jobJson.Append(",FTP");
                else
                    jobJson.Append("FTP");

                addRequest = true;
            }
            if (job.cddvd)
            {
                if (addRequest)
                    jobJson.Append(",CD/DVD");
                else
                    jobJson.Append("CD/DVD");

                addRequest = true;
            }
            if (job.mac)
            {
                if (addRequest)
                    jobJson.Append(",MAC");
                else
                    jobJson.Append("MAC");

                addRequest = true;
            }
            if (job.pc)
            {
                if (addRequest)
                    jobJson.Append(",PC");
                else
                    jobJson.Append("PC");

                addRequest = true;
            }
            if (job.test_job)
            {
                if (addRequest)
                    jobJson.Append(",Test");
                else
                    jobJson.Append("Test");

                addRequest = true;
            }
            jobJson.Append("',item_details:'");
            String itemType = "";
            for (int i = 0; i < job.print_job_items.Count; i++)
            {
                if (itemType != job.print_job_items[i].category_name)
                {
                    jobJson.Append("\\n").Append(job.print_job_items[i].category_name).Append(" : ");
                    itemType = job.print_job_items[i].category_name;
                }
                jobJson.Append(job.print_job_items[i].code_desc).Append(" ");
            }
            if((job.qty + "").Trim() != "")
            {
                String[] qtys = job.qty.Split(' ');
                String[] sizes = job.size.Split(' ');
                String[] units = job.unit.Split(' ');

                if (qtys.Length == sizes.Length && qtys.Length == units.Length)
                {
                    for (int i = 0; i < qtys.Length; i++)
                    {
                        jobJson.Append("\\n").Append("Quantity:").Append((qtys[i] + "").Replace("Quantity:", "")).Append(" Size:").Append(sizes[i].Replace("Size:", ""));
                        if (units[i].Replace("Unit:", "") != "")
                            jobJson.Append(" Unit:").Append(units[i].Replace("Unit:", ""));
                    }
                }
            }
            
            //if((job.qty + "").Trim() != "")
            //    jobJson.Append("\\n").Append("Quantity : ").Append((job.qty + "").Replace("Q:", ""));
            //if ((job.size + "").Trim() != "")
            //    jobJson.Append("\\n").Append("Size : ").Append((job.size + "").Replace("Size:", ""));
            //if ((job.unit + "").Trim() != "")
            //    jobJson.Append("\\n").Append("Unit : ").Append((job.unit + "").Replace("Unit:", ""));


            jobJson.Append("',").Append("notes:'").Append(job.notes).Append("',")
                .Append("handledby:'").Append(job.handled_by == null ? "" : (job.handled_by.objectId == 0 ? "" : job.handled_by.objectId.ToString())).Append("',")
                .Append("job_details:[").Append(""/*TODO*/).Append("],")
                .Append("job_status:'").Append(job.job_status).Append("',")
                .Append("purpose:'").Append(""/*TODO*/).Append("',")
                .Append("size:'").Append(""/**/).Append("'}");
            return jobJson.ToString();
        }
Example #13
0
        public ActionResult addNewOrder()
        {
            try
            {
                //{orderNo=--&customer=&received_date=&customer_tel=&received_by=&customer_contact_person=&order_deadline=&remark=&update_by=ivan&newjobtype=
                String sOrderNo = Request.Params["orderNo"];
                String sCustomer = Request.Params["customer"];
                String sReceived_date = Request.Params["received_date"];
                String sCustomer_tel = Request.Params["customer_tel"];
                String sReceived_by = Request.Params["received_by"];
                String sCustomerContactPerson = Request.Params["customer_contact_person"];
                String sOrderDeadline = Request.Params["order_deadline"];
                String sRemark = Request.Params["remark"];
                String sUpdateBy = Request.Params["update_by"];
                String sNewJobType = Request.Params["newjobtype"];
                String sInvoiceNo = Request.Params["invoice_no"];
                String sCustomerNo = Request.Params["customer_no"];

                UserAC user = (UserAC)Session["user"];
                IFPService service = (IFPService)FPServiceHolder.getInstance().getService("fpService");
                IFPObjectService objectService = (IFPObjectService)FPServiceHolder.getInstance().getService("fpObjectService");

                PrintOrder order = objectService.getPrintOrderByID(sOrderNo, user);
                if (order != null)
                {
                    Customer customer = objectService.getCustomerByCustomerID(sCustomerNo, user);


                    order.customer_contact = new CustomerContact();
                    order.customer_contact.customer = customer;
                    order.customer_contact.contact_person = sCustomerContactPerson;
                    order.customer_contact.tel = sCustomer_tel;
                    order.customer_contact.ctype = "normal";
                    order.customer_contact.company_name = sCustomer;

                    order.order_deadline = sOrderDeadline;
                    order.received_date = DateTime.Parse(sReceived_date);
                    order.updateDate = DateTime.Now;
                    order.remarks = sRemark;
                    order.updateBy = user.user_name;
                    order.received_date = DateTime.Parse(sReceived_date);
                    order.invoice_no = sInvoiceNo;
                    try
                    {
                        order.sales_person = objectService.getUserByID(int.Parse(sReceived_by), user);
                        order.received_by = objectService.getUserByID(int.Parse(sReceived_by), user);
                    }
                    catch (Exception e) { }


                    if (order.received_by == null)
                        order.received_by = user;

                    bool success = service.updateOrder(order, user);

                    if (success)
                    {
                        return Content("{success:true, result:\"Update success\", pid:\"" + order.pid + "\"}");
                    }
                    else
                    {
                        return Content("{success:false, result:\"" + "Update order failed" + "\"}");
                    }
                }
                else
                {

                    order = Session["newOrder"] == null ? new PrintOrder() : (PrintOrder)Session["newOrder"];

                    Customer customer = objectService.getCustomerByCustomerID(sCustomerNo, user);

                    order.customer_contact = new CustomerContact();
                    order.customer_contact.customer = customer;
                    order.customer_contact.contact_person = sCustomerContactPerson;
                    order.customer_contact.tel = sCustomer_tel;
                    order.customer_contact.ctype = "normal";
                    order.customer_contact.company_name = sCustomer;

                    order.invoice_no = sInvoiceNo;
                    order.order_deadline = sOrderDeadline;
                    order.status = PrintOrder.STATUS_PENDING;
                    try
                    {
                        order.received_by = objectService.getUserByID(int.Parse(sReceived_by), user);
                    }
                    catch (Exception e) { }
                    order.received_date = DateTime.Parse(sReceived_date);
                    order.updateDate = DateTime.Now;
                    order.remarks = sRemark;
                    try
                    {
                        order.sales_person = objectService.getUserByID(int.Parse(sReceived_by), user);
                    }
                    catch (Exception e) { }
                    order.updateBy = user.user_name;

                    if (order.received_by == null)
                        order.received_by = user;

                    if (order.received_by == null || order.order_deadline == "" || order.customer_contact == null)
                    {
                        order.print_job_list = new List<PrintItem>();
                        return Content("{success:false, result:\"" + "Missing information such as sales ,deadline, customer" + "\"}");
                    }

                    Boolean success = service.newOrder(order, user);

                    if (success)
                    {
                        Session["newOrder"] = new PrintOrder();
                        return Content("{success:true, result:\"Update success\", pid:\"" + order .pid+ "\"}");
                    }
                    else
                    {
                        order.print_job_list = new List<PrintItem>();
                        return Content("{success:false, result:\"" + "Create new order failed" + "\"}");
                    }
                }
            }
            catch (Exception e)
            {
                return Content("{success:false, result:\"" + e.Message + "\"}");
            }
        }