public CustomerListPage()
        {
            InitializeComponent();

            IsolatedStorageFile ISOFile = IsolatedStorageFile.GetUserStoreForApplication();
            if (IsolatedStorageSettings.ApplicationSettings.Contains("islogin"))
            {
                if (!(Convert.ToString(IsolatedStorageSettings.ApplicationSettings["islogin"]).ToLower() == "yes"))
                {
                    NavigationService.Navigate(new Uri("/Views/Login/LoginPage.xaml", UriKind.RelativeOrAbsolute));
                }
                else
                {
                    if (ISOFile.FileExists("CurrentLoginUserDetails"))//read current user login details
                    {
                        using (IsolatedStorageFileStream fileStream = ISOFile.OpenFile("CurrentLoginUserDetails", FileMode.Open))
                        {
                            DataContractSerializer serializer = new DataContractSerializer(typeof(LoginViewModel));
                            var ObjUserData = (LoginViewModel)serializer.ReadObject(fileStream);
                            this.txtHeaderOrgName.Text = ObjUserData.organizationName;
                            this.txtHeaderFullName.Text = ObjUserData.firstName + " " + ObjUserData.lastName;
                            _employeeId = Convert.ToInt32(ObjUserData.employeeId);
                            _organizationId = Convert.ToInt32(ObjUserData.organizationId);
                            lstMenuItems.ItemsSource = Utilities.GetMenuItems(MenuCode.CustMgnt);

                            if (Utilities.CheckInternetConnection())
                            {
                                // ----------------------------------------------------------------------
                                // "Network Status: Connected."

                                //====================================================================================================================
                                // Employee module Data Synchronization
                                //====================================================================================================================

                                // Show Loader
                                myIndeterminateProbar.Visibility = Visibility.Visible;

                                CustomerDataProvider _CustomerDataProvider = new CustomerDataProvider();
                                var result = _CustomerDataProvider.GetsyncedCustomerOfflineList("False");
                                if (result != null)
                                {
                                    if (result.Count > 0)
                                    {
                                        try
                                        {
                                            foreach (var itm in result)
                                            {
                                                CustomerRequest obj = new CustomerRequest();
                                                obj.employeeId = _employeeId;
                                                obj.organizationId = _organizationId;
                                                obj.customerId = Convert.ToInt32(itm.customerId);
                                                _customerId = Convert.ToInt32(itm.customerId);
                                                obj.addressLine1 = itm.addressLine1;
                                                obj.street = itm.address_Line2;
                                                obj.firstName = itm.firstName;
                                                obj.lastName = itm.lastName;
                                                obj.city = Convert.ToInt32(itm.city);
                                                obj.state = Convert.ToInt32(itm.state);
                                                obj.area = Convert.ToInt32(itm.area);
                                                obj.email = itm.email;
                                                obj.phone = itm.phone;
                                                obj.notes = string.Empty;

                                                String data = string.Empty;

                                                //Initialize WebClient
                                                WebClient webClient = new WebClient();

                                                //Set Header
                                                webClient.Headers[HttpRequestHeader.Authorization] = Utilities.GetAuthorization();
                                                webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                                                webClient.Headers[HttpRequestHeader.AcceptLanguage] = "en_US";

                                                data = "customerId=" + obj.customerId + "&employeeId=" + obj.employeeId + "&organizationId=" + obj.organizationId + "&firstName=" + obj.firstName + "&lastName=" + obj.lastName + "&phone=" + obj.phone + "&state=" + obj.state + "&area=" + obj.area + "&city=" + obj.city + "&addressLine1=" + obj.addressLine1 + "&street=" + obj.street + "&notes=" + obj.notes + "&email=" + obj.email;
                                                webClient.UploadStringAsync(new Uri(Utilities.GetURL("manageCustomer/updateCustomer")), "POST", data);

                                                //Assign Event Handler
                                                webClient.UploadStringCompleted += wc_UploadSycnedOfflineCompleted;

                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show("Something wrong happened.");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // ----------------------------------------------------------------------
                                //  "Network Status: Not Connected."

                                //====================================================================================================================
                                // Fill Customer List From Offline DB
                                //====================================================================================================================

                                CustomerDataProvider _CustomerDataProvider = new CustomerDataProvider();
                                ListCustomerData = new List<CustomerOfflineViewModel>();
                                foreach (var itm in _CustomerDataProvider.GetAllCustomerOfflineList())
                                {
                                    var Source = "/Assets/Employee/account-circle.png";
                                    if (!string.IsNullOrEmpty(itm.imageName))
                                    {
                                        Source = Utilities.GetMarketplaceURL() + uploadImagePath.CUSTOMER + itm.imageName;
                                    }

                                    ListCustomerData.Add(new CustomerOfflineViewModel { displayFullName = itm.firstName + " " + itm.lastName, displayContact = itm.phone, email = itm.email, stateName = itm.stateName, areaName = itm.areaName, cityName = itm.cityName, addressLine1 = itm.addressLine1, city = itm.city, state = itm.state, area = itm.area, firstName = itm.firstName, lastName = itm.lastName, employeeId = itm.employeeId, customerId = itm.customerId, fullImagePath = Source });
                                };
                                this.lstCustomerItems.ItemsSource = ListCustomerData;

                            }
                        }
                    }
                }
            }
            else
            {
                NavigationService.Navigate(new Uri("/Views/Login/LoginPage.xaml", UriKind.RelativeOrAbsolute));
            }
        }
Example #2
0
        public HomePage()
        {
            InitializeComponent();

            // Show Loader
            myIndeterminateProbar.Visibility = Visibility.Visible;

            IsolatedStorageFile ISOFile = IsolatedStorageFile.GetUserStoreForApplication();
            if (IsolatedStorageSettings.ApplicationSettings.Contains("islogin"))
            {
                if (!(Convert.ToString(IsolatedStorageSettings.ApplicationSettings["islogin"]).ToLower() == "yes"))
                {
                    NavigationService.Navigate(new Uri("/Views/Login/LoginPage.xaml", UriKind.RelativeOrAbsolute));
                }
                else
                {
                    if (ISOFile.FileExists("CurrentLoginUserDetails"))//read current user login details
                    {
                        using (IsolatedStorageFileStream fileStream = ISOFile.OpenFile("CurrentLoginUserDetails", FileMode.Open))
                        {
                            DataContractSerializer serializer = new DataContractSerializer(typeof(LoginViewModel));
                            var ObjUserData = (LoginViewModel)serializer.ReadObject(fileStream);
                            this.txtHeaderOrgName.Text = ObjUserData.organizationName;
                            this.txtHeaderFullName.Text = ObjUserData.firstName + " " + ObjUserData.lastName;
                            _employeeId = Convert.ToInt32(ObjUserData.employeeId);
                            _organizationId = Convert.ToInt32(ObjUserData.organizationId);
                            lstMenuItems.ItemsSource = Utilities.GetMenuItems(MenuCode.Home);

                            if (Utilities.CheckInternetConnection())
                            {
                                // ----------------------------------------------------------------------
                                // "Network Status: Connected."

                                //====================================================================================================================
                                // Employee module Data Synchronization
                                //====================================================================================================================

                                EmployeeDataProvider _EmployeeDataProvider = new Provider.EmployeeDataProvider();
                                var result = _EmployeeDataProvider.GetsyncedEmployeeOfflineList("False");
                                if (result != null)
                                {
                                    if (result.Count > 0)
                                    {
                                        try
                                        {
                                            foreach (var itm in result)
                                            {
                                                EmployeeRequest obj = new EmployeeRequest();
                                                obj.employeeId = Convert.ToInt32(itm.employeeId);
                                                obj.organizationId = Convert.ToInt32(itm.organizationId);
                                                _staffEmployeeId = Convert.ToInt32(itm.staffEmployeeId);
                                                obj.firstName = itm.firstName;
                                                obj.lastName = itm.lastName;
                                                obj.email = itm.email;
                                                obj.businessPhoneCode = itm.businessPhoneCode;  // hardcoded now
                                                obj.businessPhone = itm.businessPhone;
                                                obj.addressLine1 = itm.addressLine1;
                                                obj.salary = itm.salary;
                                                obj.userName = itm.userName;
                                                obj.designation = itm.designation;
                                                obj.empRoleArray = itm.role;

                                                String data = string.Empty;

                                                //Initialize WebClient
                                                WebClient webClient = new WebClient();

                                                //Set Header
                                                webClient.Headers[HttpRequestHeader.Authorization] = Utilities.GetAuthorization();
                                                webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                                                webClient.Headers[HttpRequestHeader.AcceptLanguage] = "en_US";

                                                data = "designation=" + "" + "&staffEmployeeId=" + _staffEmployeeId + "&employeeId=" + obj.employeeId + "&organizationId=" + obj.organizationId + "&firstName=" + obj.firstName + "&lastName=" + obj.lastName + "&email=" + obj.email + "&businessPhoneCode=" + obj.businessPhoneCode + "&businessPhone=" + obj.businessPhone + "&state=" + obj.state + "&area=" + obj.area + "&city=" + obj.city + "&addressLine1=" + obj.addressLine1 + "&salary=" + obj.salary + "&userName=" + obj.userName + "&role=" + obj.empRoleArray;
                                                webClient.UploadStringAsync(new Uri(Utilities.GetURL("manageEmployee/updateEmployee")), "POST", data);

                                                //Assign Event Handler
                                                webClient.UploadStringCompleted += wc_UploadSycnedOfflineCompleted;

                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show("Something wrong happened.");
                                        }
                                    }
                                }

                                CustomerDataProvider _CustomerDataProvider = new CustomerDataProvider();
                                var resultCustomer = _CustomerDataProvider.GetsyncedCustomerOfflineList("False");
                                if (resultCustomer != null)
                                {
                                    if (resultCustomer.Count > 0)
                                    {
                                        try
                                        {
                                            foreach (var itm in resultCustomer)
                                            {
                                                CustomerRequest obj = new CustomerRequest();
                                                obj.employeeId = _employeeId;
                                                obj.organizationId = _organizationId;
                                                obj.customerId = Convert.ToInt32(itm.customerId);
                                                //_customerId = Convert.ToInt32(itm.customerId);
                                                obj.addressLine1 = itm.addressLine1;
                                                obj.street = itm.address_Line2;
                                                obj.firstName = itm.firstName;
                                                obj.lastName = itm.lastName;
                                                obj.city = Convert.ToInt32(itm.city);
                                                obj.state = Convert.ToInt32(itm.state);
                                                obj.area = Convert.ToInt32(itm.area);
                                                obj.email = itm.email;
                                                obj.phone = itm.phone;
                                                obj.notes = string.Empty;

                                                String data = string.Empty;

                                                //Initialize WebClient
                                                WebClient webClient = new WebClient();

                                                //Set Header
                                                webClient.Headers[HttpRequestHeader.Authorization] = Utilities.GetAuthorization();
                                                webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                                                webClient.Headers[HttpRequestHeader.AcceptLanguage] = "en_US";

                                                data = "customerId=" + obj.customerId + "&employeeId=" + obj.employeeId + "&organizationId=" + obj.organizationId + "&firstName=" + obj.firstName + "&lastName=" + obj.lastName + "&phone=" + obj.phone + "&state=" + obj.state + "&area=" + obj.area + "&city=" + obj.city + "&addressLine1=" + obj.addressLine1 + "&street=" + obj.street + "&notes=" + obj.notes + "&email=" + obj.email;
                                                webClient.UploadStringAsync(new Uri(Utilities.GetURL("manageCustomer/updateCustomer")), "POST", data);

                                                //Assign Event Handler
                                                webClient.UploadStringCompleted += wc_UploadSycnedCustomerOfflineCompleted;

                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show("Something wrong happened.");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                NavigationService.Navigate(new Uri("/Views/Login/LoginPage.xaml", UriKind.RelativeOrAbsolute));
            }
        }
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (Utilities.CheckInternetConnection())
            {
                // ----------------------------------------------------------------------
                // "Network Status: Connected."

                // Show Loader
                myIndeterminateProbar.Visibility = Visibility.Visible;

                //====================================================================================================================
                // Clear offline Customer table
                //====================================================================================================================

                CustomerDataProvider _CustomerDataProvider = new CustomerDataProvider();
                var result = _CustomerDataProvider.DeleteAllCustomerOffline();
                if (result == true)
                {
                    // Success
                }

                //====================================================================================================================
                // Fill Customer List
                //====================================================================================================================
                // Parameters
                CustomerRequest obj = new CustomerRequest();
                obj.organizationId = _organizationId;
                obj.set = 1;
                obj.count = Utilities.GetListCount();
                String data = "organizationId=" + obj.organizationId + "&set=" + obj.set + "&count=" + obj.count;

                //Initialize WebClient
                WebClient webClient = new WebClient();
                //Set Header
                webClient.Headers[HttpRequestHeader.Authorization] = Utilities.GetAuthorization();
                webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                webClient.Headers[HttpRequestHeader.AcceptLanguage] = "en_US";
                webClient.UploadStringAsync(new Uri(Utilities.GetURL("manageCustomer/customerList")), "POST", data);
                //Assign Event Handler
                webClient.UploadStringCompleted += wc_UploadLoadCustomerCompleted;
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // ----------------------------------------------------------------------
            // Parameters

            CustomerRequest obj = new CustomerRequest();
            obj.employeeId = _employeeId;  // Logged In User's id
            obj.organizationId = _organizationId; // Logged In organizationId
            obj.customerId = _customerId;  // Logged In User's id
            obj.firstName = txtFirstName.Text.Trim();
            obj.lastName = txtLastName.Text.Trim();
            obj.phone = txtPhone.Text.Trim();
            obj.email = txtEmail.Text.Trim();
            obj.addressLine1 = txtStreet.Text.Trim();
            obj.street = txtStreet.Text.Trim();
            obj.notes = string.Empty;

            if (Utilities.CheckInternetConnection())
            {
                // ----------------------------------------------------------------------
                // "Network Status: Connected."

                ListPickerItem selectedItemState = this.listPickerState.ItemContainerGenerator.ContainerFromItem(this.listPickerState.SelectedItem) as ListPickerItem;
                data_State SelecteddataState = selectedItemState.DataContext as data_State;
                obj.state = Convert.ToInt32(SelecteddataState.stateId);

                ListPickerItem selectedItemArea = this.listPickerArea.ItemContainerGenerator.ContainerFromItem(this.listPickerArea.SelectedItem) as ListPickerItem;
                data_Area SelecteddataArea = selectedItemArea.DataContext as data_Area;
                obj.area = Convert.ToInt32(SelecteddataArea.areaId);

                ListPickerItem selectedItemCity = this.listPickerCity.ItemContainerGenerator.ContainerFromItem(this.listPickerCity.SelectedItem) as ListPickerItem;
                data_City SelecteddatCity = selectedItemCity.DataContext as data_City;
                obj.city = Convert.ToInt32(SelecteddatCity.zipId); // here zipId is cityID

                String data = string.Empty;

                if (Validation() == true)
                {
                    // Show Loader
                    myIndeterminateProbar.Visibility = Visibility.Visible;

                    //====================================================================================================================
                    // Submit Details
                    //====================================================================================================================

                    //Initialize WebClient
                    WebClient webClient = new WebClient();
                    //Set Header
                    webClient.Headers[HttpRequestHeader.Authorization] = Utilities.GetAuthorization();
                    webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                    webClient.Headers[HttpRequestHeader.AcceptLanguage] = "en_US";

                    if (_mode == "Add")
                    {
                        data = "employeeId=" + obj.employeeId + "&organizationId=" + obj.organizationId + "&firstName=" + obj.firstName + "&lastName=" + obj.lastName + "&phone=" + obj.phone + "&state=" + obj.state + "&area=" + obj.area + "&city=" + obj.city + "&addressLine1=" + obj.addressLine1 + "&street=" + obj.street + "&notes=" + obj.notes + "&email=" + obj.email;
                        webClient.UploadStringAsync(new Uri(Utilities.GetURL("manageCustomer/addCustomer")), "POST", data);
                    }
                    if (_mode == "Edit")
                    {
                        data = "customerId=" + obj.customerId + "&employeeId=" + obj.employeeId + "&organizationId=" + obj.organizationId + "&firstName=" + obj.firstName + "&lastName=" + obj.lastName + "&phone=" + obj.phone + "&state=" + obj.state + "&area=" + obj.area + "&city=" + obj.city + "&addressLine1=" + obj.addressLine1 + "&street=" + obj.street + "&notes=" + obj.notes + "&email=" + obj.email;
                        webClient.UploadStringAsync(new Uri(Utilities.GetURL("manageCustomer/updateCustomer")), "POST", data);
                    }

                    //Assign Event Handler
                    webClient.UploadStringCompleted += wc_UploadSaveCompleted;
                }
            }
            else
            {
                // ----------------------------------------------------------------------
                //  "Network Status: Not Connected."

                MessageBoxResult objMessageBox = MessageBox.Show("Right now you are in offline mode. data save and will be sent to the server the next time you are online.", "Network Status !", MessageBoxButton.OKCancel);
                if (objMessageBox == MessageBoxResult.OK)
                {
                    try
                    {
                        if (Validation() == true)
                        {
                            if (_mode == "Add")
                            {
                                MessageBox.Show("You can not create a new customer in offline mode.");
                            }

                            if (_mode == "Edit")
                            {
                                CustomerDataProvider _CustomerDataProvider = new CustomerDataProvider();
                                var result = _CustomerDataProvider.UpdateCustomerOffline(obj, "False");
                                if (result == true)
                                {
                                    MessageBox.Show("successfully Updated.");
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Something wrong happened.");
                    }
                }
            }
        }