Example #1
0
//public Customer(int? id, string password) {
//            this.Id = id;
//            this.Password = password;
//        }
        public int SaveData()
        {
            //int rc;
            //int count = 0;
            //Customer[] customers = Customer.GetCustomers(new CustomerParameters {}, out rc);
            //foreach(Customer customer in customers)
            //{
            //    if(CardId==customer.CardId)
            //    {
            //        count = 1;
            //    }
            //    else
            //    {
            //        count = 0;
            //    }
            //}
            //if (count == 0)
            //{
            int rc;
            int count  = 0;
            int result = 0;
            int count2 = 0;
            //int islength = 0;
            int count3 = 0;

            Customer[] customers = Customer.GetCustomers(new CustomerParameters {
            }, out rc);

            foreach (Customer customer in customers)
            {
                if (customer.Username.ToLower() == Username.ToLower())
                {
                    count = 1;
                }
            }
            if (this.Telephone != null && this.Telephone.Length != 10) //not 10 numbers
            {
                count2 = 1;
            }

            if (count2 == 0) //lenght is 10
            {
                if (this.Telephone != null && this.Telephone[0].ToString() == "0" && this.Telephone[1].ToString() == "5" && (this.Telephone[2].ToString() == "6" || this.Telephone[2].ToString() == "9"))
                {
                    count3 = 1;
                }
            }
            if (count == 0 && count3 == 1)
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection  = new SqlConnection(cstr.con);
                    cmd.Connection.Open();
                    cmd.CommandText = "SaveCustomerData";

                    if (Username != null)
                    {
                        cmd.Parameters.AddWithValue("username", Username);
                    }
                    if (CardId != null)
                    {
                        cmd.Parameters.AddWithValue("card_id", CardId);
                    }
                    if (Telephone != null)
                    {
                        cmd.Parameters.AddWithValue("telephone", Telephone);
                    }
                    if (CountryId != null)
                    {
                        cmd.Parameters.AddWithValue("country_id", CountryId);
                    }
                    if (CityId != null)
                    {
                        cmd.Parameters.AddWithValue("city_id", CityId);
                    }
                    if (TownId != null)
                    {
                        cmd.Parameters.AddWithValue("town_id", TownId);
                    }
                    if (Street != null)
                    {
                        cmd.Parameters.AddWithValue("street", Street);
                    }
                    if (Password != null)
                    {
                        cmd.Parameters.AddWithValue("password", Password);
                    }
                    if (Name != null)
                    {
                        cmd.Parameters.AddWithValue("name", Name);
                    }


                    SqlParameter idParam = cmd.Parameters.Add("@id", SqlDbType.Int);
                    idParam.Direction = ParameterDirection.InputOutput;
                    idParam.Value     = this.Id;

                    SqlParameter resultParam = cmd.Parameters.Add("@result", SqlDbType.Int);
                    resultParam.Direction = ParameterDirection.InputOutput;

                    // idParam.Value = this.Id;

                    int c = cmd.ExecuteNonQuery();

                    this.Id = Convert.ToInt32(idParam.Value);
                    result  = Convert.ToInt32(resultParam.Value);
                    cmd.Connection.Close();
                }
            }
            else if (count == 1)//user exist
            {
                result = 2;
            }
            else if (count2 == 1)//number not 10digit
            {
                result = 0;
            }
            else if (count2 == 0 && count3 == 0)// not standad
            {
                result = 3;
            }
            return(result);

            //}
            //else
            //{
            //    int result = 0;
            //    return result;
            //}
        }