Example #1
0
        void InsertLink()
        {
            DataTable dtItem = LibQLSX.Select("select * from C_QuotationDetail_SX where C_QuotationID = " + C_QuotationID);

            foreach (DataRow item in dtItem.Rows)
            {
                int groupID = TextUtils.ToInt(item["C_ProductGroupID"]);
                int id      = TextUtils.ToInt(item["ID"]);

                //if (groupID == 0)
                //{
                //    C_QuotationDetail_SXModel model = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(id);
                //    C_CostQuotationItemLinkBO.Instance.DeleteByAttribute("C_QuotationDetail_SXID", id);
                //    model.TotalNC = 0;
                //    C_QuotationDetail_SXBO.Instance.Update(model);
                //}
                //else
                if (groupID > 0)
                {
                    string sql = "insert into [C_CostQuotationItemLinkNew] ([C_CostID],[C_QuotationDetail_SXID],[Price],[PersonNumber],[NumberDay],[TotalR],[IsDirect],[CostNCType])"
                                 + " select ID ," + id + " as [C_QuotationDetail_SXID], 0 as b, 0 as c, 0 as d, 0 as e, 1 as f, 'C' as g"
                                 + " from [C_Cost] m where m.IsDirectCost = 1 and ((select COUNT(ID) from [C_CostQuotationItemLinkNew] where [C_CostID] = m.ID and  [C_QuotationDetail_SXID] = " + id + ") = 0)";
                    LibQLSX.ExcuteSQL(sql);
                }
            }
        }
Example #2
0
        private void btnCancelChiThi_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc muốn hủy chỉ thị cho module không?",
                                TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            int count = 0;

            foreach (int i in grvData.GetSelectedRows())
            {
                string projectModuleId = TextUtils.ToString(grvData.GetRowCellValue(i, colProjectModuleId));
                string updateSql       = "update [ProjectModule] set [ProjectDirectionID] = NULL Where [ProjectModuleId] = '" + projectModuleId + "'";
                LibQLSX.ExcuteSQL(updateSql);

                string deleteSql = "delete ProjectDirectionDetail where ProjectModuleId = '" + projectModuleId + "'";
                LibQLSX.ExcuteSQL(deleteSql);

                count++;
            }

            if (count > 0)
            {
                MessageBox.Show("Hủy chỉ thị cho module thành công.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                loadGrid();
            }
        }
        private void hủyĐangSảnXuấtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string projectId = TextUtils.ToString(grvData.GetFocusedRowCellValue(colID));
            string sql       = "Update Project set IsAssembly = 0 where ProjectId = '" + projectId + "'";

            LibQLSX.ExcuteSQL(sql);
            btnReloadData_Click(null, null);
        }
Example #4
0
        void resetAll()
        {
            grvLink.FocusedRowHandle = -1;
            decimal totalNC = 0;
            string  sql     = "update C_QuotationDetail set TotalNC = 0 where C_QuotationID = " + C_QuotationID;

            LibQLSX.ExcuteSQL(sql);
            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang xử lý..."))
            {
                for (int i = 0; i < grvLink.RowCount; i++)
                {
                    int id = TextUtils.ToInt(grvLink.GetRowCellValue(i, colID));
                    if (id == 0)
                    {
                        return;
                    }

                    int costID            = TextUtils.ToInt(grvLink.GetRowCellValue(i, colC_CostID));
                    int quotationDetailID = TextUtils.ToInt(grvLink.GetRowCellValue(i, colC_QuotationDetailID));
                    C_QuotationDetailModel quotationDetail = (C_QuotationDetailModel)C_QuotationDetailBO.Instance.FindByPK(quotationDetailID);
                    C_CostModel            cost            = (C_CostModel)C_CostBO.Instance.FindByPK(costID);

                    C_CostProductGroupLinkModel group = (C_CostProductGroupLinkModel)C_CostProductGroupLinkBO.Instance.FindByExpression(new Expression("C_CostID", cost.ID)
                                                                                                                                        .And(new Expression("C_ProductGroupID", quotationDetail.C_ProductGroupID)))[0];

                    decimal pricePerDay = TextUtils.ToDecimal(grvLink.GetRowCellValue(i, colPricePerDay));
                    decimal qty         = TextUtils.ToDecimal(grvLink.GetRowCellValue(i, colQty));

                    C_CostQuotationItemLinkModel link = (C_CostQuotationItemLinkModel)C_CostQuotationItemLinkBO.Instance.FindByPK(id);
                    link.PersonNumber = group.PersonNumber;// TextUtils.ToDecimal(drs[0]["PersonNumber"]);
                    if (group.IsFix == 1)
                    {
                        link.NumberDay = group.NumberDay;// TextUtils.ToDecimal(drs[0]["NumberDay"]);
                    }
                    else
                    {
                        link.NumberDay = group.VtuPercent * quotationDetail.PriceVT / cost.Price;
                    }
                    link.TotalR = link.NumberDay * link.PersonNumber;
                    if (cost.ID == 61)//phòng thiết kế
                    {
                        link.TotalR *= (1 + 0.3M * (quotationDetail.Qty - 1)) / quotationDetail.Qty;
                    }
                    link.Price = link.TotalR * cost.Price;
                    C_CostQuotationItemLinkBO.Instance.Update(link);

                    quotationDetail.TotalNC += link.Price;
                    C_QuotationDetailBO.Instance.Update(quotationDetail);
                }
                IsSaved = true;
            }
            MessageBox.Show("Reset thành công.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #5
0
        private void btnDel_Click(object sender, EventArgs e)
        {
            try
            {
                if (grvData.DataSource == null)
                {
                    return;
                }
                int    id   = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colID));
                string code = grvData.GetFocusedRowCellValue(colCode).ToString();
                if (id == 0)
                {
                    return;
                }

                //if (C_CostProductGroupLinkBO.Instance.CheckExist("C_CostID", id))
                //{
                //    MessageBox.Show("Chi phí này đang liên kết với nghành hàng nên không thể xóa được.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //    return;
                //}

                if (C_CostQuotationItemLinkBO.Instance.CheckExist("C_CostID", id))
                {
                    MessageBox.Show("Chi phí này đang liên kết với thiết bị nên không thể xóa được.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                if (MessageBox.Show("Bạn có chắc muốn xóa chi phí [" + grvData.GetFocusedRowCellValue(colName).ToString() + "] không?",
                                    TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }

                //ModulesBO.Instance.Delete(id);
                C_CostModel model = (C_CostModel)C_CostBO.Instance.FindByPK(id);
                model.IsDeleted = true;
                C_CostBO.Instance.Update(model);

                LibQLSX.ExcuteSQL("delete C_CostProductGroupLink where C_CostID = " + id);
                LibQLSX.ExcuteSQL("delete C_CostQuotationLink where C_CostID = " + id);

                LoadInfoSearch();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #6
0
        private void btnDeadlineSXLR_Click(object sender, EventArgs e)
        {
            string projectCode = TextUtils.ToString(grvProject.GetFocusedRowCellValue(colProjectCode));

            if (dtpSXLRDeadline.EditValue != null && projectCode != "")
            {
                DateTime date = TextUtils.ToDate3(dtpSXLRDeadline.EditValue);
                LibQLSX.ExcuteSQL("update Project set AssemblyDeadline = '" + date.Year + "-" + date.Month + "-" + date.Day
                                  + "' where [ProjectCode] = '" + projectCode + "'");
                string id = TextUtils.ToString(cboProject.EditValue);
                loadProject();
                cboProject.EditValue = id;

                MessageBox.Show("Thay đổi deadline SXLR thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #7
0
        private void btnSetStatus_Click(object sender, EventArgs e)
        {
            int projectStatusID = TextUtils.ToInt(cboStatus.SelectedValue);

            if (projectStatusID == 0)
            {
                return;
            }

            foreach (int i in grvData.GetSelectedRows())
            {
                string projectId = TextUtils.ToString(grvData.GetRowCellValue(i, colID));
                string sql       = "Update Project set ProjectStatusID = " + projectStatusID + " where ProjectId = '" + projectId + "'";
                LibQLSX.ExcuteSQL(sql);
            }

            btnReloadData_Click(null, null);
        }
Example #8
0
        private void phụcHồiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int id = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colID));

            if (id == 0)
            {
                return;
            }
            string       name   = TextUtils.ToString(grvData.GetFocusedRowCellValue(colFullName));
            DialogResult result = MessageBox.Show("Bạn có thực sự muốn chuyển nhân viên [" + name + "] sang trạng thái đi làm?", TextUtils.Caption,
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                UsersModel model = (UsersModel)UsersBO.Instance.FindByPK(id);
                model.Status = 0;//ngừng hoạt động
                UsersBO.Instance.Update(model);

                LibQLSX.ExcuteSQL("update Users set IsStop = 0 where Account = '" + model.LoginName + "'");
                loadGrid();
            }
        }
Example #9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();
            try
            {
                if (!ValidateForm())
                {
                    return;
                }

                Model.BankAccount = txtBankAccount.Text.Trim();
                Model.BHXH        = txtBHXH.Text.Trim();
                Model.BHYT        = txtBHYT.Text.Trim();
                try
                {
                    Model.BirthOfDate = TextUtils.ToDate3(dtpBirthOfDate.EditValue);
                }
                catch
                {
                    Model.BirthOfDate = DateTime.Now;
                }

                Model.CMTND          = txtCMTND.Text.Trim();
                Model.Code           = txtCode.Text.Trim();
                Model.DepartmentID   = TextUtils.ToInt(cboDepartment.SelectedValue);
                Model.Email          = txtEmail.Text.Trim();
                Model.EmailCom       = txtEmailCom.Text.Trim();
                Model.FullName       = txtFullName.Text;
                Model.HandPhone      = txtTelephone.Text;
                Model.HomeAddress    = txtHomeAddress.Text;
                Model.JobDescription = txtJobDescription.Text.Trim();
                Model.MST            = txtMST.Text.Trim();
                Model.Position       = txtPosition.Text;
                Model.Qualifications = txtQualifications.Text.Trim();
                Model.Sex            = cboSex.SelectedIndex;
                Model.UserGroupID    = TextUtils.ToInt(lookUpEdit1.EditValue);
                Model.UserGroupSXID  = TextUtils.ToInt(cboGroup.EditValue);

                try
                {
                    Model.StartWorking = TextUtils.ToDate3(dtpStartWorking.EditValue);
                }
                catch
                {
                    Model.StartWorking = DateTime.Now;
                }

                Model.ImagePath = pictureBox1.ImageLocation;
                Model.Status    = cboStatus.SelectedIndex;

                if (chkHasUser.Checked)
                {
                    Model.LoginName    = txtLoginName.Text.Trim();
                    Model.PasswordHash = MD5.EncryptPassword(txtPasswordHash.Text.Trim());
                }
                else
                {
                    Model.LoginName    = "";
                    Model.PasswordHash = "";
                }

                Model.UpdatedDate = Model.CreatedDate;
                Model.UpdatedBy   = Global.AppUserName;

                if (Model.ID == 0)
                {
                    Model.CreatedDate = TextUtils.GetSystemDate();
                    Model.CreatedBy   = Global.AppUserName;

                    Model.ID = (int)pt.Insert(Model);
                }
                else
                {
                    pt.Update(Model);
                }
                pt.CommitTransaction();

                //Update mã nhân viên cho bên QLSX
                if (Model.LoginName != "")
                {
                    string pId = TextUtils.ToString(TextUtils.ExcuteScalar("select top 1 PId from [Department] with(nolock) where ID = " + TextUtils.ToInt(cboDepartment.SelectedValue)));
                    LibQLSX.ExcuteSQL("update Users set Code = '" + Model.Code + "', UserGroup1ID = " + Model.UserGroupSXID + ", [DepartmentId1]= '" + pId + "' where Account = '" + Model.LoginName + "'");
                }

                MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (this.LoadDataChange != null)
                {
                    this.LoadDataChange(null, null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                pt.CloseConnection();
            }
        }
Example #10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            DataTable dtUserKCS = LibQLSX.Select("select top 1 * from Users where Account = '" + Global.AppUserName + "'");

            if (dtUserKCS.Rows.Count == 0)
            {
                MessageBox.Show("Tài khoản đăng nhập không có trên QLSX", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //pt.CloseConnection();
                return;
            }

            decimal OK = 0;
            decimal NG = 0;

            //ProcessTransaction pt = new ProcessTransaction();
            //pt.OpenConnection();
            //pt.BeginTransaction();

            if (!ValidateForm())
            {
                //pt.CloseConnection();
                return;
            }
            grvData.FocusedRowHandle = -1;

            bool isDiffError = TextUtils.ToInt(ProductPartsImport.CountError) < TextUtils.ToInt(txtCountError.EditValue);

            if (!isDiffError)
            {
                //Xóa hết những nhật ký lỗi của vật tư khi KCS, trước khi lưu
                //CriteriaImportBO.Instance.DeleteByAttribute("ProductPartsImportId", ProductPartsImport.ProductPartsImportId);

                LibQLSX.ExcuteSQL(string.Format("delete CriteriaImport where ProductPartsImportId = '{0}' and CountError = {1}"
                                                , ProductPartsImport.ProductPartsImportId, TextUtils.ToInt(ProductPartsImport.CountError)));
            }

            try
            {
                for (int i = 0; i < grvData.RowCount; i++)
                {
                    string criteriaImportId = TextUtils.ToString(grvData.GetRowCellValue(i, colCriteriaImportId));

                    CriteriaImportModel model = new CriteriaImportModel();
                    //if (criteriaImportId != "")
                    //{
                    //    ArrayList arr = CriteriaImportBO.Instance.FindByAttribute("CriteriaImportId", criteriaImportId);
                    //    if (arr.Count > 0)
                    //    {
                    //        model = (CriteriaImportModel)arr[0];
                    //    }
                    //    else
                    //    {
                    //        criteriaImportId = "";
                    //    }
                    //}

                    model.CriteriaName         = "Đúng thông số, kích thước kỹ thuật.";
                    model.ValueRequest         = "Vật tư, thiết bị đảm bảo chất lượng.";
                    model.CriteriaIndex        = TextUtils.ToInt(grvData.GetRowCellValue(i, colSTT));
                    model.IsHalf               = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colIsHalf));
                    model.ProductPartsImportId = ProductPartsImport.ProductPartsImportId;

                    bool status = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colStatus));
                    model.Status = status ? 1 : 0;

                    model.ValueResult = TextUtils.ToString(grvData.GetRowCellValue(i, colValueResult));
                    model.CountError  = TextUtils.ToInt(txtCountError.EditValue);

                    //if (criteriaImportId != "" && !isDiffError)
                    //{
                    //    CriteriaImportBO.Instance.UpdateQLSX(model);
                    //}
                    //else
                    //{
                    DataTable dt = LibQLSX.Select("SELECT top 1 CriteriaImportId FROM CriteriaImport order by CriteriaImportId desc");
                    if (dt.Rows.Count > 0)
                    {
                        criteriaImportId = TextUtils.ToString(dt.Rows[0]["CriteriaImportId"]);
                        string number = criteriaImportId.Substring(2, 8);
                        criteriaImportId = "CI" + string.Format("{0:00000000}", TextUtils.ToInt(number) + 1);
                    }
                    model.CriteriaImportId = criteriaImportId;
                    CriteriaImportBO.Instance.InsertQLSX(model);
                    //}
                    if (model.Status == 1)
                    {
                        OK++;
                    }
                    else
                    {
                        NG++;
                    }
                }

                ProductPartsImport.UserId   = TextUtils.ToString(dtUserKCS.Rows[0]["UserId"]);
                ProductPartsImport.TotalOK  = TextUtils.ToDecimal(txtTotalOK.EditValue); // Qty % 1 == 0 ? OK : Qty;
                ProductPartsImport.TotalNG  = TextUtils.ToDecimal(txtTotalNG.EditValue); //Qty % 1 == 0 ? NG : Qty; //NG;
                ProductPartsImport.TotalKCS = TextUtils.ToDecimal(txtTotalKCS.EditValue);

                ProductPartsImport.LevelError = cboLevelError.SelectedIndex;
                ProductPartsImport.CountError = TextUtils.ToInt(txtCountError.EditValue);

                ProductPartsImportBO.Instance.UpdateQLSX(ProductPartsImport);

                //pt.CommitTransaction();

                loadGrid();

                _isSaved = true;

                MessageBox.Show("Tác vụ thành công!", TextUtils.Caption,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Tác vụ không thành công!" + Environment.NewLine + ex.Message, TextUtils.Caption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                //pt.CloseConnection();
            }

            if (_isSaved)
            {
                if (this.LoadDataChange != null)
                {
                    this.LoadDataChange(null, null);
                }
            }
        }
Example #11
0
        private void btnCheckHoaDon_Click(object sender, EventArgs e)
        {
            grvData.ExpandAllGroups();
            for (int i = 0; i < grvData.RowCount; i++)
            {
                string completeDate      = TextUtils.ToString(grvData.GetRowCellValue(i, colCompletedDate));
                int    payVoucherID      = TextUtils.ToInt(grvData.GetRowCellValue(i, colPayVoucherID));
                string poCode            = TextUtils.ToString(grvData.GetRowCellValue(i, colItemCode));
                int    caseVoucherDebtID = TextUtils.ToInt(grvData.GetRowCellValue(i, colID));
                if (caseVoucherDebtID == 0)
                {
                    continue;
                }
                if (completeDate != "")
                {
                    continue;
                }
                if (payVoucherID == 1)//Nợ hóa đơn
                {
                    string sqlTotalVat = "SELECT TotalVAT = case when dbo.vOrderNew.IsTranferAfferVAT = 1 then isnull(dbo.vOrderNew.VAT,10)*dbo.vOrderNew.TotalPrice /100" +
                                         " else isnull(dbo.vOrderNew.VAT,10)*(dbo.vOrderNew.TotalPrice+dbo.vOrderNew.DeliveryCost)/100 end " +
                                         " from vOrderNew with(nolock) where vOrderNew.OrderCode = '" + poCode + "'";
                    string sqlInvoice = "select sum(T_XNTC.C_PSNO) FROM T_XNTC INNER JOIN T_DM_VUVIEC ON T_XNTC.FK_VUVIEC = T_DM_VUVIEC.PK_ID" +
                                        " WHERE (T_DM_VUVIEC.C_MA = '" + poCode + "') AND (T_XNTC.FK_TKNO LIKE '133%')";

                    decimal totalVAT     = TextUtils.ToDecimal(LibQLSX.ExcuteScalar(sqlTotalVat));
                    decimal totalInvoice = TextUtils.ToDecimal(LibIE.ExcuteScalar(sqlInvoice));

                    decimal chenhLech = totalVAT - totalInvoice;
                    if (chenhLech <= 10 && chenhLech >= -10)
                    {
                        string sqlDateTra = "select top 1 C_NGAYLAP FROM T_XNTC INNER JOIN T_DM_VUVIEC ON T_XNTC.FK_VUVIEC = T_DM_VUVIEC.PK_ID" +
                                            " WHERE (T_DM_VUVIEC.C_MA = '" + poCode + "') AND (T_XNTC.FK_TKNO LIKE '133%')" +
                                            " order by C_NGAYLAP desc";
                        DateTime?dateNgayTra = TextUtils.ToDate2(LibIE.ExcuteScalar(sqlDateTra));
                        if (dateNgayTra.HasValue)
                        {
                            string sqlUpdate = "update CaseVoucherDebt set CompletedDate = '" + dateNgayTra.Value.ToString("yyyy-MM-dd") + "' where ID = " + caseVoucherDebtID;
                            LibQLSX.ExcuteSQL(sqlUpdate);
                        }
                    }

                    if (chenhLech < -10)
                    {
                        string sqlUpdateChenhLech = "update CaseVoucherDebt set TotalDiff = " + chenhLech + " where ID = " + caseVoucherDebtID;
                        LibQLSX.ExcuteSQL(sqlUpdateChenhLech);
                    }
                }

                if (payVoucherID == 2)//Nợ báo giá
                {
                    string sql = "SELECT TOP 1 [C_NGAYLAP]"
                                 + " FROM [tanphat].[dbo].[V_XNTC_VUVIEC] with (nolock)"
                                 + " where [C_MA] = '" + poCode + "' and FK_TKNO LIKE '133%' and [FK_PHANXUONG] = 115";

                    DateTime?dateNgayLap = TextUtils.ToDate2(LibIE.ExcuteScalar(sql));
                    if (dateNgayLap.HasValue)
                    {
                        string sqlUpdate = "update CaseVoucherDebt set CompletedDate = '" + dateNgayLap.Value.ToString("yyyy-MM-dd") + "' where ID = " + caseVoucherDebtID;
                        LibQLSX.ExcuteSQL(sqlUpdate);
                    }
                }
            }
            loadData();
            MessageBox.Show("Hoàn thành Check báo giá, hóa đơn", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }