Ejemplo n.º 1
0
        public static string getCustomerJson(Customer customer, CustomerContact cc)
        {
            if (customer == null)
                customer = new Customer();
            if (cc == null)
                cc = new CustomerContact();

            StringBuilder customerJson = new StringBuilder();
            customerJson.Append("{").Append("objectid:'").Append(customer.objectId.ToString()).Append("',")
                .Append("company_code:'").Append(customer.company_code == null ? string.Empty : customer.company_code.ToString()).Append("',")
                .Append("company_name:'").Append(customer.company_name == null ? string.Empty : filter(customer.company_name.ToString())).Append("',")
                 .Append("contact_objectid:'").Append(cc.objectId.ToString()).Append("',")
                 .Append("contact_person:'").Append(cc.contact_person == null ? string.Empty : cc.contact_person.ToString()).Append("',")
                .Append("contact_tel:'").Append(cc.tel == null ? string.Empty : cc.tel.ToString()).Append("',")
                .Append("email:'").Append(cc.email == null ? string.Empty : cc.email.ToString()).Append("',")
                .Append("deliveryid:'").Append(cc.deliveryid.ToString ()).Append("',")
                 .Append("street1:'").Append(cc.street1 == null ? string.Empty : cc.street1.ToString().Replace("'", "\\\'")).Append("',")
                 .Append("street2:'").Append(cc.street2 == null ? string.Empty : cc.street2.ToString().Replace("'", "\\\'")).Append("',")
                 .Append("street3:'").Append(cc.street3 == null ? string.Empty : cc.street3.ToString().Replace("'", "\\\'").Replace ("\n","").Replace ("\r","")).Append("',")
                 .Append("district:'").Append(cc.district == null ? string.Empty : cc.district.ToString()).Append("',")
                 .Append("city:'").Append(cc.city == null ? string.Empty : cc.city.ToString()).Append("',")
                 .Append("district:'").Append(cc.district == null ? string.Empty : cc.district.ToString()).Append("',")
                  .Append("fax:'").Append(cc.fax == null ? string.Empty : cc.fax.ToString()).Append("',")
                   .Append("remark:'").Append(cc.remarks == null ? string.Empty : cc.remarks.ToString()).Append("',")
                 .Append("mobile:'").Append(cc.mobile == null ? string.Empty : cc.mobile.ToString()).Append("',")
                .Append("contact_address:'").Append(cc.address == null ? string.Empty : cc.address.ToString()).Append("'}");

            return customerJson.ToString();
        }
Ejemplo n.º 2
0
 public CustomerContact getCustomerContactByCustomer(Customer customer, string ctype, DbTransaction transaction)
 {
     SqlTransaction trans = (SqlTransaction)transaction;
     List<CustomerContact> contacts = search("and Customer_Contact.customer = '" + customer.objectId + "' and IsDeleted = 0 and ctype='" + ctype + "' ", trans);
     if (contacts != null && contacts.Count > 0)
     {
         return contacts[0];
     }
     else
     {
         return null;
     }
 }
Ejemplo n.º 3
0
        public object addcustomer(string code, string name, string person, string tel, string address, string cid)
        {
            var result = string.Empty;
            UserAC user = (UserAC)Session["user"];
            IFPService service = (IFPService)FPServiceHolder.getInstance().getService("fpService");
            IFPObjectService objectService = (IFPObjectService)FPServiceHolder.getInstance().getService("fpObjectService");
            int objectid = 0;
            int.TryParse(cid, out objectid);
            var customer = objectService.getCustomerByID(objectid, user);
            string customer_code = string.Empty;
           

            if(customer !=null )
                customer_code = customer.company_code.Trim();
            var customer1 = objectService.getCustomerByCustomerID(code.Trim(), user);
            if (customer1 != null && customer == null)
            {
                result = "has exist the company code !";
            }
            else
            {
                if (customer != null)
                {
                    customer.company_code = code.Trim();
                    customer.company_name = name.Trim();
                    service.updateCustomer(customer, user);
                    result = "update information successfully !";
                }
                else
                {
                    customer = new Customer();
                    customer.company_code = code.Trim();
                    customer.company_name = name.Trim();
                    service.addCustomer(customer, user);
                    result = "add information successfully !";
                }

                if (customer_code != string.Empty && customer_code.Trim() != code.Trim())
                {
                    var customercontacts = objectService.getContactsByCode(customer_code.Trim(), user);

                    if (customercontacts.Count() > 0)
                    {
                        foreach (var contact in customercontacts)
                        {
                            contact.customer = customer;
                            service.updateCustomerContact(contact, user);
                        }
                    }
                }

                var cc = objectService.getCustomerContactByCode(code.Trim(), "default", user);
                if (cc != null)
                {
                    cc.address = address.Trim();
                    cc.contact_person = person.Trim();
                    cc.tel = tel.Trim();
                    cc.ctype = "default";
                    cc.customer = customer;
                    service.updateCustomerContact(cc, user);
                }
                else
                {
                    cc = new CustomerContact();
                    cc.address = address.Trim();
                    cc.contact_person = person.Trim();
                    cc.tel = tel.Trim();
                    cc.ctype = "default";
                    cc.customer = customer;
                    service.addCustomerContact(cc, user);
                }
                
            }
            return Json(result);
        }
Ejemplo n.º 4
0
 public CustomerContact getCustomerContactByCustomer(Customer customer, string ctype, UserAC user)
 {
     IDatabase db = DAOFactory.getInstance().getDatabase();
     DbConnection conn = db.getConnection();
     DbTransaction transaction = db.beginTransaction(conn);
     try
     {
         ICustomerContactDAO customercontactDAO = DAOFactory.getInstance().createCustomerContactDAO();
         CustomerContact cc = customercontactDAO.getCustomerContactByCustomer(customer, ctype, transaction);
         transaction.Commit();
         return cc;
     }
     catch (Exception e)
     {
         transaction.Rollback();
         throw e;
     }
     finally
     {
         conn.Close();
     }
 }
Ejemplo n.º 5
0
        public bool deleteCustomer(Customer customer, UserAC user)
        {
            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                ICustomerDAO customerDao = DAOFactory.getInstance().createCustomerDAO();

                customer.updateBy = user.eng_name;
                customer.updateDate = DateTime.Now;
                customer.isDeleted = false;

                customerDao.delete(customer, transaction);
                transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            } 
        }
Ejemplo n.º 6
0
        public object add(
            string objectid,
            string city,
            string companyname,
            string contact,
            string deadline,
            string district,
            string handleby,
            string height,
            string length,
            string mobile,
            string nonorder,
            string notes,
            string number,
            string partno,
            string remarks,
            string requestby,
            string street1,
            string street2,
            string street3,
            string tel,
            string updateby,
            string updatedate,
            string weight,
            string width,
            string code,
            string delivery_type,
            string status,
            string goods_type
        )
        {
            try
            {
                int objid = 0;
                int.TryParse(objectid, out objid);
                var q = Request["width"];
                if (q == null)
                    q = Request.Params["query"];
                UserAC user = (UserAC)Session["user"];
                IFPService service = (IFPService)FPServiceHolder.getInstance().getService("fpService");
                IFPObjectService objectService = (IFPObjectService)FPServiceHolder.getInstance().getService("fpObjectService");

                Delivery delivery = objectService.getDeliveryById(objid, user);
            //    CustomerContact cc = new CustomerContact();
            //    if (code == null)
            //        throw new Exception("null contact code !");

                Customer customer = objectService.getCustomerByCustomerID(code.Trim(), user);

            //    if (customer == null)
          //          throw new Exception("this customer is not exist,please input exist customer .");

                if (customer == null)
                    customer = new Customer();

                int handuserid = 0;
                int.TryParse(handleby, out handuserid);
                UserAC handuser = objectService.getUserByID(handuserid, user);

                int requestuserid = 0;
                int.TryParse(requestby, out requestuserid);
                UserAC requestuser = objectService.getUserByID(requestuserid, user);

                DateTime dead = new DateTime();
                if (string.IsNullOrEmpty(deadline))
                    dead = DateTime.Now;
                else
                {
                    var m = deadline.Substring(deadline.Length - 2);
                    if (m.ToLower().Contains("pm") || m.ToLower().Contains("am"))
                    {

                        var datetime = deadline.Split(' ');
                        var date = datetime[0].Split('/');
                        var time = datetime[1].Replace(m, string.Empty).Split(':');

                        if (m.ToLower().Trim() == "pm")
                        {
                            dead = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), int.Parse(time[0]) + 12, int.Parse(time[1]), 0);
                        }
                        else
                        {
                            dead = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), int.Parse(time[0]), int.Parse(time[1]), 0);

                        }
                    }
                    else
                    {
                        dead = DateTime.Now;
                    }
                }

               // if (customer == null)
              //      customer = new Customer();

                if (delivery != null)
                {

                    delivery.assigned_by = user;
                    delivery.deadline = dead;
                    delivery.status = "processing";
                    delivery.handled_by = handuser;
                    delivery.height = height;
                    delivery.isDeleted = false;
                    delivery.length = length;
                    delivery.goods_type = goods_type;
                    delivery.non_order = nonorder;
                    delivery.notes = notes;
                    delivery.number = number;
                    delivery.objectId = objid;
                    delivery.part_no = partno;
                    delivery.requested_by = requestuser;
                    delivery.weight = weight;
                    delivery.width = width;
                    delivery.delivery_type = delivery_type;
                    delivery.status = status;
                    delivery.remarks = remarks;

                    delivery.customer = customer;

                    //cc = delivery.contact;
                    //if (cc != null)
                    //{
                    //    cc.city = city;
                    //    cc.cid = code;
                    //    cc.cname = companyname;
                    //    cc.contact_person = contact;
                    //    cc.createDate = DateTime.Now;
                    //    cc.ctype = "normal";
                    //    cc.customer = customer;
                    //    cc.district = district;
                    //    cc.tel = tel;
                    //    cc.isDeleted = false;
                    //    cc.mobile = mobile;
                    // //   cc.remarks = remarks;
                    //    cc.street1 = street1;
                    //    cc.street2 = street2;
                    //    cc.street3 = street3;
                    //    service.updateCustomerContact(cc, user);
                    //}
                    //else
                    //{
                    //    cc = new CustomerContact();
                    //    cc.city = city;
                    //    cc.cid = code;
                    //    cc.cname = companyname;
                    //    cc.contact_person = contact;
                    //    cc.createDate = DateTime.Now;
                    //    cc.ctype = "normal";
                    //    cc.customer = customer;
                    //    cc.district = district;
                    //    cc.tel = tel;
                    //    cc.isDeleted = false;
                    //    cc.mobile = mobile;
                    // //   cc.remarks = remarks;
                    //    cc.street1 = street1;
                    //    cc.street2 = street2;
                    //    cc.street3 = street3;
                    //    service.addCustomerContact(cc, user);
                    //}


                   // delivery.contact = cc;
                    service.updateDelivery(delivery, user);
                }
                else
                {
                    delivery = new Delivery();

                    delivery.assigned_by = user;
                    delivery.deadline = dead;
                    delivery.status = "processing";
                    delivery.handled_by = handuser;
                    delivery.height = height;
                    delivery.isDeleted = false;
                    delivery.length = length;
                    delivery.non_order = nonorder;
                    delivery.notes = notes;
                    delivery.number = number;
                    delivery.objectId = objid;
                    delivery.part_no = partno;
                    delivery.requested_by = requestuser;
                    delivery.weight = weight;
                    delivery.width = width;
                    delivery.delivery_type = delivery_type;
                    delivery.remarks =remarks ;
                    delivery.goods_type = goods_type;

                    delivery.customer = customer;

                  //  cc.city = city;
                  //  cc.cid = code;
                  //  cc.cname = companyname;
                  //  cc.contact_person = contact;
                  //  cc.createDate = DateTime.Now;
                  //  cc.ctype = "normal";
                  //  cc.customer = customer;
                  //  cc.district = district;
                  //  cc.tel = tel;
                  //  cc.isDeleted = false;
                  //  cc.mobile = mobile;
                  ////  cc.remarks = remarks;
                  //  cc.street1 = street1;
                  //  cc.street2 = street2;
                  //  cc.street3 = street3;
                  //  service.addCustomerContact(cc, user);


                  //  delivery.contact = cc;
                    service.addDelivery(delivery, user);
                }

                List<CustomerContact> customercontacts = new List<CustomerContact>(); //1.1
                if (Session["customercontacts"] != null) //1.1
                    customercontacts = Session["customercontacts"] as List<CustomerContact>;//1.1
              
                foreach (var cc in customercontacts)
                {
                    cc.deliveryid = delivery.objectId;
                    service.addCustomerContact(cc, user);

                    if (delivery != null)
                    {
                        if (delivery.customer != null && delivery.customer.objectId != customer.objectId)
                        {
                            delivery.customer = customer;
                            service.updateDelivery(delivery, user);
                        }
                    }
                }
                Session["customercontacts"] = null;

                return Content("{success:true,result:\"successfully !\",objectid:" + delivery.objectId + "}");
            }
            catch (Exception ex)
            {
                return Content("{success:false,result:\"" + ex.Message + "\",objectid:" + 0 + "}");
            }
        }
Ejemplo n.º 7
0
        public bool add(Customer customer, DbTransaction transaction)
        {

            IFPObjectDAO fpObjectDAO = DAOFactory.getInstance().createFPObjectDAO();
            fpObjectDAO.add(customer,transaction);

            SqlTransaction trans = (SqlTransaction)transaction;
            String sql = "insert into Customer(ObjectId, company_name, company_code) values " +
                "(@ObjectId,@company_name, @company_code)";
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = sql;
            cmd.Transaction = trans;
            cmd.Connection = trans.Connection;
            cmd.Parameters.Add(genSqlParameter("ObjectId", SqlDbType.Int, 10, customer.objectId));
            cmd.Parameters.Add(genSqlParameter("company_code", SqlDbType.NVarChar, 255, customer.company_code));
            cmd.Parameters.Add(genSqlParameter("company_name", SqlDbType.NVarChar, 255, customer.company_name));
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            return true;
        }
Ejemplo n.º 8
0
        private List<Customer> getQueryResult(SqlCommand cmd)
        {
            DbDataReader reader = cmd.ExecuteReader();
            DataTable dt = new DataTable();

            List<Customer> customers = new List<Customer>();
            Customer customer = null;

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

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    customer = new Customer();
                    customer.objectId = getInt(dt.Rows[i]["ObjectId"]);
                    customer.createDate = getDateTime(dt.Rows[i]["CreateDate"]);
                    customer.updateDate = getDateTime(dt.Rows[i]["UpdateDate"]);
                    customer.updateBy = getString(dt.Rows[i]["UpdateBy"]);
                    customer.isDeleted = (getInt(dt.Rows[i]["IsDeleted"]) == 1);
                    customer.company_code = getString(dt.Rows[i]["company_code"]);
                    customer.company_name = getString(dt.Rows[i]["company_name"]);
                    customers.Add(customer);
                }
            }
            return customers;
        }
Ejemplo n.º 9
0
 public bool delete(Customer customer, DbTransaction transaction)
 {
     IFPObjectDAO fpObjectDAO = DAOFactory.getInstance().createFPObjectDAO();
     return fpObjectDAO.delete(customer, transaction);
 }
Ejemplo n.º 10
0
        public object addcustomer(string code, string name, string person, string tel, string address, string cid,string email,string fax,string city,string remark,string mobile,string district,string street2,string street3)
        {

            var result = string.Empty;
            bool bresult = false;
            try
            {
                UserAC user = (UserAC)Session["user"];
                IFPService service = (IFPService)FPServiceHolder.getInstance().getService("fpService");
                IFPObjectService objectService = (IFPObjectService)FPServiceHolder.getInstance().getService("fpObjectService");
                int objectid = 0;
                int.TryParse(cid, out objectid);
                var customer = objectService.getCustomerByID(objectid, user);
                string customer_code = string.Empty;


                if (customer != null)
                    customer_code = customer.company_code.Trim();
                var customer1 = objectService.getCustomerByCustomerID(code.Trim(), user);

                //if ((customer1 != null && customer == null) || (customer1 != null && customer != null && customer.company_code .Trim() != customer1.company_code .Trim ()))
                
                if (false){
                    result = "has exist the company code !";
                    bresult = false;
                }
                else
                {
                    if (customer != null)
                    {
                        customer.company_code = code.Trim();
                        customer.company_name = name.Trim();
                        service.updateCustomer(customer, user);
                        result = "update information successfully !";
                        bresult = true;
                    }
                    else
                    {
                        customer = new Customer();
                        customer.company_code = code.Trim();
                        customer.company_name = name.Trim();
                        service.addCustomer(customer, user);
                        result = "add information successfully !";
                        bresult = true;
                    }

                    if (customer_code != string.Empty && customer_code.Trim() != code.Trim())
                    {
                        var customercontacts = objectService.getContactsByCode(customer_code.Trim(), user);

                        if (customercontacts.Count() > 0)
                        {
                            foreach (var contact in customercontacts)
                            {
                                contact.customer = customer;
                                service.updateCustomerContact(contact, user);
                            }
                        }
                    }

                    var cc = objectService.getCustomerContactByCode(customer_code.Trim(), "default", user);
                    if (cc != null)
                    {
                        cc.address = address.Trim();
                        cc.contact_person = person.Trim();
                        cc.tel = tel.Trim();
                        cc.ctype = "default";
                        cc.customer = customer;
                        cc.city = city;
                        cc.email = email;
                        cc.remarks = remark;
                        cc.mobile = mobile;
                        cc.district = district;

                        cc.street1 = address;
                        cc.street2 = street2;
                        cc.street3 = street3;

                        cc.fax = fax;
                        service.updateCustomerContact(cc, user);
                    }
                    else
                    {
                        cc = new CustomerContact();
                        cc.address = address.Trim();
                        cc.contact_person = person.Trim();
                        cc.tel = tel.Trim();
                        cc.ctype = "default";
                        cc.customer = customer;
                        cc.city = city;
                        cc.email = email;
                        cc.remarks = remark;
                        cc.mobile = mobile;
                        cc.district = district;


                        cc.street1 = address;
                        cc.street2 = street2;
                        cc.street3 = street3;


                        cc.fax = fax;
                        service.addCustomerContact(cc, user);
                    }

                }
                return Content("{success:" + bresult.ToString ().ToLower () + ", result:\"" + result + "\"}");
            }
            catch (Exception ex)
            {
                return Content("{success:false, result:\"" + ex.Message + "\"}");
            }
        }