Beispiel #1
0
        private void addbutton_Click(object sender, EventArgs e)
        {
            User session = app.getSession();
            User user    = new User()
            {
                name          = namefield.Text,
                mobile_number = mobilenumberfield.Text,
                username      = usernamefield.Text,
                password      = passwordfield.Text,
                bid           = session.bid,
            };


            if (user.name == "Name" || user.name == "")
            {
                app.notifyTo(statusLabel, "User name is required", "warning");
            }
            else if (user.mobile_number == "Mobile Number" || user.mobile_number == "")
            {
                app.notifyTo(statusLabel, "User mobile number is required", "warning");
            }
            else if (user.username == "Username" || user.username == "")
            {
                app.notifyTo(statusLabel, "Username is required", "warning");
            }
            else if (user.password == "Password" || user.password == "")
            {
                app.notifyTo(statusLabel, "User Password is required", "warning");
            }
            else
            {
                if (user.name != "" && user.mobile_number != "" && user.username != "" && user.password != "" &&
                    user.name != "Name" && user.mobile_number != "Mobile Number" && user.username != "Username" && user.password != "Password")
                {
                    if (userPictureBox.Image != null)
                    {
                        user.picture = app.imageToByteArray(userPictureBox.Image);
                    }

                    addbutton.Enabled = false;
                    int response = addService.addUser(user);
                    addbutton.Enabled = true;
                    if (response > 0)
                    {
                        namefield.Text         = "Name";
                        mobilenumberfield.Text = "Mobile Number";
                        usernamefield.Text     = "Username";
                        passwordfield.Text     = "Password";
                        app.notifyTo(statusLabel, "User Created Successfully", "success");
                    }
                    else
                    {
                        if (response == -2)
                        {
                            app.notifyTo(statusLabel, "User " + user.username + " already exist", "warning");
                        }
                        if (response == -3)
                        {
                            app.notifyTo(statusLabel, "User with mobile number " + user.mobile_number + " already exist", "warning");
                        }
                        else
                        {
                            app.notifyTo(statusLabel, "Unable to add the user", "warning");
                        }
                    }
                }
                else
                {
                    app.notifyTo(statusLabel, "All fields are required", "warning");
                }
            }
        }
Beispiel #2
0
        public int addBusiness(Business business)
        {
            SSGetService    getService    = new SSGetService();
            SSAddService    addService    = new SSAddService();
            SSRemoteService remoteService = new SSRemoteService();
            SSUpdateService updateService = new SSUpdateService();

            //Business existingBusiness = getService.getBusinessByName(business.business_name);
            //if (existingBusiness.name == null)
            //{

            //    Key key = remoteService.getProductKey(business.product_key);
            //    if (key.product_key != null)
            //    {
            //        if (key.status == "PA")
            //        {
            business.status = "AC";
            //update remote productKet status

            //done

            using (SqlCommand command = new SqlCommand("INSERT INTO ss_business(name,motto,address,telephone,email_address,product_key,machine_name,status,logo)VALUES(@name,@motto,@address,@telephone,@email_address,@product_key,@machine_name,@status,@logo)"))
            {
                command.Parameters.AddWithValue("@name", business.business_name);
                command.Parameters.AddWithValue("@motto", business.motto.ToString().ToUpper());
                command.Parameters.AddWithValue("@address", business.address);
                command.Parameters.AddWithValue("@telephone", business.telephone);
                command.Parameters.AddWithValue("@email_address", business.email_address);
                command.Parameters.AddWithValue("@product_key", business.product_key);
                command.Parameters.AddWithValue("@machine_name", business.machine_name);
                command.Parameters.AddWithValue("@status", business.status);
                if (business.logo != null)
                {
                    command.Parameters.Add("@logo", SqlDbType.Image, business.logo.Length).Value = business.logo;
                }

                int response1 = service.execute(command);
                int response2 = 1;             //service.remoteExecute(command);
                if (response1 > 0 && response2 > 0)
                {
                    Business currentBusiness = getService.getBusinessByName(business.business_name);
                    if (currentBusiness.business_name != null)
                    {
                        //register admin user


                        User user = new User()
                        {
                            bid           = currentBusiness.id,
                            name          = business.name,
                            username      = business.username,
                            password      = business.password,
                            mobile_number = business.telephone,
                            role          = "All",
                        };
                        if (business.logo != null)
                        {
                            user.picture = business.logo;
                        }


                        int res = addService.addUser(user);
                        if (res > 0)
                        {
                            this.addLog(new Log()
                            {
                                type        = "Add Business",
                                statement   = command.CommandText,
                                description = "Added Business" + business.business_name,
                            });
                            return(res);
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        return(-2);
                    }
                }
                else
                {
                    return(-3);
                }
            }
            //        }
            //        else
            //        {
            //            return 201;
            //        }
            //    }
            //    else
            //    {
            //        return -404;
            //    }
            //}
            //else
            //{
            //    return -200;
            //}
        }