Esempio n. 1
0
    protected void lnkOK_Click(object sender, EventArgs e)
    {
        SupplierTransaction supp = new SupplierTransaction();
        OtherTransaction    oth  = new OtherTransaction();

        if (!(supp.VendorExists(oth.Replace(txtVendorName.Text.Trim()))))
        {
            string vUserName = tbUserName.Text.Replace(" ", "");
            //if (vUserName.Length > 8)
            //    vUserName = vUserName.Substring(0, 8).ToUpper();
            //else
            //    vUserName = vUserName.ToUpper();

            if (supp.CheckUser(tbUserName.Text.Trim()))
            {
                string randomPwd = RandomPasswordGenerator.GenerateRandomPassword();

                int vVendorId = supp.InsertUser(connstring, vUserName, EncryptionHelper.Encrypt(randomPwd), ((int)Constant.USERTYPE.VENDOR).ToString().Trim());
                ViewState["sUserID"] = vVendorId;

                web_usercontrol_mobileno uctrlMobileNo1 = (web_usercontrol_mobileno)FindControl("uctrlMobileNo");

                supp.InsertOneTimeSupplier(vVendorId.ToString().Trim(), txtVendorName.Text.Trim(),
                                           ((int)Constant.SUPPLIERTYPE.OneTimeSupplier).ToString().Trim(),
                                           txtEmailAddress.Text.Trim(),
                                           txtAddress1.Text.Trim(),
                                           txtAddress2.Text.Trim(),
                                           txtContactPerson.Text.Trim(),
                                           txtTelephoneNumber.Text.Trim(), uctrlMobileNo1.MobileNumber);

                supp.SaveCategoriesAndSubCategories(vVendorId, ViewState[Constant.QS_CATEGORYID].ToString(), ViewState[Constant.QS_SUBCATEGORYID].ToString());

                string emailOk = "";
                if (SendEmail())
                {
                    emailOk = " and notified";
                }
                lblMessage.Text = txtVendorName.Text.Trim() + " has been successfully added" + emailOk + ".";
                lnkClose.Attributes.Add("onclick", "AddSuppliersB('" + vVendorId + "', '" + txtVendorName.Text.Trim() + "');");
                DisableFields();
            }
            else
            {
                lblMessage.Text = tbUserName.Text.Trim() + " already exists.";
            }
        }
        else
        {
            lblMessage.Text = txtVendorName.Text.Trim() + " already exists in the vendor list.";
        }
    }