Exemple #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();
        }
        public bool add(CustomerContact cc, DbTransaction transaction)
        {

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

            SqlTransaction trans = (SqlTransaction)transaction;
            String sql = "insert into Customer_Contact(ObjectId, cid, contact_person,tel,address,email,fax,ctype,street1,street2,street3,city,remarks,mobile,district,deliveryid, customer, company_name) values " +
                "(@ObjectId, @cid,@contact_person,@tel,@address,@email,@fax,@ctype,@street1,@street2,@street3,@city,@remarks,@mobile,@district,@deliveryid, @customer,@company_name)";
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = sql;
            cmd.Transaction = trans;
            cmd.Connection = trans.Connection;

            cmd.Parameters.Add(genSqlParameter("ObjectId", SqlDbType.Int, 10, cc.objectId));
            cmd.Parameters.Add(genSqlParameter("cid", SqlDbType.NVarChar, 50, cc.customer.company_code));
            cmd.Parameters.Add(genSqlParameter("contact_person", SqlDbType.NVarChar, 255, cc.contact_person));
            cmd.Parameters.Add(genSqlParameter("tel", SqlDbType.NVarChar, 50, cc.tel));
            cmd.Parameters.Add(genSqlParameter("address", SqlDbType.NVarChar,50,cc.address));
            cmd.Parameters.Add(genSqlParameter("email", SqlDbType.NVarChar, 50,cc.email));
            cmd.Parameters.Add(genSqlParameter("fax", SqlDbType.NVarChar, 50,cc.fax));
            cmd.Parameters.Add(genSqlParameter("ctype", SqlDbType.NVarChar, 50, cc.ctype));


            cmd.Parameters.Add(genSqlParameter("street1", SqlDbType.NVarChar, 255, cc.street1));
            cmd.Parameters.Add(genSqlParameter("street2", SqlDbType.NVarChar, 255, cc.street2));
            cmd.Parameters.Add(genSqlParameter("street3", SqlDbType.NVarChar, 255, cc.street3));
            cmd.Parameters.Add(genSqlParameter("city", SqlDbType.NVarChar, 50, cc.city));
            cmd.Parameters.Add(genSqlParameter("remarks", SqlDbType.NVarChar, 255, cc.remarks));
            cmd.Parameters.Add(genSqlParameter("mobile", SqlDbType.NVarChar, 50, cc.mobile));
            cmd.Parameters.Add(genSqlParameter("district", SqlDbType.NVarChar, 50, cc.district));

            cmd.Parameters.Add(genSqlParameter("deliveryid", SqlDbType.Int, 10, cc.deliveryid));
            cmd.Parameters.Add(genSqlParameter("customer", SqlDbType.Int, 10, cc.customer.objectId));
            cmd.Parameters.Add(genSqlParameter("company_name", SqlDbType.NVarChar, 255, cc.company_name));
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            return true;
        }
 public bool delete(CustomerContact cc, DbTransaction transaction)
 {
     IFPObjectDAO fpObjectDAO = DAOFactory.getInstance().createFPObjectDAO();
     return fpObjectDAO.delete(cc, transaction);
 }
        private List<CustomerContact> getQueryResult(SqlCommand cmd)
        {

            ICustomerDAO customerDAO = DAOFactory.getInstance().createCustomerDAO();
            DbDataReader reader = cmd.ExecuteReader();
            DataTable dt = new DataTable();

            List<CustomerContact> contacts = new List<CustomerContact>();
            CustomerContact contact = null;

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

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

                    contact.objectId = getInt(dt.Rows[i]["ObjectId"]);
                    contact.createDate = getDateTime(dt.Rows[i]["CreateDate"]);
                    contact.updateDate = getDateTime(dt.Rows[i]["UpdateDate"]);
                    contact.updateBy = getString(dt.Rows[i]["UpdateBy"]);
                    contact.isDeleted = (getInt(dt.Rows[i]["IsDeleted"]) == 1);

                    contact.customer = customerDAO.getByID(getInt(dt.Rows[i]["customer"]),cmd.Transaction);
                    contact.contact_person = getString(dt.Rows[i]["contact_person"]);
                    contact.tel = getString(dt.Rows[i]["tel"]);
                    contact.address = getString(dt.Rows[i]["address"]);
                    contact.email = getString(dt.Rows[i]["email"]);
                    contact.fax = getString(dt.Rows[i]["fax"]);
                    contact.ctype = getString(dt.Rows[i]["ctype"]);
                    contact.cid = getString(dt.Rows[i]["cid"]);

                    contact.street1 = getString(dt.Rows[i]["street1"]);
                    contact.street2 = getString(dt.Rows[i]["street2"]);
                    contact.street3 = getString(dt.Rows[i]["street3"]);
                    contact.city = getString(dt.Rows[i]["city"]);
                    contact.remarks = getString(dt.Rows[i]["remarks"]);
                    contact.mobile = getString(dt.Rows[i]["mobile"]);
                    contact.district = getString(dt.Rows[i]["district"]);
                    contact.deliveryid = getInt(dt.Rows[i]["deliveryid"] == null ? "0" : dt.Rows[i]["deliveryid"]);

                    if (contact.customer != null)
                        contact.cname = contact.customer.company_name;
                    contact.company_name = getString(dt.Rows[i]["company_name"]);
                    contacts.Add(contact);
                }
            }
            return contacts;
        }
Exemple #5
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);
        }
Exemple #6
0
        public bool deleteCustomerContact(CustomerContact cc, UserAC user)
        {
            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                ICustomerContactDAO ccDao = DAOFactory.getInstance().createCustomerContactDAO();

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

                ccDao.delete(cc, transaction);
                transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            } 
        }
Exemple #7
0
        public object addcustomer( string objectid, string name, string street1, string street2, string street3, string city,string district, string contact, string tel, string mobile,
                            string customerid)
        {

            var result = string.Empty;
            List<CustomerContact> customercontacts = new List<CustomerContact>();
            if (Session["customercontacts"] != null)
                customercontacts = Session["customercontacts"] as List<CustomerContact>;
            try
            {

                int deliveryid = 0;
                int.TryParse(objectid, out deliveryid);
                if (deliveryid == 0)
                {
                  //  throw new Exception("Please add a delivery before adding customer contact!");
                }
                UserAC user = (UserAC)Session["user"];
                IFPService service = (IFPService)FPServiceHolder.getInstance().getService("fpService");
                IFPObjectService objectService = (IFPObjectService)FPServiceHolder.getInstance().getService("fpObjectService");

                var customer = objectService.getCustomerByCustomerID(customerid, user);
                if (customer == null)
                {
                    throw new Exception("The customer is not exist!");
                }
                string customer_code = string.Empty;                

                CustomerContact cc = new CustomerContact();

                cc = new CustomerContact();
                cc.objectId = -(customercontacts.Count() + 1);
                cc.customer = customer;
                cc.street1 =street1 ;
                cc.street2 =street2 ;
                cc.street3 =street3 ;
                cc.contact_person = contact;
                cc.tel = tel.Trim();
                cc.ctype = "normal";
                cc.customer = customer;
                cc.deliveryid = deliveryid;
                cc.city = city;
                cc.district = district;
                cc.mobile = mobile;

                customercontacts.Add(cc);
                Session["customercontacts"] = customercontacts;

                //if (deliveryid > 0)
                //{
                //    //  throw new Exception("Please add a delivery before adding customer contact!");
                //    service.addCustomerContact(cc, user);

                //    Delivery de = objectService.getDeliveryById(deliveryid, user);
                //    if (de != null)
                //    {
                //        if (de.customer != null && de.customer.objectId != customer.objectId)
                //        {
                //            de.customer = customer;
                //            service.updateDelivery(de, user);
                //        }
                //    }
                //    Session["customercontacts"] = null;
                //}
               

                return Content("{success:true, result:\"" + "add successfully!" + "\"}");
            }
            catch (Exception ex)
            {
                return Content("{success:false, result:\"" + ex.Message + "\"}");
            }
        }
Exemple #8
0
        private object getdefaultcustomerbyquery(string query)
        {
            UserAC user = (UserAC)Session["user"];
            IFPService service = (IFPService)FPServiceHolder.getInstance().getService("fpService");
            IFPObjectService objectService = (IFPObjectService)FPServiceHolder.getInstance().getService("fpObjectService");

            List<Customer> customers = objectService.getDefaultCustomers(query, 10, 0, null, true, user);

            if (customers.Count == 0)
                return Content("{tags:[{id:'0',name:' '}]}");

            StringBuilder usersJson = new StringBuilder("{tags:[");
            for (int i = 0; i < customers.Count; i++)
            {
                CustomerContact cc = objectService.getCustomerContactByCode(customers[i].company_code, "default", user);
                if (i > 0)
                    usersJson.Append(",");

                if (cc == null)
                    cc = new CustomerContact();
                usersJson.Append("{code:'").Append(customers[i].company_code).Append("',")
                     .Append("objectid:'").Append(customers[i].objectId).Append("',");
                if (cc.street1 != null && cc.street1.Trim() != string.Empty)
                    usersJson.Append("street1:'").Append(cc.street1).Append("',");
                else
                    usersJson.Append("street1:'").Append(cc.street1 == null ? string.Empty : cc.street1.ToString().Replace("'", "\\\'")).Append("',");
                usersJson.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).Append("',")
                .Append("city:'").Append(cc.city).Append("',")
                .Append("contact:'").Append(cc.contact_person).Append("',")
                .Append("tel:'").Append(cc.tel).Append("',")
                .Append("mobile:'").Append(cc.mobile).Append("',")
                .Append("remark:'").Append(cc.remarks).Append("',")
                .Append("name:'").Append(customers[i].company_name).Append("'}");
            }
            usersJson.Append("]}");

            return Content(usersJson.ToString());
        }
Exemple #9
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 + "\"}");
            }
        }