Example #1
0
        private void DoSave()
        {
            var data = new customertbl
            {
                customerName   = TxtCustomerName.Text,
                customerEmail  = TxtCusEmail.Text,
                companyName    = TxtCompanyName.Text,
                companyAddress = TxtCompanyAddress.Text,
                companyPhone   = TxtPhoneNo.Text,
                companyEmail   = TxtComEmail.Text,
                accountNo      = ParseInt(TxtAccountNo.SelectedValue),
                creaBy         = currentUser,
                creaDate       = DatetimeHelper.GetDatetimeNow()
            };

            if (TxtAccountNo.SelectedValue != "-1")
            {
                data.accountNo = ParseInt(TxtAccountNo.SelectedValue);
            }

            var ret = customerControl.AddData(data);

            if (ret.Result)
            {
                ClearFields();
                SetLayout(ModeForm.ViewData);
                Alert("data berhasil disimpan");
            }
            else
            {
                Alert("Gagal menyimpan data");
            }
        }
Example #2
0
        private void DoUpdate()
        {
            int id   = ParseInt(TxtCustomerNo.Text);
            var data = new customertbl
            {
                customerNo     = id,
                customerName   = TxtCustomerName.Text,
                customerEmail  = TxtCusEmail.Text,
                companyName    = TxtCompanyName.Text,
                companyAddress = TxtCompanyAddress.Text,
                companyPhone   = TxtPhoneNo.Text,
                companyEmail   = TxtComEmail.Text,
                modBy          = currentUser,
                modDate        = DatetimeHelper.GetDatetimeNow()
            };

            if (TxtAccountNo.SelectedValue != "-1")
            {
                data.accountNo = ParseInt(TxtAccountNo.SelectedValue);
            }

            var ret = customerControl.UpdateData(id.ToString(), data);

            if (ret.Result)
            {
                ClearFields();
                SetLayout(ModeForm.ViewData);
                Alert("Data berhasil diubah");
            }
            else
            {
                Alert("Gagal mengubah data");
            }
        }
Example #3
0
        public async Task <bool> AddData2(customertbl obj)
        {
            try
            {
                using (var context = new smlpobDB())
                {
                    context.customertbls.Add(obj);
                    await context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                LogHelpers.source  = this.GetType().Name;
                LogHelpers.message = ex.Message;
                LogHelpers.user    = "";
                LogHelpers.WriteLog();
            }

            return(false);
        }
        public async Task <bool> UpdateData(string id, customertbl obj)
        {
            try
            {
                if (id != obj.customerNo.ToString())
                {
                    return(false);
                }

                using (var context = new smlpobDB())
                {
                    context.customertbls.Attach(obj);
                    context.Entry(obj).Property(x => x.customerName).IsModified   = true;
                    context.Entry(obj).Property(x => x.customerEmail).IsModified  = true;
                    context.Entry(obj).Property(x => x.companyName).IsModified    = true;
                    context.Entry(obj).Property(x => x.companyAddress).IsModified = true;
                    context.Entry(obj).Property(x => x.companyPhone).IsModified   = true;
                    context.Entry(obj).Property(x => x.companyEmail).IsModified   = true;
                    context.Entry(obj).Property(x => x.accountNo).IsModified      = true;
                    context.Entry(obj).Property(x => x.modBy).IsModified          = true;
                    context.Entry(obj).Property(x => x.modDate).IsModified        = true;
                    await context.SaveChangesAsync();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogHelpers.source  = this.GetType().Name;
                LogHelpers.message = ex.Message;
                LogHelpers.user    = "";
                LogHelpers.WriteLog();
            }

            return(false);
        }
        protected async void BtnDaftar_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(txtemail.Text))
                {
                    var seldata = context.customertbls.Where(x => x.customerEmail == txtemail.Text).ToList();
                    if (seldata != null && seldata.Count > 0)
                    {
                        CommonWeb.Alert(this, "Email ini sudah terdaftar");
                    }
                    else
                    {
                        try
                        {
                            //register to asp membership first!
                            MembershipUser user = Membership.CreateUser(txtemail.Text, txtpassword.Text, txtemail.Text);
                            //account
                            string pwd     = Crypto.Encrypt(txtpassword.Text);
                            var    NewItem = new accounttbl()
                            {
                                username        = txtemail.Text,
                                password        = pwd,
                                roleName        = "pelanggan",
                                creaBy          = "registration system",
                                creaDate        = DatetimeHelper.GetDatetimeNow(),
                                isEmailVerified = "0"
                            };

                            //customers
                            var IDS   = txtemail.Text;
                            var idacc = (from x in context.accounttbls
                                         where x.username == IDS
                                         select x.accountNo).FirstOrDefault();
                            var NewItem2 = new customertbl()
                            {
                                customerName   = txtusername.Text,
                                customerEmail  = txtemail.Text,
                                companyName    = txtcompanyname.Text,
                                companyAddress = txtaddress.Text,
                                companyPhone   = txtphone.Text,
                                companyEmail   = txtcompanyemail.Text,
                                accountNo      = idacc,
                                creaBy         = "registration system",
                                creaDate       = DatetimeHelper.GetDatetimeNow()
                            };
                            context.accounttbls.Add(NewItem);
                            context.customertbls.Add(NewItem2);
                            context.SaveChanges();

                            var    roleFromAccountTable = registerControls.GetRole(txtemail.Text);
                            string role = roleFromAccountTable;
                            Roles.AddUserToRole(txtemail.Text, role);

                            //kirim email

                            var subject     = "Aktivasi Akun untuk Sistem Informasi Pelayanan Online Balitanah";
                            var mainMessage = "Silahkan klik link berikut untuk mengaktivasi akun anda:";
                            var message     = mainMessage + $"<br> <a href='{ConfigurationManager.AppSettings["RootWebUrl"]}/Pages/Public/Activation.aspx?userId={txtemail.Text}'>Aktivasi Akun</a>";
                            var msgPhone    = mainMessage + $" { ConfigurationManager.AppSettings["RootWebUrl"]}/Pages/Public/Activation.aspx?userId={txtemail.Text}";
                            var ret         = EmailService.SendEmail(subject, message, txtemail.Text);
                            await SmsService.SendSms(msgPhone, txtphone.Text);

                            //var userAdded = Membership.GetUser(txtemail.Text);
                            //if (userAdded != null)
                            //{
                            //    userAdded.IsApproved = true;
                            //    userAdded.UnlockUser();
                            //    Membership.UpdateUser(userAdded);

                            //}
                            Response.Redirect("RegisterDone.aspx", false);
                            Context.ApplicationInstance.CompleteRequest();
                        }
                        catch (Exception ex)
                        {
                            TxtStatus.Text     = "Gagal menyimpan data registrasi, silakan isi dengan lengkap data-data yang diperlukan.";
                            LogHelpers.source  = this.GetType().ToString();
                            LogHelpers.message = "fail to register user:"******"Gagal menyimpan data registrasi, silakan isi dengan lengkap data-data yang diperlukan.";
            }
        }
Example #6
0
        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                //update
                if (!string.IsNullOrEmpty(TxtID.Value))
                {
                    var IDS2     = int.Parse(TxtID.Value);
                    var NewItem2 = (from x in context.customertbls
                                    where x.customerNo == IDS2
                                    select x).FirstOrDefault();
                    NewItem2.customerName   = txtNama.Text;
                    NewItem2.customerEmail  = txtEmail.Text;
                    NewItem2.companyName    = txtPerusahaan.Text;
                    NewItem2.companyAddress = txtPerusahaan.Text;
                    NewItem2.companyPhone   = txtNoTelepon.Text;
                    NewItem2.companyEmail   = txtCompanyEmail.Text;
                    NewItem2.creaBy         = "Coba";
                    NewItem2.modBy          = "Cobaa";
                    NewItem2.creaDate       = DateTime.Now;
                    NewItem2.modDate        = DateTime.Now;
                    //NewItem2.customerNo = Convert.ToInt32(TxtcustomerNo.Text);

                    var IDS    = txtEmail.Text;
                    var idacc1 = (from x in context.customertbls
                                  where x.customerEmail == IDS
                                  select x.accountNo).FirstOrDefault();
                    var NewItem = (from x in context.accounttbls
                                   where x.accountNo == idacc1
                                   select x).FirstOrDefault();

                    //var IDS = txtemai;
                    //var NewItem = (from x in context.accounttbls
                    //               where x.accountNo == IDS
                    //               select x).FirstOrDefault();
                    NewItem.username        = txtEmail.Text;
                    NewItem.password        = txtPassword.Text;
                    NewItem.roleName        = "Customer";
                    NewItem.creaBy          = "Coba";
                    NewItem.modBy           = "Cobaaa";
                    NewItem.creaDate        = DateTime.Now;
                    NewItem.modDate         = DateTime.Now;
                    NewItem.isEmailVerified = "0";
                    //NewItem.accountNo = Convert.ToInt32(TxtAccountNo.Text);
                }
                else //add new
                {
                    var seldata2 = context.customertbls.Select(x => x.customerEmail).ToList();
                    foreach (var item in seldata2)
                    {
                        if (txtEmail.Text == item)
                        {
                            TxtStatus.Text = "Email Sudah Terdaftar";
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Email Sudah Terdaftar')", true);
                        }
                        else if (txtEmail.Text != item)
                        {
                            //account
                            var NewItem = new accounttbl()
                            {
                            };
                            NewItem.username        = txtEmail.Text;
                            NewItem.password        = txtPassword.Text;
                            NewItem.roleName        = "Customer";
                            NewItem.creaBy          = "Coba";
                            NewItem.modBy           = "Cobaaa";
                            NewItem.creaDate        = DateTime.Now;
                            NewItem.modDate         = DateTime.Now;
                            NewItem.isEmailVerified = "0";
                            context.accounttbls.Add(NewItem);

                            //customor
                            var IDS   = txtEmail.Text;
                            var idacc = (from x in context.accounttbls
                                         where x.username == IDS
                                         select x.accountNo).FirstOrDefault();
                            var NewItem2 = new customertbl()
                            {
                            };
                            NewItem2.customerName   = txtNama.Text;
                            NewItem2.customerEmail  = txtEmail.Text;
                            NewItem2.companyName    = txtPerusahaan.Text;
                            NewItem2.companyAddress = txtPerusahaan.Text;
                            NewItem2.companyPhone   = txtNoTelepon.Text;
                            NewItem2.companyEmail   = txtCompanyEmail.Text;
                            NewItem2.accountNo      = idacc;
                            NewItem2.creaBy         = "Coba";
                            NewItem2.modBy          = "Cobaa";
                            NewItem2.creaDate       = DateTime.Now;
                            NewItem2.modDate        = DateTime.Now;
                            //data2.accountNo = Convert.ToInt32(txtAccountNo.Text);
                            context.customertbls.Add(NewItem2);
                        }
                        else
                        {
                            TxtStatus.Text = "gagal save";
                        }
                    }
                }
                context.SaveChanges();
                PanelGrid.Visible  = true;
                PanelInput.Visible = false;
                RefreshGrid();
            }
            catch (Exception ex)
            {
                TxtStatus.Text = "gagal save --> " + ex.Message;
            }
        }