예제 #1
0
 internal LoginUserItem GetDefaultUser()
 {
     CurrentItem = new LoginUserItem();
     CurrentItem.SetDefaultUser();
     CurrentItem = DataProvider.SelectItem(0, FormPositioningEnum.First) as LoginUserItem;
     return(CurrentItem);
 }
예제 #2
0
 public bool ChangePW(string UserName, string Password)
 {
     CurrentItem = new LoginUserItem();
     CurrentItem.Fields["Login"].SetValue(Crypt.Encripta(UserName));
     CurrentItem = DataProvider.SelectItem(0, FormPositioningEnum.First) as LoginUserItem;
     CurrentItem.Fields["Password"].SetValue(Crypt.Encripta(Password));
     return(DataProvider.UpdateItem(CurrentItem) > 0);
 }
예제 #3
0
        /// <summary>
        /// Update um registo de usuario
        /// </summary>
        private void UpdateUser()
        {
            try
            {
                if (CurrentGroup != null && (bool)CurrentGroup.Fields["IsAdmin"].Value)
                {
                    string vgPass = "";
                    if (TextBox8.Text != "")
                    {
                        if (TextBox8.Text == TextBox9.Text)
                        {
                            vgPass = TextBox8.Text.ToUpper();
                        }
                        else
                        {
                            ErrorList.Add("SenhaErrada", "Confirmação de senha invalida");
                            return;
                        }
                    }
                    try
                    {
                        LoginUserItem item = new LoginUserItem();

                        item.Fields["Group"].SetValue(ListBox5.SelectedValue);

                        item.Fields["Login"].SetValue(Crypt.Encripta(TextBox7.Text));

                        item.Fields["Id"].SetValue(ListBox6.SelectedValue);
                        if (vgPass != "")
                        {
                            item.Fields["Password"].SetValue(Crypt.Encripta(vgPass));
                        }
                        else
                        {
                            LoginUserItem OldItem = vgMembership.GetUser(ListBox6.SelectedValue);
                            item.Fields["Password"].SetValue(OldItem.Fields["Password"].GetFormattedValue());
                        }
                        item.Fields["Obs"].SetValue(Crypt.Encripta(TextBox10.Text));
                        item.Fields["Name"].SetValue(Crypt.Encripta(TextBox11.Text.ToUpper()));
                        vgMembership.UpdateUser(item);
                        ListBox6.Items[ListBox6.SelectedIndex].Text = TextBox7.Text;
                        ListBox6.Enabled = true;
                        ListBox5.Enabled = true;
                        EnableUserButtons(true, true, true, true);
                    }
                    catch (Exception e)
                    {
                        ErrorList.Add("UpdateUserError", e.Message);
                    }
                }
            }
            catch
            {
            }
        }
예제 #4
0
 private bool CheckUser(string UserName, string Password)
 {
     CurrentItem = new LoginUserItem();
     CurrentItem.Fields["Login"].SetValue(Crypt.Encripta(UserName));
     CurrentItem = DataProvider.SelectItem(0, FormPositioningEnum.First) as LoginUserItem;
     if (CurrentItem != null)
     {
         return(CurrentItem.Fields["Password"].Value.Equals(Crypt.Encripta(Password)));
     }
     return(false);
 }
예제 #5
0
        /// <summary>
        /// Metodo que mostra o registro do usuario selecionado
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ChangedUser()
        {
            if (ListBox6.SelectedItem != null)
            {
                LoginUserItem vgUser = vgMembership.GetUser(Crypt.Encripta(ListBox6.SelectedItem.Text));
                TextBox7.Text     = Crypt.Decripta(vgUser.Fields["Login"].GetFormattedValue());
                TextBox11.Text    = Crypt.Decripta(vgUser.Fields["Name"].GetFormattedValue());
                TextBox10.Text    = Crypt.Decripta(vgUser.Fields["Obs"].GetFormattedValue());
                TextBox9.Enabled  = true;
                TextBox9.Text     = "";
                TextBox10.Enabled = true;
                TextBox8.Text     = "";
                TextBox7.Enabled  = true;
                TextBox8.Enabled  = true;

                ViewState["IncluiUsuario"] = false;
                EnableUserButtons(true, true, true, true);
            }
        }
예제 #6
0
        private void CancelUserChanges()
        {
            try
            {
                if (CurrentGroup != null && (bool)CurrentGroup.Fields["IsAdmin"].Value)
                {
                    if (ViewState["IncluiUsuario"] != null && (bool)ViewState["IncluiUsuario"] == true)
                    {
                        TextBox7.Text              = "";
                        TextBox11.Text             = "";
                        TextBox9.Text              = "";
                        TextBox8.Text              = "";
                        TextBox10.Text             = "";
                        ViewState["IncluiUsuario"] = false;
                    }
                    else if (ListBox6.SelectedIndex != -1 && ListBox6.SelectedValue != null)
                    {
                        LoginUserItem vgUser = vgMembership.GetUser(Crypt.Encripta(ListBox6.SelectedItem.Text));
                        TextBox7.Text  = Crypt.Decripta(vgUser.Fields["Login"].GetFormattedValue());
                        TextBox11.Text = Crypt.Decripta(vgUser.Fields["Name"].GetFormattedValue());

                        TextBox10.Text = Crypt.Decripta(vgUser.Fields["Obs"].GetFormattedValue());
                    }
                    EnableUserButtons(true, true, true, true);
                    ListBox6.Enabled  = true;
                    ListBox5.Enabled  = true;
                    TextBox9.Enabled  = true;
                    TextBox7.Enabled  = true;
                    TextBox8.Enabled  = true;
                    TextBox10.Enabled = true;
                }
            }
            catch
            {
            }
        }
예제 #7
0
        private void p1_client_print(bool want_report, bool want_dcm)
        {
            bool print_dcm_ok    = false;
            bool print_report_ok = false;

            try
            {
                ui_pre_print();

                //根据实际情况更新打印需求
                want_report = want_report && this.lblReportPrintFlag.Text.Contains("打印");
                want_dcm    = want_dcm && this.lblDcmPrintFlag.Text.Contains("打印");

                //实际情况不允许打印
                if (!want_report && !want_dcm)
                {
                    return;
                }

                #region 多次打印,需身份验证
                string printer_id        = "";
                bool   need_verification = (want_report && this.lblReportPrintFlag.Text.Contains("已")) ||
                                           (want_dcm && this.lblDcmPrintFlag.Text.Contains("已"));
                if (need_verification)
                {
                    LoginUserItem item = get_login();
                    if (item == null)
                    {
                        return;
                    }

                    start_p1_tcp_client();
                    connect_p1_tcp_client(_p1_server_ip, _p1_server_port);

                    Helper.add_text(this.txtMsg,
                                    string.Format("{0}连接数据服务器P1: {1}{0}",
                                                  Environment.NewLine,
                                                  (Helper.is_tcp_client_normal(_p1_tcp_client) ? "成功" : "失败")));
                    Helper.add_text(this.txtMsg,
                                    string.Format("{0}向数据服务器P1发身份验证命令, 等待服务器P1返回结果...{0}",
                                                  Environment.NewLine));

                    //发验证命令
                    LoginCmd login = new LoginCmd();
                    login.sender_name           = this_name;
                    login.login_user.login_name = item.login_name;
                    login.login_user.login_psw  = item.login_psw;
                    LoginCmdAck login_ack = Helper.tcp_client_send_and_response(_p1_tcp_client, login) as LoginCmdAck;

                    Helper.add_text(this.txtMsg,
                                    string.Format("{0}数据服务器P1返回身份验证结果: {1}{0}",
                                                  Environment.NewLine,
                                                  (login_ack == null ? "失败" : (login_ack.status != 0 ? "失败" : "成功"))));

                    if (login_ack == null)
                    {
                        throw new MsgBoxException("通信异常", "请确认与数据服务器P1之间的网络连接是否正常.");
                    }
                    if (login_ack.status != 0)
                    {
                        throw new MsgBoxException("验证失败",
                                                  string.Format("密码错误或者工号不存在.错误代码={0}.", login_ack.status));
                    }

                    //记录工号,后面备用
                    printer_id = item.login_name;
                }
                #endregion

                //可以考虑将三项任务中的2项改为并行执行,调用线程等待这2项任务的返回结果
                Task <bool> task_dcm    = null;
                Task <bool> task_report = null;
                #region 胶片本地打印
                if (is_local_print_dcm && want_dcm)
                {
                    task_dcm = Task.Factory.StartNew(() => {
                        return(local_print_dcm(this.lblUserID.Text.Trim(), printer_id));
                    });
                }
                #endregion
                #region 报告本地打印
                if (is_local_print_report && want_report)
                {
                    task_report = Task.Factory.StartNew(() => {
                        return(local_print_report(this.lblUserID.Text.Trim(), printer_id));
                    });
                }
                #endregion
                #region 报告和(/或者)胶片用服务器打印
                try
                {
                    if ((!is_local_print_report && want_report) ||
                        (!is_local_print_dcm && want_dcm))
                    {
                        Helper.add_text(this.txtMsg,
                                        string.Format("{0}连接数据服务器P1: {1}{0}",
                                                      Environment.NewLine,
                                                      (Helper.is_tcp_client_normal(_p1_tcp_client) ? "成功" : "失败")));

                        string which = "";
                        if ((!is_local_print_report && want_report) &&
                            (!is_local_print_dcm && want_dcm))
                        {
                            which = "报告和胶片";
                        }
                        else if (!is_local_print_report && want_report)
                        {
                            which = "报告";
                        }
                        else
                        {
                            which = "胶片";
                        }
                        Helper.add_text(this.txtMsg,
                                        string.Format("{1}向数据服务器P1发打印{0}命令, 等待服务器P1返回结果...{1}",
                                                      which, Environment.NewLine));

                        start_p1_tcp_client();
                        connect_p1_tcp_client(_p1_server_ip, _p1_server_port);

                        //发打印命令
                        ServerPrintUserCmd spuc = new ServerPrintUserCmd();
                        spuc.sender_name  = this_name;
                        spuc.user_id      = this.lblUserID.Text.Trim();
                        spuc.printer_id   = printer_id;
                        spuc.print_dcm    = !is_local_print_dcm && want_dcm;
                        spuc.print_report = !is_local_print_report && want_report;
                        ServerPrintUserCmdAck spuc_ack = Helper.tcp_client_send_and_response(_p1_tcp_client, spuc, 60000) as ServerPrintUserCmdAck;

                        Helper.add_text(this.txtMsg,
                                        string.Format("{0}数据服务器P1返回打印结果: {1}{0}",
                                                      Environment.NewLine, (spuc_ack == null ? "失败" : "成功")));

                        if (spuc_ack == null)
                        {
                            throw new MsgBoxException("通信异常", "请确认与数据服务器P1之间的网络连接是否正常.");
                        }
                        if (spuc_ack.print_dcm)
                        {
                            Helper.add_text(this.txtMsg,
                                            string.Format("{0}打印胶片: {1}{0}",
                                                          Environment.NewLine,
                                                          (spuc_ack.print_dcm_ack == 0 ? "成功" : "失败")));
                        }
                        if (spuc_ack.print_report)
                        {
                            Helper.add_text(this.txtMsg,
                                            string.Format("{0}打印报告: {1}{0}",
                                                          Environment.NewLine,
                                                          (spuc_ack.print_report_ack == 0 ? "成功" : "失败")));
                        }

                        if (spuc_ack.print_dcm)
                        {
                            print_dcm_ok = (spuc_ack.print_dcm_ack == 0);
                        }
                        if (spuc_ack.print_report)
                        {
                            print_report_ok = (spuc_ack.print_report_ack == 0);
                        }
                    }
                }
                catch (MsgBoxException ex)
                {
                    Helper.add_text(this.txtMsg,
                                    string.Format("{0}{1}, {2}{0}",
                                                  Environment.NewLine, ex.Title, ex.Message));
                }
                catch (System.Exception ex)
                {
                    EzLogger.GlobalLogger.warning(string.Format("{0}{2}{1}{2}",
                                                                ex.Message, ex.StackTrace, Environment.NewLine));
                }
                #endregion
                if (task_dcm != null)
                {
                    task_dcm.Wait();
                    print_dcm_ok = task_dcm.Result;
                }
                if (task_report != null)
                {
                    task_report.Wait();
                    print_report_ok = task_report.Result;
                }
            }
            catch (MsgBoxException ex)
            {
                Helper.add_text(this.txtMsg,
                                string.Format("{0}{1}, {2}{0}",
                                              Environment.NewLine, ex.Title, ex.Message));
            }
            catch (System.Exception ex)
            {
                EzLogger.GlobalLogger.warning(string.Format("{0}{2}{1}{2}",
                                                            ex.Message, ex.StackTrace, Environment.NewLine));
            }
            finally
            {
                stop_p1_tcp_client();

                ui_post_print(print_dcm_ok, print_report_ok);
            }
        }
예제 #8
0
        /// <summary>
        /// Insere um usuario no banco de dados
        /// </summary>
        private void CreateUser()
        {
            try
            {
                if (CurrentGroup != null && (bool)CurrentGroup.Fields["IsAdmin"].Value)
                {
                    if (ListBox5.SelectedIndex == -1)
                    {
                        ErrorList.Add("UsuarioGrupoInvalido", "Escolha um grupo");
                    }
                    else
                    {
                        if (TextBox7.Text == "")
                        {
                            ErrorList.Add("UsuarioNomeInvalido", "Nome do Login de usuário tem que ser preenchido");
                        }

                        if (TextBox11.Text == "")
                        {
                            ErrorList.Add("UsuarioNomeInvalido", "Nome Completo do usuário tem que ser preenchido");
                        }

                        if (TextBox8.Text == "")
                        {
                            ErrorList.Add("UsuarioSenhaInvalido", "Senha do usuário tem que ser preenchido");
                        }
                        if (TextBox9.Text == "")
                        {
                            ErrorList.Add("UsuarioCsenhaInvalido", "Confirmação de senha tem que ser preenchido");
                        }
                    }
                    if (ErrorList.Count > 0)
                    {
                        return;
                    }
                    if (TextBox8.Text != TextBox9.Text)
                    {
                        ErrorList.Add("SenhaEconfirmacaoDif", "Confirmação de senha invalida");
                    }
                    if (ErrorList.Count > 0)
                    {
                        return;
                    }
                    try
                    {
                        LoginUserItem item = new LoginUserItem();
                        item.Fields["Login"].SetValue(Crypt.Encripta(TextBox7.Text.ToUpper()));
                        item.Fields["Id"].SetValue(ListBox6.SelectedValue);

                        item.Fields["Password"].SetValue(Crypt.Encripta(TextBox8.Text.ToUpper()));
                        item.Fields["Group"].SetValue(ListBox5.SelectedValue);

                        item.Fields["Obs"].SetValue(Crypt.Encripta(TextBox10.Text));
                        item.Fields["Name"].SetValue(Crypt.Encripta(TextBox11.Text));
                        if (vgMembership.CreateUser(item) == 0)
                        {
                            throw new Exception("Erro na criação do usuario");
                        }
                        FillUserListBox();
                        ListBox6.Enabled       = true;
                        ListBox5.Enabled       = true;
                        ListBox6.SelectedIndex = ListBox6.Items.Count - 1;
                        EnableUserButtons(false, false, true, true);
                    }
                    catch (Exception ex)
                    {
                        ErrorList.Add("ErroDeCriacao", ex.Message);
                    }
                }
            }
            catch
            {
            }
        }
예제 #9
0
 public void UpdateUser(LoginUserItem user)
 {
     UserProvider.DataProvider.UpdateItem(user);
 }
예제 #10
0
 public int CreateUser(LoginUserItem NewUser)
 {
     return(UserProvider.DataProvider.InsertItem(NewUser));
 }
예제 #11
0
 private void CreateDefaultUser()
 {
     CurrentItem = new LoginUserItem();
     CurrentItem.SetDefaultUser();
     DataProvider.InsertItem(CurrentItem);
 }