Exemple #1
0
 public frmUpdateContract(VcpmcContext ctx, UpdataType updataType = UpdataType.Add, ContractObject contractObjects = null)
 {
     InitializeComponent();
     this._updataType      = updataType;
     this._contractObjects = contractObjects;
     this._ctx             = ctx;
 }
Exemple #2
0
 private void LoadDatafromDB(string currentIdDsChoise)
 {
     try
     {
         Guid guid = new Guid(currentIdDsChoise);
         distributionDatas = new List <DistributionData>();
         VcpmcContext ctx = new VcpmcContext();
         var          x   = (from s in ctx.DistributionDatas
                             //TODO
                             //where s.DistibutionId == guid
                             select s).ToList();
         if (x != null)
         {
             distributionDatas = x;
             dgvListFile.Invoke(new MethodInvoker(delegate
             {
                 dgvListFile.DataSource = distributionDatas;
                 for (int i = 0; i < dgvListFile.RowCount; i++)
                 {
                     if ((bool)dgvListFile.Rows[i].Cells["StatusLoadData"].Value == true)
                     {
                         dgvListFile.Rows[i].Cells["statusLoadData"].Style.BackColor = Color.Green;
                         dgvListFile.Rows[i].Cells["statusLoadData"].Style.ForeColor = Color.White;
                     }
                     else
                     {
                         dgvListFile.Rows[i].Cells["statusLoadData"].Style.BackColor = Color.Red;
                         dgvListFile.Rows[i].Cells["statusLoadData"].Style.ForeColor = Color.White;
                     }
                     if ((bool)dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Value == true)
                     {
                         dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.BackColor = Color.Green;
                         dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.ForeColor = Color.White;
                     }
                     else
                     {
                         dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.BackColor = Color.Red;
                         dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.ForeColor = Color.White;
                     }
                 }
             }));
         }
         else
         {
             MessageBox.Show("Load data from database be error!");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #3
0
 private void frmMemberChoisePO_Load(object sender, EventArgs e)
 {
     try
     {
         VcpmcContext ctx = new VcpmcContext();
         var          x   = (from s in ctx.MemberBHs
                             orderby s.TimeCreate descending
                             select s).ToList();
         dgvListPO.DataSource = x;
     }
     catch (Exception)
     {
         MessageBox.Show("Load import work member is error");
     }
 }
Exemple #4
0
 private void frmDistributionChoisePO_Load(object sender, EventArgs e)
 {
     try
     {
         VcpmcContext ctx = new VcpmcContext();
         var          x   = (from s in ctx.DistributionDatas
                             orderby s.TimeCreate descending
                             select s).ToList();
         dgvListPO.DataSource = x;
     }
     catch (Exception)
     {
         MessageBox.Show("Load list PO is error");
     }
 }
 private void frmMasterImportChoise_Load(object sender, EventArgs e)
 {
     try
     {
         VcpmcContext ctx = new VcpmcContext();
         //var x = (from s in ctx.YoutubeFiles
         //         orderby s.TimeCreate descending
         //         select s).ToList();
         //dgvListPO.DataSource = x;
     }
     catch (Exception)
     {
         MessageBox.Show("Load import Masterlist PO be error");
     }
 }
Exemple #6
0
 private void PrintetAll(string[] idList)
 {
     try
     {
         VcpmcContext ctx = new VcpmcContext();
         for (int i = 0; i < idList.Length; i++)
         {
             //get data
             string id = idList[i];
             var    x  = (from s in ctx.DistributionDataItems
                          where s.DistributionDataId.ToString() == id
                          select s).ToList();
             //report
             var reportDatSource = new ReportDataSource("DataSet1", x);
             ReportParameter[] reportParameters = new ReportParameter[] {
                 new ReportParameter("strdate", DateTime.Now.ToString("dd")),
                 new ReportParameter("strmonth", DateTime.Now.ToString("MM")),
                 new ReportParameter("stryear", DateTime.Now.ToString("yyy")),
                 new ReportParameter("strPeopleSign", "Nguyen Van Teo"),
             };
             //
             LocalReport localReport = new LocalReport();
             string      path        = Path.GetDirectoryName(Application.ExecutablePath);
             //string fullPath = path+ @"\VCPMC_Report\form\report\template\DistributionReport.rdlc";
             string fullPath = @"E:\Solution\Source Code\VCPMC_masterListDataReport\TH_solution\Demo\VCPMC_Report\form\report\template\DistributionReport.rdlc";
             localReport.ReportPath = fullPath;
             localReport.DataSources.Clear();
             localReport.DataSources.Add(reportDatSource);
             localReport.SetParameters(reportParameters);
             PrinterHelper.PrintToPrinter(localReport, true);
             //break;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #7
0
        private void SaveDataToDB(string[] idList, Distibution distibution)
        {
            try
            {
                if (idList.Length > 0 && distibution != null)
                {
                    VcpmcContext vcpmcContext = new VcpmcContext();

                    //vcpmcContext.SaveChanges();
                    long count = 0;
                    for (int i = 0; i < idList.Length; i++)
                    {
                        foreach (var item in distributionDatas)
                        {
                            if (item.Id.ToString() == idList[i])
                            {
                                //3.save detail
                                foreach (var item2 in item.DistributionDataItems)
                                {
                                    vcpmcContext.DistributionDataItems.Add(item2);
                                    count++;
                                }
                                //2.save master2
                                //TODO
                                //item.DistibutionId = distibution.Id;
                                item.StatusSaveDataToDatabase = true;
                                vcpmcContext.DistributionDatas.Add(item);
                                break;
                            }
                        }
                        //break;
                    }
                    //
                    //1.save master
                    distibution.TotalRecord = count;
                    vcpmcContext.Distibutions.Add(distibution);

                    vcpmcContext.SaveChanges();
                    distibution = null;
                    dgvListFile.Invoke(new MethodInvoker(delegate
                    {
                        for (int i = 0; i < dgvListFile.RowCount; i++)
                        {
                            if ((bool)dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Value == true)
                            {
                                dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.BackColor = Color.Green;
                                dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.ForeColor = Color.White;
                            }
                            else
                            {
                                dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.BackColor = Color.Red;
                                dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.ForeColor = Color.White;
                            }
                        }
                    }));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void LookupCA()
        {
            try
            {
                #region pre-data
                VcpmcContext ctx = new VcpmcContext();
                //1.member detail
                var listMemberBhDetail = (from s in ctx.MemberBHDetails
                                          where s.MemberBHId == guidBhMember
                                          select s).ToList();
                if (listMemberBhDetail.Count == 0)
                {
                    pcloader.Invoke(new MethodInvoker(delegate
                    {
                        pcloader.Visible = false;
                    }));
                    MessageBox.Show("Please import Bhmedia Member");
                    return;
                }
                string[] arrStrBhDetailTmp = null;
                foreach (var item in listMemberBhDetail)
                {
                    //1.1.but danh
                    if (item.Type == "SINGLE")
                    {
                        arrStrBhDetailTmp = item.StageName.Split(',');
                        foreach (var itemD in arrStrBhDetailTmp)
                        {
                            item.ListStageName.Add(itemD.Trim());
                        }
                    }
                    //1.2. Thanh vien nhom
                    else
                    {
                        arrStrBhDetailTmp = item.SubMember.Split(',');
                        foreach (var itemD in arrStrBhDetailTmp)
                        {
                            item.ListSubMember.Add(itemD.Trim());
                        }
                    }
                }
                //2.
                var listWorkMemberDetail = (from s in ctx.ImportMapWorkMemberDetails
                                            where s.ImportMapWorkMemberId == guidWorkMember
                                            select s).ToList();
                if (listWorkMemberDetail.Count == 0)
                {
                    pcloader.Invoke(new MethodInvoker(delegate
                    {
                        pcloader.Visible = false;
                    }));
                    MessageBox.Show("Please import work-member");
                    return;
                }
                //3. danh sach loai tru
                var listExceptionWorkDetail = (from s in ctx.ExceptionWorkDetails
                                               where s.ExceptionWorkId == guidExceptWorkMember && s.Type == "EXCEPT"
                                               select s).ToList();
                string[] arrPoolName = null;
                foreach (var item in listExceptionWorkDetail)
                {
                    arrPoolName = item.PoolName.Split(';');
                    foreach (var itemD in arrPoolName)
                    {
                        if (itemD.Trim() != "")
                        {
                            item.ListPoolName.Add(itemD.Trim());
                        }
                    }
                }
                var listIncudeWorkDetail = (from s in ctx.ExceptionWorkDetails
                                            where s.ExceptionWorkId == guidExceptWorkMember && s.Type == "INCLUDE"
                                            select s).ToList();
                string[] arrPoolNameIncude = null;
                foreach (var item in listIncudeWorkDetail)
                {
                    arrPoolNameIncude = item.PoolName.Split(';');
                    foreach (var itemD in arrPoolNameIncude)
                    {
                        if (itemD.Trim() != "")
                        {
                            item.ListPoolName.Add(itemD.Trim());
                        }
                    }
                }
                #endregion

                #region map data
                //int pos = -1;
                foreach (var item in distributionDataItems)
                {
                    #region I.tim tac gia dua vao bai hat
                    item.TotalAuthor = "";
                    //ImportMapWorkMemberDetail detail = null;
                    foreach (var wm in listWorkMemberDetail)
                    {
                        //danh sach bai hat can tim = danh sach nap vao mau: dua vao ten=> lay duoc tac gia
                        if (item.WorkInNo == wm.Internal)
                        {
                            //hien lay ca ma va ten bị sai
                            //detail = wm;
                            //if (item.Title2.Trim() == wm.Title2.Trim())
                            //{
                            //    if (item.Title2 == "SAU LE BONG 2")
                            //    {
                            //        int A = 1;
                            //    }
                            //    item.TotalAuthor = wm.TotalAuthor;
                            //    item.IsMapAuthor = true;
                            //    break;
                            //}
                            //else
                            //{
                            //    int a = 1;
                            //}
                            item.TotalAuthor = wm.TotalAuthor;
                            item.IsMapAuthor = true;
                            break;
                        }
                    }
                    if (item.TotalAuthor.Length == 0)
                    {
                        item.IsMapAuthor = false;
                        continue;
                    }
                    #endregion

                    #region II.map voi danh sach bh de lay thong tin
                    //1.lay duoc tac gia
                    //lay danh sach tac gia BH nam trong danh sach
                    //#region Lay tac gia BH
                    string[] arrAyyOuthor = item.TotalAuthor.Split(',');
                    for (int i = 0; i < arrAyyOuthor.Length; i++)
                    {
                        arrAyyOuthor[i] = arrAyyOuthor[i].Trim();
                    }

                    //2.tim chi tiet tac gia trong danh sach BH, dua vao ten tac gia
                    //arrAyyOuthor: VINH SU, BHMEDIA
                    //arrAyyOuthor: CO PHUONG, TRINH CONG SON, BHMEDIA
                    //Member: VINH SU
                    MemberBHDetail memberHbDetailTmp = null;
                    foreach (var temp in arrAyyOuthor)
                    {
                        if (memberHbDetailTmp == null)//danh dau de lay tac gia dau tien
                        {
                            foreach (var tempD in listMemberBhDetail)
                            {
                                if (tempD.Type == "SINGLE")
                                {
                                    if (tempD.ListStageName.Count > 0)
                                    {
                                        if (StringHelper.CheckStringInArrayString(temp, tempD.ListStageName))
                                        {
                                            if (item.Title2 == "THUONG TIEC MOT DOI HOA")
                                            {
                                                //int a = 1;
                                            }
                                            memberHbDetailTmp = tempD;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (memberHbDetailTmp == null)
                    {
                        continue;
                    }
                    else
                    {
                        item.SubMember         = memberHbDetailTmp.SubMember;
                        item.Beneficiary       = memberHbDetailTmp.Beneficiary;
                        item.GetPart           = memberHbDetailTmp.GetPart;
                        item.IsAlwaysGet       = memberHbDetailTmp.IsAlwaysGet;
                        item.returnDate        = memberHbDetailTmp.returnDate;
                        item.Percent           = memberHbDetailTmp.Percent;
                        item.IsGiveBeneficiary = memberHbDetailTmp.IsGiveBeneficiary;
                        item.IsCreateReport    = memberHbDetailTmp.IsCreateReport;
                        item.Note = memberHbDetailTmp.Note;
                        //xac dinh map bang single
                        item.IsMapByGroup = false;
                    }
                    item.BhAuthor = memberHbDetailTmp.ListStageName[0];
                    #endregion

                    //test
                    //if (item.BhAuthor == "ANH BANG")
                    //{
                    //    int a = 1;
                    //    if(item.Title2 == "NGAP NGUNG")
                    //    {
                    //        int ii = 1;
                    //    }
                    //}

                    #region III.calc
                    if (item.IsAlwaysGet)
                    {
                        item.IsCondittionTime = true;
                        if (item.Note2.Length > 0)
                        {
                            item.Note2 += ",";
                        }
                        item.Note2 += "ALLWAYS";
                    }
                    else
                    {
                        if (item.returnDate == null)
                        {
                            item.IsCondittionTime = false;
                        }
                        else
                        {
                            //if (item.returnDate >= item.ContractTime)
                            if (item.ContractTime >= item.returnDate)
                            {
                                item.IsCondittionTime = true;
                            }
                            else
                            {
                                item.IsCondittionTime = false;
                                if (item.Note2.Length > 0)
                                {
                                    item.Note2 += ",";
                                }
                                item.Note2 += "CONTRACT TIME LESS DISTRIBUTION TIME";
                            }
                        }
                    }
                    #endregion

                    #region Bao gom
                    if (listIncudeWorkDetail.Count > 0)
                    {
                        var filter = listIncudeWorkDetail.FindAll(x => x.Member2 == item.BhAuthor).ToList();
                        if (filter != null && filter.Count > 0)
                        {
                            //tac gia chi ban trong 10 bai nay thoi
                            bool isNameTrong = false;

                            #region Xac dinh co nam trong nhung tac pham ban hay khong
                            foreach (var f in filter)
                            {
                                //NEU BAI HAT DANG XET NAM TRONG DANH SACH
                                if (item.Title2 == f.Title2)
                                {
                                    if (f.ListPoolName.Count > 0)
                                    {
                                        #region Chi bao gom linh vuc
                                        //THI XET TOI THUOC NHOM NHAC CHUONG, NHACC= CHO, MIDE FILE
                                        if (StringHelper.CheckStringContainsArrayString(item.PoolName.Trim(), f.ListPoolName))
                                        {
                                            //thanh son chi ban 10 bai
                                            isNameTrong = true;
                                            //item.IsCondittionTime = true;
                                            //if (item.Note2.Length > 0)
                                            //{
                                            //    item.Note2 += ",";
                                            //}
                                            //item.Note2 += "INCLUDE";
                                            break;
                                        }
                                        #endregion
                                    }
                                    else
                                    {
                                        //item.IsCondittionTime = true;
                                        isNameTrong = true;
                                        //if (item.Note2.Length > 0)
                                        //{
                                        //    item.Note2 += ",";
                                        //}
                                        //item.Note2 += "INCLUDE";
                                        break;
                                    }
                                }
                            }
                            #endregion

                            #region Neu khong nam trong thi luon la tac gia
                            if (!isNameTrong)
                            {
                                //khong nam trong danh sach ban, no thuoc ve tac gia
                                item.IsCondittionTime = false;
                            }
                            else
                            {
                                //int a = 1;
                            }
                            #endregion
                        }
                    }
                    #endregion

                    #region IV.ngoai tru
                    //if(item.Title2== "CAU TRE KY NIEM" && item.PoolName2== "NHAC CHUONG, NHAC CHO"
                    //    && item.IsCondittionTime ==false)
                    //{
                    //    int a = 1;
                    //}
                    if (listExceptionWorkDetail.Count > 0)
                    {
                        //LAY DANH SACH NGOAI TRU THEO TAC GIA
                        var filter = listExceptionWorkDetail.FindAll(x => x.Member2 == item.BhAuthor).ToList();
                        if (filter != null && filter.Count > 0)
                        {
                            foreach (var f in filter)
                            {
                                //NEU BAI HAT DANG XET NAM TRONG DANH SACH
                                if (item.Title2 == f.Title2)
                                {
                                    if (f.ListPoolName.Count > 0)
                                    {
                                        #region Loai tri theo linh vuc
                                        //THI XET TOI THUOC NHOM NHAC CHUONG, NHACC= CHO, MIDE FILE
                                        if (StringHelper.CheckStringContainsArrayString(item.PoolName.Trim(), f.ListPoolName))
                                        {
                                            //vinh su
                                            //ban cho maseco: 22/01/2014
                                            //ban cho hb: 01/02/2018: nen luon cua maseco
                                            //TODO: can truyen time vao de so sanh
                                            item.IsCondittionTime = true;//hien ong vinh su
                                            item.IsExcept         = true;
                                            if (item.Note2.Length > 0)
                                            {
                                                item.Note2 += ",";
                                            }
                                            item.Note2 += "EXCEPTION";
                                            break;
                                        }
                                        #endregion
                                    }
                                    else
                                    {
                                        #region Loai tru theo toan bo
                                        item.IsExcept = true;
                                        #endregion
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region Nếu là nhóm: lấy ngày theo nhóm
                    foreach (var tempD in listMemberBhDetail)
                    {
                        if (tempD.Type == "GROUP")
                        {
                            if (tempD.ListSubMember.Count > 0)
                            {
                                //neu la nhom thi pool source name phai bang group
                                //kiem tra tac gia co nam trong nhom thanh vien khong
                                string[] strSoureName = null;
                                if (item.PoolName2 == "GOOGLE")
                                {
                                    #region Nếu là google thì lấy theo quý
                                    DateTime?time = null;
                                    if (item.SourceName.Substring(0, 3) == "HCM")
                                    {
                                        //hcm: HCM20142831_GOOGLE_YOUTUBE_Q4_2019_MR
                                        //item.SourceName = "HN20142831_GOOGLE_YOUTUBE_Q324_2019_MR";
                                        //item.SourceName = "HCM20142831_GOOGLE_2019_MR";
                                        strSoureName = item.SourceName.Split('_');
                                        if (strSoureName.Length > 2)
                                        {
                                            string strYear = strSoureName[strSoureName.Length - 2];
                                            string quy     = strSoureName[strSoureName.Length - 3];
                                            if (quy.Length > 1 && quy.Length < 6 & quy.Substring(0, 1).ToUpper() == "Q")
                                            {
                                                quy = quy.Substring(1, quy.Length - 1);
                                                try
                                                {
                                                    int conver = int.Parse(quy);
                                                    time = CreateTime(strYear, quy);
                                                }
                                                catch (Exception)
                                                {
                                                    time = null;
                                                }
                                            }
                                            else
                                            {
                                                time = null;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //TODO: cho ha noi format
                                    }
                                    if (time != null)
                                    {
                                        item.ContractTime = (DateTime)time;
                                    }
                                    else
                                    {
                                        //int a = 1;
                                    }
                                    #endregion
                                }
                                if (item.PoolName2 == tempD.Member && StringHelper.CheckStringInArrayString(item.BhAuthor, tempD.ListSubMember))
                                {
                                    //nếu cần map ma ngay la không xác định thì coi như không cần map
                                    if (tempD.IsAlwaysGet == false && tempD.returnDate == null)
                                    {
                                        break;
                                    }
                                    item.SubMember   = tempD.SubMember;
                                    item.Beneficiary = tempD.Beneficiary;
                                    item.GetPart     = tempD.GetPart;
                                    item.IsAlwaysGet = tempD.IsAlwaysGet;
                                    if (item.PoolName2 != "GOOGLE")
                                    {
                                        item.returnDate = tempD.returnDate;
                                    }
                                    item.Percent           = tempD.Percent;
                                    item.IsGiveBeneficiary = tempD.IsGiveBeneficiary;
                                    item.IsCreateReport    = tempD.IsCreateReport;
                                    item.Note = tempD.Note;
                                    //chuyen sang map nhom
                                    item.IsMapByGroup = true;

                                    if (item.IsAlwaysGet)
                                    {
                                        item.IsCondittionTime = true;
                                        if (item.Note2.Length > 0)
                                        {
                                            item.Note2 += ",";
                                        }
                                        item.Note2 += "ALLWAYS";
                                    }
                                    else
                                    {
                                        if (tempD.returnDate == null)
                                        {
                                            item.IsCondittionTime = false;
                                        }
                                        else
                                        {
                                            //if (memberHbDetailTmp.returnDate >= item.ContractTime)
                                            if (item.ContractTime >= memberHbDetailTmp.returnDate)
                                            {
                                                item.IsCondittionTime = true;
                                            }
                                            else
                                            {
                                                item.IsCondittionTime = false;
                                                if (item.Note2.Length > 0)
                                                {
                                                    item.Note2 += ",";
                                                }
                                                item.Note2 += "CONTRACT TIME LESS DISTRIBUTION TIME";
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    #endregion
                }
                #endregion

                #region test danh sach khong co tac gia
                string listEmpty = "";
                foreach (var item in distributionDataItems)
                {
                    if (item.BhAuthor == "")
                    {
                        listEmpty += item.WorkInNo + ",";
                        //t a = 1;
                    }
                }
                //string sfsd = "";
                #endregion

                #region Show
                //dgvEditFileImport.Invoke(new MethodInvoker(delegate
                //{
                //    dgvEditFileImport.DataSource = distributionDataItems;
                //    for (int i = 0; i < dgvEditFileImport.Rows.Count; i++)
                //    {
                //        if ((bool)dgvEditFileImport.Rows[i].Cells["IsCondittionTime"].Value == false)
                //        {
                //            dgvEditFileImport.Rows[i].Cells["IsCondittionTime"].Style.BackColor = Color.Red;
                //            dgvEditFileImport.Rows[i].Cells["IsCondittionTime"].Style.ForeColor = Color.White;
                //        }

                //        //if ((bool)dgvEditFileImport.Rows[i].Cells["IsExeptWork"].Value == true)
                //        //{
                //        //    dgvEditFileImport.Rows[i].Cells["IsExeptWork"].Style.BackColor = Color.Red;
                //        //    dgvEditFileImport.Rows[i].Cells["IsExeptWork"].Style.ForeColor = Color.White;
                //        //}
                //        if (dgvEditFileImport.Rows[i].Cells["Beneficiary"].Value.ToString() == string.Empty)
                //        {
                //            dgvEditFileImport.Rows[i].Cells["Beneficiary"].Style.BackColor = Color.Red;
                //            dgvEditFileImport.Rows[i].Cells["Beneficiary"].Style.ForeColor = Color.White;
                //        }
                //        //if ((bool)dgvEditFileImport.Rows[i].Cells["IsGoogle"].Value == true)
                //        //{
                //        //    dgvEditFileImport.Rows[i].Cells["IsGoogle"].Style.BackColor = Color.Red;
                //        //    dgvEditFileImport.Rows[i].Cells["IsGoogle"].Style.ForeColor = Color.White;
                //        //}
                //    }
                //}));
                statusTripMain.Invoke(new MethodInvoker(delegate
                {
                    tssLblInfo.Text = "Lookup CA is successfull";
                }));
                #endregion
            }
            catch (Exception ex)
            {
                pcloader.Invoke(new MethodInvoker(delegate
                {
                    pcloader.Visible = false;
                }));
                MessageBox.Show(ex.ToString());
            }
        }