Ejemplo n.º 1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (isRequest)
         {
             statusMain.Invoke(new MethodInvoker(delegate
             {
                 lbOperation.Text = "Waiting reponse...";
             }));
             return;
         }
         if (isFilter)
         {
             statusMain.Invoke(new MethodInvoker(delegate
             {
                 lbOperation.Text = "Waiting filter...";
             }));
             return;
         }
         CurrenObject = new UserViewModel();
         frmUserUpdate frm = new frmUserUpdate(controller, UpdataType.Add, CurrenObject, RoleList);
         frm.ShowDialog();
         if (frm.ObjectReturn != null && frm.ObjectReturn.Status == Utilities.Common.UpdateStatus.Successfull)
         {
             lbOperation.Text = $"Added Item: {frm.ObjectReturn.Message}, total Added: {frm.ObjectReturn.TotalEffect}";
             #region set background
             Operation        = OperationType.GetDataFromServer;
             pcloader.Visible = true;
             pcloader.Dock    = DockStyle.Fill;
             backgroundWorker.RunWorkerAsync();
             #endregion
         }
         else
         {
             if (frm.ObjectReturn != null)
             {
                 lbOperation.Text = $"Added Item: {frm.ObjectReturn.Message}";
             }
             else
             {
                 lbOperation.Text = $"Added Item is failure";
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: " + ex.ToString());
     }
 }
Ejemplo n.º 2
0
 private void dgvMain_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     try
     {
         if (isRequest)
         {
             statusMain.Invoke(new MethodInvoker(delegate
             {
                 lbOperation.Text = "Waiting reponse...";
             }));
             return;
         }
         if (isFilter)
         {
             statusMain.Invoke(new MethodInvoker(delegate
             {
                 lbOperation.Text = "Waiting filter...";
             }));
             return;
         }
         if (dgvMain.Rows.Count == 0)
         {
             return;
         }
         if (dgvMain.Rows.Count == 0)
         {
             return;
         }
         if (data == null || data.IsSuccessed == false || data.ResultObj == null || data.ResultObj.Items.Count == 0)
         {
             return;
         }
         if (dgvMain.Rows.Count > 0)
         {
             string id = (string)dgvMain.CurrentRow.Cells["Id"].Value;
             CurrenObject = data.ResultObj.Items.Where(s => s.Id == id).First();
             if (CurrenObject == null)
             {
                 MessageBox.Show("Eror: recode is null");
                 return;
             }
             frmUserUpdate frm = new frmUserUpdate(controller, UpdataType.View, CurrenObject, RoleList);
             frm.ShowDialog();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 3
0
 private void btnEdit_Click(object sender, EventArgs e)
 {
     try
     {
         if (isRequest)
         {
             statusMain.Invoke(new MethodInvoker(delegate
             {
                 lbOperation.Text = "Waiting reponse...";
             }));
             return;
         }
         if (isFilter)
         {
             statusMain.Invoke(new MethodInvoker(delegate
             {
                 lbOperation.Text = "Waiting filter...";
             }));
             return;
         }
         if (data == null || data.IsSuccessed == false || data.ResultObj == null || data.ResultObj.Items.Count == 0)
         {
             return;
         }
         string id    = string.Empty;
         int    count = 0;
         for (int i = 0; i < dgvMain.Rows.Count; i++)
         {
             if (dgvMain.Rows[i].Cells[0].Value != null && (bool)dgvMain.Rows[i].Cells[0].Value == true)
             {
                 count++;
                 id = (string)dgvMain.Rows[i].Cells["Id"].Value;
                 if (count > 1)
                 {
                     MessageBox.Show("Please choise only one record!");
                     return;
                 }
             }
         }
         if (id == string.Empty)
         {
             MessageBox.Show("Please must choise one record!");
             return;
         }
         CurrenObject = data.ResultObj.Items.Where(s => s.Id == id).First();
         if (CurrenObject == null)
         {
             MessageBox.Show("Eror: recode is null");
             return;
         }
         frmUserUpdate frm = new frmUserUpdate(controller, UpdataType.Edit, CurrenObject, RoleList);
         frm.ShowDialog();
         if (frm.ObjectReturn != null && frm.ObjectReturn.Status == Utilities.Common.UpdateStatus.Successfull)
         {
             lbOperation.Text = $"Edited Item: {frm.ObjectReturn.Message}, total Edited: {frm.ObjectReturn.TotalEffect}";
             #region set backgroundMonopolyer
             Operation        = OperationType.GetDataFromServer;
             pcloader.Visible = true;
             pcloader.Dock    = DockStyle.Fill;
             backgroundWorker.RunWorkerAsync();
             #endregion
         }
         else
         {
             if (frm.ObjectReturn != null)
             {
                 lbOperation.Text = $"Edited Item: {frm.ObjectReturn.Message}";
             }
             else
             {
                 lbOperation.Text = $"Edited Item is failure";
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: " + ex.ToString());
     }
 }