public frmPreclaimUpdate(PreclaimController preclaimController, UpdataType view, PreclaimViewModel currenObject)
 {
     InitializeComponent();
     this._preclaimController = preclaimController;
     this._updataType         = view;
     this.currenObject        = currenObject;
 }
Beispiel #2
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 PreclaimViewModel();
         frmPreclaimUpdate frm = new frmPreclaimUpdate(controller, UpdataType.Add, CurrenObject);
         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 backgroundWorker
             Operation        = OperationType.GetDataFromServer;
             pcloader.Visible = true;
             pcloader.Dock    = DockStyle.Fill;
             backgroundWorker1.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());
     }
 }
Beispiel #3
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 (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).FirstOrDefault();
             if (CurrenObject == null)
             {
                 MessageBox.Show("Eror: recode is null");
                 return;
             }
             frmPreclaimUpdate frm = new frmPreclaimUpdate(controller, UpdataType.View, CurrenObject);
             frm.ShowDialog();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
        private async void SaveDataToDatabase()
        {
            try
            {
                PeclaimChangeListRequest request = new PeclaimChangeListRequest();
                int      countSend       = 0;
                int      countSended     = 0;
                int      countrun        = 0;
                int      totalrun        = 0;
                int      totalInserted   = 0;
                int      totalUpdateSucc = 0;
                DateTime startTime       = DateTime.Now;
                dataImport1.Clear();
                //save

                if (totalPageIm % Core.countPerSave == 0)
                {
                    countSend = dataImport.Count / Core.countPerSave;
                }
                else
                {
                    countSend = dataImport.Count / Core.countPerSave + 1;
                }

                foreach (var item in dataImport)
                {
                    //if(item.MONTH != 8)
                    //{
                    //    int a = 1;
                    //}
                    countrun++;
                    totalrun++;
                    #region create list
                    PreclaimCreateRequest pre = new PreclaimCreateRequest();
                    pre.Asset_ID       = item.Asset_ID;
                    pre.ISRC           = item.ISRC;
                    pre.Comp_Asset_ID  = item.Comp_Asset_ID;
                    pre.C_Title        = item.C_Title;
                    pre.C_ISWC         = item.C_ISWC;
                    pre.C_Workcode     = item.C_Workcode;
                    pre.C_Writers      = item.C_Writers;
                    pre.Combined_Claim = item.Combined_Claim;
                    pre.Mechanical     = item.Mechanical;
                    pre.Performance    = item.Performance;
                    //pre.MONTH = item.MONTH;
                    pre.DtCREATED_AT = item.DtCREATED_AT;
                    pre.DtUPDATED_AT = item.DtUPDATED_AT;
                    //pre.Year = item.Year;
                    request.Items.Add(pre);
                    #endregion
                    if (countrun == Core.countPerSave || totalrun == dataImport.Count)
                    {
                        //send
                        request.Total = countrun;
                        var changeData = await _preclaimController.ChangeList(request);

                        #region get info from reponse
                        if (changeData != null && changeData.Items != null)
                        {
                            //insert
                            totalInserted += changeData.Items.Where
                                             (
                                p => p.Command == Utilities.Common.CommandType.Add &&
                                p.Status == Utilities.Common.UpdateStatus.Successfull
                                             ).Count();
                            //update
                            totalUpdateSucc += changeData.Items.Where
                                               (
                                p => p.Command == Utilities.Common.CommandType.Update &&
                                p.Status == Utilities.Common.UpdateStatus.Successfull
                                               ).Count();
                            List <UpdateStatusViewModel> uvmL = changeData.Items.Where
                                                                (
                                p => p.Command == Utilities.Common.CommandType.Update &&
                                p.Status == Utilities.Common.UpdateStatus.Failure   //test
                                                                ).ToList();
                            foreach (var uvm in uvmL)
                            {
                                PreclaimViewModel x = dataImport.Where(p => p.Asset_ID == uvm.Asset_id).FirstOrDefault();
                                if (x != null)
                                {
                                    dataImport1.Add(x);
                                }
                            }
                            dataImport1 = dataImport1.OrderBy(p => p.SerialNo).ToList();
                        }
                        #endregion
                        //clear
                        request.Items.Clear();
                        countrun = 0;
                        //cap nhat phan tram
                        countSended++;
                        mainStatus.Invoke(new MethodInvoker(delegate
                        {
                            float values                  = (float)countSended / (float)countSend * 100;
                            progressBarImport.Value       = (int)values;
                            progressBarImport.ToolTipText = progressBarImport.Value.ToString();
                        }));
                    }
                }
                //view
                int totalFailure = 0;
                if (dataImport1 != null && dataImport1.Count > 0)
                {
                    totalFailure = dataImport1.Count;
                    if (totalFailure % limitIm1 == 0)
                    {
                        totalPageIm1 = totalFailure / limitIm1;
                    }
                    else
                    {
                        totalPageIm1 = totalFailure / limitIm1 + 1;
                    }
                    lbTotalPage1.Invoke(new MethodInvoker(delegate
                    {
                        lbTotalPage1.Text = totalPageIm1.ToString();
                    }));
                    GotoPage1(currentPageIm1, totalPageIm1);
                    mainStatus.Invoke(new MethodInvoker(delegate
                    {
                        lbInfo.Text = $"Total records saveing be failure: {totalFailure}";
                    }));
                }
                else
                {
                    dataImport1        = new List <PreclaimViewModel>();
                    currentDataImView1 = new List <PreclaimViewModel>();
                    dgvImportFailure.Invoke(new MethodInvoker(delegate
                    {
                        dgvImportFailure.DataSource = currentDataImView1;
                    }));
                    mainStatus.Invoke(new MethodInvoker(delegate
                    {
                        lbInfo.Text = "Saving is successfull!";
                    }));
                }
                mainStatus.Invoke(new MethodInvoker(delegate
                {
                    progressBarImport.Value       = 100;
                    progressBarImport.ToolTipText = progressBarImport.Value.ToString();
                }));
                DateTime endTime = DateTime.Now;
                lbInfoImport1.Invoke(new MethodInvoker(delegate
                {
                    lbInfoImport1.Text  = $"Time load(second(s)): {(endTime - startTime).TotalSeconds.ToString("##0.##")}, ";
                    lbInfoImport1.Text += $"total add new(s): {totalInserted}, total Update(s): {totalUpdateSucc}, ";
                    lbInfoImport1.Text += $"total Failure: {totalFailure}";
                }));
            }
            catch (Exception)
            {
                mainStatus.Invoke(new MethodInvoker(delegate
                {
                    lbInfo.Text = "send request to server be error";
                }));
            }
        }
Beispiel #5
0
        private async void btnDelete_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    = "";
                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;
                }
                var confirmResult = MessageBox.Show("Are you sure to delete this record?",
                                                    "Confirm Delete!!",
                                                    MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    var deleteStatus = await controller.Delete(CurrenObject.Id);

                    if (deleteStatus != null && deleteStatus.Status == Utilities.Common.UpdateStatus.Successfull)
                    {
                        lbOperation.Text = $"Deleted record: {deleteStatus.Message}, total Deleted: {deleteStatus.TotalEffect}";
                        #region set backgroundWorker
                        Operation        = OperationType.GetDataFromServer;
                        pcloader.Visible = true;
                        pcloader.Dock    = DockStyle.Fill;
                        backgroundWorker1.RunWorkerAsync();
                        #endregion
                    }
                    else
                    {
                        if (deleteStatus != null)
                        {
                            lbOperation.Text = $"Deleted Item: {deleteStatus.Message}";
                        }
                        else
                        {
                            lbOperation.Text = $"Deleted Item is failure";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.ToString());
            }
        }
Beispiel #6
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;
         }
         frmPreclaimUpdate frm = new frmPreclaimUpdate(controller, UpdataType.Edit, CurrenObject);
         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 backgroundWorker
             Operation        = OperationType.GetDataFromServer;
             pcloader.Visible = true;
             pcloader.Dock    = DockStyle.Fill;
             backgroundWorker1.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());
     }
 }
        /// <summary>
        /// Nạp file json preclaim
        /// </summary>
        /// <param name="path"></param>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public static List <PreclaimViewModel> JsonToPreclaim(string path)
        {
            string        line;
            List <string> subJsonList = new List <string>();
            StreamReader  r           = new StreamReader(path);
            bool          isFirst     = false;
            string        subJson     = "";

            while ((line = r.ReadLine()) != null)
            {
                subJson += line;
                if (line.Trim() == "{")
                {
                    isFirst = true;
                }
                else if (line.Trim() == "}")
                {
                    if (isFirst)
                    {
                        subJsonList.Add(subJson);
                    }
                    isFirst = false;
                    subJson = "";
                }
            }
            List <PreclaimViewModel> objects = new List <PreclaimViewModel>();
            BsonDocument             doctem  = null;
            PreclaimJson             preJson = null;
            PreclaimViewModel        preVM   = null;
            int serial = 1;

            for (int i = 0; i < subJsonList.Count; i++)
            {
                doctem  = BsonSerializer.Deserialize <BsonDocument>(subJsonList[i]);
                preJson = BsonSerializer.Deserialize <PreclaimJson>(doctem);
                preVM   = new PreclaimViewModel
                {
                    SerialNo       = serial,
                    Asset_ID       = preJson.Asset_ID,
                    ISRC           = preJson.ISRC == null ? string.Empty: VnHelper.ConvertToUnSign(ConvertAllToUnicode.ConvertFromComposite(preJson.ISRC.ToUpper())),
                    Comp_Asset_ID  = preJson.Comp_Asset_ID,
                    C_Title        = preJson.C_Title == null ? string.Empty : VnHelper.ConvertToUnSign(ConvertAllToUnicode.ConvertFromComposite(preJson.C_Title.ToUpper())),
                    C_ISWC         = preJson.C_ISWC == null ? string.Empty : VnHelper.ConvertToUnSign(ConvertAllToUnicode.ConvertFromComposite(preJson.C_ISWC.ToUpper())),
                    C_Workcode     = preJson.C_Workcode == null ? string.Empty : VnHelper.ConvertToUnSign(ConvertAllToUnicode.ConvertFromComposite(preJson.C_Workcode.ToUpper())),
                    C_Writers      = preJson.C_Writers == null ? string.Empty : VnHelper.ConvertToUnSign(ConvertAllToUnicode.ConvertFromComposite(preJson.C_Writers.ToUpper())),
                    Combined_Claim = preJson.Combined_Claim == null ? "0": VnHelper.ConvertToUnSign(preJson.Combined_Claim),
                    Mechanical     = preJson.Mechanical == null ? "0" : VnHelper.ConvertToUnSign(preJson.Mechanical),
                    Performance    = preJson.Performance == null ? "0" : VnHelper.ConvertToUnSign(preJson.Performance),
                    //MONTH = month,// preJson.MONTH,
                    //Year = year
                };
                //if (preJson.CREATED_AT != null)
                //{
                preVM.DtCREATED_AT = TimeTicks.ConvertTicksMongoToC(preJson.CREATED_AT);
                //}
                if (preJson.UPDATED_AT != null)
                {
                    preVM.DtUPDATED_AT = TimeTicks.ConvertTicksMongoToC((long)preJson.UPDATED_AT);
                }
                objects.Add(preVM);
                serial++;
            }
            return(objects);
        }
        private void LoadFrom()
        {
            if (_updataType == UpdataType.Edit || _updataType == UpdataType.View)
            {
                if (_updataType == UpdataType.Edit)
                {
                    this.Text = "Update Preclaim";
                }
                else
                {
                    this.Text = "View Preclaim";
                }
                if (currenObject == null)
                {
                    return;
                }
                #region Common
                txtAsset_ID.Text      = currenObject.Asset_ID.ToString();
                txtISRC.Text          = currenObject.ISRC;
                txtComp_Asset_ID.Text = currenObject.Comp_Asset_ID;
                txtC_Title.Text       = currenObject.C_Title;
                txtC_ISWC.Text        = currenObject.C_ISWC;
                txtC_Workcode.Text    = currenObject.C_Workcode;
                txtC_Writers.Text     = currenObject.C_Writers;
                #endregion

                #region Contract
                numCombined_Claim.Text = currenObject.Combined_Claim;
                numMechanical.Text     = currenObject.Mechanical;
                numPerformance.Text    = currenObject.Performance;
                //numMONTH.Text = currenObject.MONTH.ToString();
                //numYear.Text = currenObject.Year.ToString();
                if (currenObject.DtCREATED_AT != null)
                {
                    if (currenObject.DtCREATED_AT < dtCreate_at.MinDate)
                    {
                        currenObject.DtCREATED_AT = dtCreate_at.MinDate;
                    }
                }
                else
                {
                    currenObject.DtCREATED_AT = DateTime.Now;
                }
                dtCreate_at.Value = currenObject.DtCREATED_AT;
                if (currenObject.DtUPDATED_AT != null)
                {
                    if (currenObject.DtUPDATED_AT < dtCreate_at.MinDate)
                    {
                        currenObject.DtUPDATED_AT = dtCreate_at.MinDate;
                    }
                    dtUpdate_at.Value = (DateTime)currenObject.DtUPDATED_AT;
                }
                else
                {
                    if (_updataType == UpdataType.Edit)
                    {
                        dtUpdate_at.Visible = true;
                        lbUpdateAt.Text     = "Update at:";
                        dtUpdate_at.Value   = DateTime.Now;
                    }
                    else
                    {
                        dtUpdate_at.Visible = false;
                        lbUpdateAt.Text     = "Update at: null";
                    }
                }
                #endregion

                #region enable
                dtCreate_at.Enabled = false;
                if (_updataType == UpdataType.View)
                {
                    #region Common
                    txtAsset_ID.ReadOnly       = true;
                    txtISRC.ReadOnly           = true;
                    txtComp_Asset_ID.ReadOnly  = true;
                    txtC_Title.ReadOnly        = true;
                    txtC_ISWC.ReadOnly         = true;
                    txtC_Workcode.ReadOnly     = true;
                    txtC_Writers.ReadOnly      = true;
                    numCombined_Claim.ReadOnly = true;
                    numMechanical.ReadOnly     = true;
                    numPerformance.ReadOnly    = true;
                    //numMONTH.ReadOnly = true;
                    //numYear.ReadOnly = true;
                    btnOk.Enabled = false;
                    #endregion
                }
                else
                {
                    txtAsset_ID.ReadOnly = true;
                    //numMONTH.Enabled = false;
                    //numYear.Enabled = false;
                    dtUpdate_at.Enabled = false;
                }
                #endregion
            }
            else if (_updataType == UpdataType.Add)
            {
                this.Text           = "Add Preclaim";
                currenObject        = new PreclaimViewModel();
                dtUpdate_at.Visible = false;
                lbUpdateAt.Visible  = false;
                dtCreate_at.Value   = DateTime.Now;
                //numMONTH.Value = DateTime.Now.Month;
                //numYear.Value = DateTime.Now.Year;
            }
        }